4
4
import subprocess
5
5
6
6
from sinol_make import util
7
- from sinol_make .helpers import paths
7
+ from sinol_make .helpers import package_util , paths
8
8
from sinol_make .interfaces .BaseCommand import BaseCommand
9
9
10
10
@@ -37,11 +37,11 @@ def compile_file_latex_div(self, file_path):
37
37
print (util .info (f'Compilation successful for file { os .path .basename (file_path )} .' ))
38
38
return True
39
39
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 , compiler = 'pdflatex' ):
41
+ print (f'Compiling { os .path .basename (file_path )} ({ compiler } )...' )
42
42
os .chdir (os .path .dirname (file_path ))
43
43
for _ in range (3 ):
44
- subprocess .run (['pdflatex' , file_path ])
44
+ subprocess .run ([compiler , file_path ])
45
45
pdf_file = os .path .splitext (file_path )[0 ] + '.pdf'
46
46
pdf_file_path = os .path .join (os .path .dirname (file_path ), pdf_file )
47
47
if not os .path .exists (pdf_file_path ):
@@ -53,8 +53,8 @@ def make_file(self, file_path):
53
53
"""
54
54
Compile the file two times to get the references right.
55
55
"""
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 )
58
58
else :
59
59
if not self .compile_file_latex_div (file_path ):
60
60
return False
@@ -73,22 +73,32 @@ def configure_subparser(self, subparser: argparse.ArgumentParser):
73
73
help = 'Compile latex files to pdf' ,
74
74
description = 'Compiles latex files to pdf. By default compiles all files in the `doc` directory.\n '
75
75
'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' ],
77
77
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 '
79
79
' pdflatex - uses pdflatex. Works with .png and .jpg images.\n '
80
- ' latex_dvi - uses latex and dvipdf. Works with .ps and .eps images.' , default = 'auto' )
80
+ ' lualatex - uses lualatex. Like pdflatex, but supports the graph drawing library of TikZ.\n '
81
+ ' latex_dvi - uses latex and dvipdf. Works with .ps and .eps images.' , default = argparse .SUPPRESS )
81
82
parser .add_argument ('files' , type = str , nargs = '*' , help = 'files to compile' )
82
83
return parser
83
84
84
85
def run (self , args : argparse .Namespace ):
85
86
args = util .init_package_command (args )
86
87
88
+ # Note: when other commands call DocCommand as a subroutine, they provide
89
+ # their own argparse.Namespace instead of going through the argparse
90
+ # configuration in configure_subparser. To match their behavior,
91
+ # we configure argparse to omit the latex_compiler attribute entirely
92
+ # when it is not provided by the user, instead of using the default
93
+ # behavior of defaulting to None.
87
94
if not hasattr (args , 'latex_compiler' ):
88
- args .latex_compiler = 'auto'
95
+ config = package_util .get_config ()
96
+ args .latex_compiler = config .get ('sinol_latex_compiler' , 'auto' )
89
97
90
98
if args .latex_compiler == 'pdflatex' :
91
99
self .compilation_method = 'pdflatex'
100
+ elif args .latex_compiler == 'lualatex' :
101
+ self .compilation_method = 'lualatex'
92
102
elif args .latex_compiler == 'latex_dvi' :
93
103
self .compilation_method = 'latex_dvi'
94
104
elif args .latex_compiler == 'auto' :
0 commit comments