Skip to content

Commit 8bd3ad4

Browse files
committed
Allow compiling LaTeX with lualatex
This is necessary to use some TeX features, such as TikZ's graph drawing library. As there isn't a reasonable way of detecting the necessity of using lualatex, the --latex-compiler option is now also exposed through config.yml, to make it possible to export the package if the statement only compiles with the right latex compiler.
1 parent e592a2d commit 8bd3ad4

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

example_package/config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ sinol_task_id: __ID__
7373
# See README.md for more information.
7474
sinol_contest_type: oi
7575

76+
# You can configure how sinol-make will compile the LaTeX in `doc/`. By default,
77+
# it will attempt to choose an option that makes sense based on the presence
78+
# of *.ps/*.eps figures. You can choose between `pdflatex`, `lualatex` and
79+
# `latex_dvi`.
80+
# This option can be overridden by passing `--latex_compiler` to `sinol-make doc`.
81+
sinol_latex_compiler: auto
82+
7683
# You can specify which tests are static (handwritten). This allows sinol-make to differentiate between
7784
# old and handwritten tests. If this key is not present old tests won't be removed.
7885
# This key is optional and should be a list of tests.

src/sinol_make/commands/doc/__init__.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import subprocess
55

66
from sinol_make import util
7-
from sinol_make.helpers import paths
7+
from sinol_make.helpers import package_util, paths
88
from sinol_make.interfaces.BaseCommand import BaseCommand
99

1010

@@ -37,11 +37,11 @@ def compile_file_latex_div(self, file_path):
3737
print(util.info(f'Compilation successful for file {os.path.basename(file_path)}.'))
3838
return True
3939

40-
def compile_pdf_latex(self, file_path):
41-
print(f'Compiling {os.path.basename(file_path)} (pdflatex)...')
40+
def compile_pdf_latex(self, file_path, pdflatex='pdflatex'):
41+
print(f'Compiling {os.path.basename(file_path)} ({pdflatex})...')
4242
os.chdir(os.path.dirname(file_path))
4343
for _ in range(3):
44-
subprocess.run(['pdflatex', file_path])
44+
subprocess.run([pdflatex, file_path])
4545
pdf_file = os.path.splitext(file_path)[0] + '.pdf'
4646
pdf_file_path = os.path.join(os.path.dirname(file_path), pdf_file)
4747
if not os.path.exists(pdf_file_path):
@@ -53,8 +53,8 @@ def make_file(self, file_path):
5353
"""
5454
Compile the file two times to get the references right.
5555
"""
56-
if self.compilation_method == 'pdflatex':
57-
return self.compile_pdf_latex(file_path)
56+
if self.compilation_method in ('pdflatex', 'lualatex'):
57+
return self.compile_pdf_latex(file_path, self.compilation_method)
5858
else:
5959
if not self.compile_file_latex_div(file_path):
6060
return False
@@ -73,10 +73,11 @@ def configure_subparser(self, subparser: argparse.ArgumentParser):
7373
help='Compile latex files to pdf',
7474
description='Compiles latex files to pdf. By default compiles all files in the `doc` directory.\n'
7575
'You can also specify files to compile.')
76-
parser.add_argument('--latex-compiler', dest='latex_compiler', choices=['auto', 'pdflatex', 'latex_dvi'],
76+
parser.add_argument('--latex-compiler', dest='latex_compiler', choices=['auto', 'pdflatex', 'latex_dvi', 'lualatex'],
7777
help='Compiler used to compile documents. Available options:\n'
78-
' auto - uses the compiler based on the image types (default option).\n'
78+
' auto - uses the compiler based on the image types (default option, if not configured in config.yml).\n'
7979
' pdflatex - uses pdflatex. Works with .png and .jpg images.\n'
80+
' lualatex - uses lualatex. Like pdflatex, but supports the graph drawing library of TikZ.\n'
8081
' latex_dvi - uses latex and dvipdf. Works with .ps and .eps images.', default='auto')
8182
parser.add_argument('files', type=str, nargs='*', help='files to compile')
8283
return parser
@@ -85,10 +86,13 @@ def run(self, args: argparse.Namespace):
8586
args = util.init_package_command(args)
8687

8788
if not hasattr(args, 'latex_compiler'):
88-
args.latex_compiler = 'auto'
89+
config = package_util.get_config()
90+
args.latex_compiler = config.get('sinol_latex_compiler', 'auto')
8991

9092
if args.latex_compiler == 'pdflatex':
9193
self.compilation_method = 'pdflatex'
94+
elif args.latex_compiler == 'lualatex':
95+
self.compilation_method = 'lualatex'
9296
elif args.latex_compiler == 'latex_dvi':
9397
self.compilation_method = 'latex_dvi'
9498
elif args.latex_compiler == 'auto':

src/sinol_make/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def save_config(config):
9191
"title_en",
9292
"sinol_task_id",
9393
"sinol_contest_type",
94+
"sinol_latex_compiler",
9495
"sinol_static_tests",
9596
"sinol_undocumented_time_tool",
9697
"sinol_undocumented_test_limits",

0 commit comments

Comments
 (0)