Skip to content

Commit

Permalink
Update Ubuntu & Pandoc
Browse files Browse the repository at this point in the history
  • Loading branch information
y-yu committed Jul 21, 2024
1 parent fe44524 commit 4a77b8b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 23 deletions.
32 changes: 14 additions & 18 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
FROM ubuntu:22.04
FROM ubuntu:24.04

LABEL maintainer="YOSHIMRUA Hikaru <yyu [at] mental.poker>"

ARG TARGETARCH

RUN apt-get update

ENV PERSISTENT_DEPS \
ENV PERSISTENT_DEPS='\
openjdk-11-jdk \
python3-pip \
wget \
Expand All @@ -19,11 +17,13 @@ ENV PERSISTENT_DEPS \
lz4 \
ca-certificates \
unzip \
fontconfig
fontconfig \
python3-pandocfilters \
python3-pypdf'
RUN apt-get install -y --no-install-recommends $PERSISTENT_DEPS

# Setup fonts
ENV FONT_PATH /usr/share/fonts/
ENV FONT_PATH=/usr/share/fonts/
RUN mkdir -p $FONT_PATH && \
# Source Code Pro
wget "https://github.com/adobe-fonts/source-code-pro/releases/download/2.038R-ro%2F1.058R-it%2F1.018R-VAR/OTF-source-code-pro-2.038R-ro-1.058R-it.zip" && \
Expand All @@ -32,23 +32,19 @@ RUN mkdir -p $FONT_PATH && \
rm -rf OTF-source-code-pro-2.038R-ro-1.058R-it.zip source-code-pro && \
fc-cache -f -v

ARG TARGETARCH

# Install Pandoc
ENV PANDOC_VERSION 2.19
ENV PANDOC_DOWNLOAD_URL https://github.com/jgm/pandoc/releases/download/$PANDOC_VERSION/pandoc-$PANDOC_VERSION-linux-$TARGETARCH.tar.gz
ENV PANDOC_ROOT /usr/local/bin/pandoc
ENV PANDOC_VERSION=3.2.1
ENV PANDOC_DOWNLOAD_URL="https://github.com/jgm/pandoc/releases/download/$PANDOC_VERSION/pandoc-$PANDOC_VERSION-linux-$TARGETARCH.tar.gz"
ENV PANDOC_ROOT=/usr/local/bin/pandoc
RUN wget -qO- "$PANDOC_DOWNLOAD_URL" | tar -xzf - && \
cp pandoc-$PANDOC_VERSION/bin/pandoc $PANDOC_ROOT && \
rm -Rf pandoc-$PANDOC_VERSION/

# Install Pandocfilter
COPY requirements.txt ./
RUN pip install --upgrade pip && \
pip install -r requirements.txt && \
rm requirements.txt

# Install TeXLive
ARG TEXLIVE_OPTIONS=""
ENV TEXLIVE_PATH /usr/local/texlive
ENV TEXLIVE_PATH=/usr/local/texlive
RUN mkdir /tmp/install-tl-unx && \
wget -qO- http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz | \
tar -xz -C /tmp/install-tl-unx --strip-components=1 && \
Expand All @@ -69,11 +65,11 @@ RUN mkdir /tmp/install-tl-unx && \
$TEXLIVE_OPTIONS; \
fi

ENV PATH $TEXLIVE_PATH/bin/aarch64-linux:$TEXLIVE_PATH/bin/x86_64-linux:/bin:$PATH
ENV PATH="$TEXLIVE_PATH/bin/aarch64-linux:$TEXLIVE_PATH/bin/x86_64-linux:/bin:$PATH"
RUN tlmgr $TEXLIVE_OPTIONS install latexmk collection-luatex collection-langjapanese \
collection-fontsrecommended filehook type1cm mdframed needspace \
fncychap everyhook svn-prov zref sourcesanspro \
cm-unicode sourceserifpro haranoaji letltxmacro && \
cm-unicode sourceserifpro haranoaji letltxmacro svg transparent && \
luaotfload-tool -u -vvv && \
rm -fr /tmp/install-tl-unx && \
apt-get -y clean
Expand Down
2 changes: 1 addition & 1 deletion latexmkrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env perl

$pdflatex = 'lualatex %O %S -halt-on-error';
$pdflatex = 'lualatex %O -halt-on-error -shell-escape %B';
$pdf_mode = 3;
$bibtex = 'pbibtex';
5 changes: 4 additions & 1 deletion python/fix_pdf_tex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

import re
import sys
from pypdf import PdfReader

re_include_graphics = re.compile(
r'\\includegraphics\[width=\\unitlength,page=(\d+)\]')
re_end_picture = re.compile(r'\\end\{picture\}')

reader = PdfReader(sys.argv[1])
num_pages = len(reader.pages)

inside = False
num_pages = int(sys.argv[1])
for line in sys.stdin:
if not inside:
m = re_include_graphics.search(line)
Expand Down
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

18 changes: 18 additions & 0 deletions scala_text.tex
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

\usepackage{longtable,booktabs}
\usepackage{graphicx,grffile}
\usepackage{svg}

\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>.8\linewidth\linewidth\else\Gin@nat@width\fi}
Expand Down Expand Up @@ -104,6 +105,23 @@
% Pandocの画像を適切に表示させるため
\setkeys{Gin}{keepaspectratio}

% Pandoc用
% https://github.com/jgm/pandoc/blob/501d7cc02d8ed694e32f26756bc433250d34b193/data/templates/default.latex#L304-L317
\makeatletter
\newsavebox\pandoc@box
\newcommand*\pandocbounded[1]{% scales image to fit in text height/width
\sbox\pandoc@box{#1}%
\Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
\Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
\ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
\ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
\else\usebox{\pandoc@box}%
\fi%
}
% Set default figure placement to htbp
\def\fps@figure{htbp}
\makeatother

\begin{document}

\begin{luacode*}
Expand Down
3 changes: 1 addition & 2 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ do
PDF=`pwd`/${BASH_REMATCH[1]}.pdf
PDFTEX=`pwd`/${BASH_REMATCH[1]}.pdf_tex
inkscape -D "$SVG" --export-filename="$PDF" --export-latex
PAGES=$(egrep -a '/Type /Page\b' "$PDF" | wc -l | tr -d ' ')
python3 ./python/fix_pdf_tex.py "$PAGES" < "$PDFTEX" > "$PDFTEX.tmp"
python3 ./python/fix_pdf_tex.py "$PDF" < "$PDFTEX" > "$PDFTEX.tmp"
mv "$PDFTEX.tmp" "$PDFTEX"
fi
done
Expand Down

0 comments on commit 4a77b8b

Please sign in to comment.