diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index b3226dfe..35daabd8 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -36,6 +36,10 @@ jobs: run: venv/bin/ruff check --output-format=github - name: Check ruff formatting run: venv/bin/ruff format --check --diff + - name: Install lualatex (temporary, until githubci docker image is updated) + run: | + apt-get update + apt-get install fonts-cmu fonts-noto-color-emoji texlive-luatex - name: Test with pytest run: venv/bin/pytest - name: Run mypy @@ -53,6 +57,10 @@ jobs: - name: Build debian packages run: | make builddeb + - name: Install lualatex (temporary, until githubci docker image is updated) + run: | + apt-get update + apt-get install fonts-cmu fonts-noto-color-emoji texlive-luatex - name: Install debian package run: dpkg -i ../kattis-problemtools_*.deb - name: Verify examples diff --git a/README.md b/README.md index 210a35bb..76d25f65 100644 --- a/README.md +++ b/README.md @@ -237,7 +237,11 @@ The dependencies needed to *build/install* problemtools can be installed with: And the dependencies needed to *run* problemtools can be installed with: - sudo apt install ghostscript pandoc python3 texlive-fonts-recommended texlive-lang-cyrillic texlive-latex-extra texlive-plain-generic tidy dvisvgm + sudo apt install ghostscript pandoc python3 texlive-fonts-recommended texlive-latex-extra texlive-luatex texlive-plain-generic tidy dvisvgm + +To render problem statements to pdf with non-latin characters, also add the following fonts: + + sudo apt install fonts-cmu fonts-noto-color-emoji ### Fedora diff --git a/admin/docker/Dockerfile.runreqs b/admin/docker/Dockerfile.runreqs index c27486dd..30bc8245 100644 --- a/admin/docker/Dockerfile.runreqs +++ b/admin/docker/Dockerfile.runreqs @@ -16,13 +16,15 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ rm -f /etc/apt/apt.conf.d/docker-clean && \ apt-get update && apt-get install -y \ dvisvgm \ + fonts-cmu \ + fonts-noto-color-emoji \ ghostscript \ libgmp-dev \ pandoc \ python3 \ python3-venv \ texlive-fonts-recommended \ - texlive-lang-cyrillic \ texlive-latex-extra \ + texlive-luatex \ texlive-plain-generic \ tidy diff --git a/debian/control b/debian/control index a6b27d74..564ed283 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ Homepage: https://github.com/Kattis/problemtools Package: kattis-problemtools Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, pandoc, python3, texlive-plain-generic, texlive-fonts-recommended, texlive-latex-extra, texlive-lang-cyrillic, tidy, ghostscript, dvisvgm +Depends: ${shlibs:Depends}, ${misc:Depends}, pandoc, python3, texlive-plain-generic, texlive-fonts-recommended, texlive-latex-extra, texlive-luatex, tidy, ghostscript, dvisvgm, fonts-cmu, fonts-noto-color-emoji Recommends: gcc, g++ Description: Kattis Problem Tools These are tools to manage and verify problem packages in the diff --git a/problemtools/problem2pdf.py b/problemtools/problem2pdf.py index 57529480..1eaa38a6 100644 --- a/problemtools/problem2pdf.py +++ b/problemtools/problem2pdf.py @@ -102,12 +102,12 @@ def latex2pdf(options: argparse.Namespace, statement_file: Path) -> bool: origcwd = os.getcwd() os.chdir(texfile.parent) - params = ['pdflatex', '-interaction=nonstopmode'] + params = ['lualatex', '--interaction=nonstopmode'] output = None if options.quiet: output = open(os.devnull, 'w') if options.nopdf: - params.append('-draftmode') + params.append('--draftmode') params.append(str(texfile.name)) diff --git a/problemtools/templates/latex/problemset.cls b/problemtools/templates/latex/problemset.cls index 3d72c3b8..380b59fb 100644 --- a/problemtools/templates/latex/problemset.cls +++ b/problemtools/templates/latex/problemset.cls @@ -36,8 +36,6 @@ \RequirePackage{times} % Font choice \RequirePackage{amsmath} % AMS \RequirePackage{amssymb} % AMS -\RequirePackage[OT2,T1]{fontenc} % Cyrillic and standard % TODO: make alphabet options more general -\RequirePackage[utf8]{inputenc} % UTF-8 support \RequirePackage{fancyhdr} % Headers \RequirePackage{graphicx} % Graphics \RequirePackage{subfigure} % Subfigures @@ -55,6 +53,24 @@ \ifplastex\else \RequirePackage{xstring} \RequirePackage{pgffor} +% I do not understand how to do font handling well in a portable way in +% lualatex. The default font seems to only have latin characters. If we +% try to load a font which is not installed, rendering fails, which makes +% problem2pdf and verifyproblem unhappy. After a lot of trial-and-error, +% I ended up with this conditional loading of fonts (so we should degrade +% gracefully when fonts are missing). Getting the emoji font to work was weird, +% as apparently we need to define the fallback using lua code because the font +% uses colors. +\RequirePackage{fontspec} +\RequirePackage{luacode} +\IfFontExistsTF{CMU Serif}{ + \IfFontExistsTF{NotoColorEmoji}{ + \directlua{luaotfload.add_fallback("myfallback", {"NotoColorEmoji:mode=harf;"})} + \setmainfont{CMU Serif}[RawFeature={fallback=myfallback}] + }{ + \setmainfont{CMU Serif} + } +}{} \fi %% Commands used to set name, logo, etc of contest @@ -291,8 +307,8 @@ \newcommand{\sampletable}[4]{ % First find widths of the two files - \savebox{\PS@sampleinbox}{\lstinputlisting[inputencoding=utf8/latin1,basicstyle=\ttfamily]{#2}} - \savebox{\PS@sampleoutbox}{\lstinputlisting[inputencoding=utf8/latin1,basicstyle=\ttfamily]{#4}} + \savebox{\PS@sampleinbox}{\lstinputlisting[inputencoding=utf8,basicstyle=\ttfamily]{#2}} + \savebox{\PS@sampleoutbox}{\lstinputlisting[inputencoding=utf8,basicstyle=\ttfamily]{#4}} \settowidth{\PS@sampleoutwidth}{\usebox{\PS@sampleoutbox}} \settowidth{\PS@sampleinwidth}{\usebox{\PS@sampleinbox}} \setlength{\PS@sampletotwidth}{\PS@sampleinwidth} @@ -369,7 +385,7 @@ \hline \parbox[t]{0.55\textwidth}{ \vspace{-0.49cm} - \lstinputlisting[inputencoding=utf8/latin1,basicstyle=\ttfamily]{\jobname.pstmp} + \lstinputlisting[inputencoding=utf8,basicstyle=\ttfamily]{\jobname.pstmp} \vspace{-0.21cm} }\\ \hline