Skip to content

Commit f9205b4

Browse files
committed
fix #455: expect dvi output when the engine args contain --no-pdf or --output-format=dvi
1 parent 126d213 commit f9205b4

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: tinytex
22
Type: Package
33
Title: Helper Functions to Install and Maintain TeX Live, and Compile LaTeX Documents
4-
Version: 0.54
4+
Version: 0.54.1
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre", "cph"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
77
person(given = "Posit Software, PBC", role = c("cph", "fnd")),

R/latex.R

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
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(

man/latexmk.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test-ci/test-dvi.tex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
\documentclass{standalone}
2+
\begin{document}
3+
Just a test
4+
\end{document}

tests/test-ci/test-latex.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
library(testit)
2+
3+
assert('latexmk() can generate DVI output', {
4+
latexmk2 = function(e, a = NULL) latexmk('test-dvi.tex', e, engine_args = a)
5+
(latexmk2('latex') %==% 'test-dvi.dvi')
6+
(latexmk2('xelatex', '--no-pdf') %==% 'test-dvi.xdv')
7+
(latexmk2('lualatex', '--output-format=dvi') %==% 'test-dvi.dvi')
8+
})

0 commit comments

Comments
 (0)