From 4a77b8b29bb3cf6e079a3f0f57b804b10186ca87 Mon Sep 17 00:00:00 2001 From: Yoshimura Yuu Date: Sun, 21 Jul 2024 20:42:26 +0900 Subject: [PATCH] Update Ubuntu & Pandoc --- docker/Dockerfile | 32 ++++++++++++++------------------ latexmkrc | 2 +- python/fix_pdf_tex.py | 5 ++++- requirements.txt | 1 - scala_text.tex | 18 ++++++++++++++++++ setup.sh | 3 +-- 6 files changed, 38 insertions(+), 23 deletions(-) delete mode 100644 requirements.txt diff --git a/docker/Dockerfile b/docker/Dockerfile index 78fefda..6863a83 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,12 +1,10 @@ -FROM ubuntu:22.04 +FROM ubuntu:24.04 LABEL maintainer="YOSHIMRUA Hikaru " -ARG TARGETARCH - RUN apt-get update -ENV PERSISTENT_DEPS \ +ENV PERSISTENT_DEPS='\ openjdk-11-jdk \ python3-pip \ wget \ @@ -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" && \ @@ -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 && \ @@ -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 diff --git a/latexmkrc b/latexmkrc index b2f9a0b..00d7df6 100644 --- a/latexmkrc +++ b/latexmkrc @@ -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'; diff --git a/python/fix_pdf_tex.py b/python/fix_pdf_tex.py index 7ea278d..131a04e 100644 --- a/python/fix_pdf_tex.py +++ b/python/fix_pdf_tex.py @@ -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) diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index a9c0040..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -pandocfilters>=1.4.2 diff --git a/scala_text.tex b/scala_text.tex index f541454..1f73ce0 100644 --- a/scala_text.tex +++ b/scala_text.tex @@ -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} @@ -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*} diff --git a/setup.sh b/setup.sh index 041fb2d..646af62 100755 --- a/setup.sh +++ b/setup.sh @@ -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