6262# ' \code{options(tinytex.install_packages = FALSE)}.
6363# ' @param pdf_file Path to the PDF output file. By default, it is under the same
6464# ' directory as the input \code{file} and also has the same base name. When
65- # ' \code{engine == 'latex'}, this will be a DVI file.
65+ # ' \code{engine == 'latex'} or \code{engine_args} contains \verb{--no-pdf} or
66+ # ' \code{--output-format=dvi}, this will be a DVI file.
6667# ' @param clean Whether to clean up auxiliary files after compilation (can be
6768# ' set in the global option \code{tinytex.clean}, which defaults to
6869# ' \code{TRUE}).
@@ -73,15 +74,17 @@ latexmk = function(
7374 file , engine = c(' pdflatex' , ' xelatex' , ' lualatex' , ' latex' , ' tectonic' ),
7475 bib_engine = c(' bibtex' , ' biber' ), engine_args = NULL , emulation = TRUE ,
7576 min_times = 1 , max_times = 10 , install_packages = emulation && tlmgr_writable(),
76- pdf_file = gsub( ' tex$ ' , ' pdf ' , file ) , clean = TRUE
77+ pdf_file = NULL , clean = TRUE
7778) {
7879 if (! grepl(' [.]tex$' , file ))
7980 stop(" The input file '" , file , " ' does not have the .tex extension" )
8081 file = path.expand(file )
8182 if (missing(engine )) engine = getOption(' tinytex.engine' , engine )
8283 engine = gsub(' ^(pdf|xe|lua)(tex)$' , ' \\ 1la\\ 2' , engine ) # normalize *tex to *latex
8384 engine = match.arg(engine )
84- is_latex = engine == ' latex'
85+ is_dvi = engine == ' latex' ||
86+ any(grepl(' (^| )(--output-format=dvi|--no-pdf)( |$)' , engine_args ))
87+ ext = if (is_dvi ) { if (engine == ' xelatex' ) ' xdv' else ' dvi' } else ' pdf'
8588 tweak_path()
8689 if (missing(emulation )) emulation = getOption(' tinytex.latexmk.emulation' , emulation )
8790 if (! emulation ) {
@@ -100,20 +103,19 @@ latexmk = function(
100103 if (missing(bib_engine )) bib_engine = getOption(' tinytex.bib_engine' , bib_engine )
101104 if (missing(engine_args )) engine_args = getOption(' tinytex.engine_args' , engine_args )
102105 if (missing(clean )) clean = getOption(' tinytex.clean' , TRUE )
103- pdf = gsub( ' tex$ ' , if ( is_latex ) ' dvi ' else ' pdf ' , basename(file ))
106+ out = with_ext( basename(file ), ext )
104107 if (! is.null(output_dir <- getOption(' tinytex.output_dir' ))) {
105108 output_dir_arg = shQuote(paste0(if (emulation ) ' -' , ' -output-directory=' , output_dir ))
106109 if (length(grep(output_dir_arg , engine_args , fixed = TRUE )) == 0 ) stop(
107110 " When you set the global option 'tinytex.output_dir', the argument 'engine_args' " ,
108111 " must contain this value: " , capture.output(dput(output_dir_arg ))
109112 )
110- pdf = file.path(output_dir , pdf )
111- if (missing(pdf_file )) pdf_file = file.path(output_dir , basename(pdf_file ))
113+ if (is.null(pdf_file )) out = file.path(output_dir , out )
112114 }
113- if (is_latex ) pdf_file = with_ext( pdf_file , ' dvi ' )
115+ if (is.null( pdf_file )) pdf_file = out
114116 check_pdf = function () {
115- if (! file.exists(pdf )) show_latex_error(file , with_ext(pdf , ' log' ), TRUE )
116- xfun :: file_rename(pdf , pdf_file )
117+ if (! file.exists(out )) show_latex_error(file , with_ext(out , ' log' ), TRUE )
118+ xfun :: file_rename(out , pdf_file )
117119 pdf_file
118120 }
119121 if (engine == ' tectonic' ) {
@@ -129,7 +131,7 @@ latexmk = function(
129131 }
130132 system2_quiet(' latexmk' , c(
131133 ' -latexoption=-halt-on-error -interaction=batchmode' ,
132- if (is_latex ) ' -latex=latex' else paste0(' -pdf -pdflatex=' , engine ),
134+ if (is_dvi ) ' -latex=latex' else paste0(' -pdf -pdflatex=' , engine ),
133135 engine_args , shQuote(file )
134136 ), error = {
135137 if (install_packages ) warning(
0 commit comments