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 , 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' :
0 commit comments