44import subprocess
55
66from sinol_make import util
7- from sinol_make .helpers import paths
7+ from sinol_make .helpers import package_util , paths
88from 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 , compiler = 'pdflatex' ):
41+ print (f'Compiling { os .path .basename (file_path )} ({ compiler } )...' )
4242 os .chdir (os .path .dirname (file_path ))
4343 for _ in range (3 ):
44- subprocess .run (['pdflatex' , file_path ])
44+ subprocess .run ([compiler , 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,22 +73,32 @@ 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- ' 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 )
8182 parser .add_argument ('files' , type = str , nargs = '*' , help = 'files to compile' )
8283 return parser
8384
8485 def run (self , args : argparse .Namespace ):
8586 args = util .init_package_command (args )
8687
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.
8794 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' )
8997
9098 if args .latex_compiler == 'pdflatex' :
9199 self .compilation_method = 'pdflatex'
100+ elif args .latex_compiler == 'lualatex' :
101+ self .compilation_method = 'lualatex'
92102 elif args .latex_compiler == 'latex_dvi' :
93103 self .compilation_method = 'latex_dvi'
94104 elif args .latex_compiler == 'auto' :
0 commit comments