Learn R Programming

tinytex (version 0.53)

latexmk: Compile a LaTeX document

Description

The function latexmk() emulates the system command latexmk (https://ctan.org/pkg/latexmk) to compile a LaTeX document. The functions pdflatex(), xelatex(), and lualatex() are wrappers of latexmk(engine =, emulation = TRUE).

Usage

latexmk(
  file,
  engine = c("pdflatex", "xelatex", "lualatex", "latex", "tectonic"),
  bib_engine = c("bibtex", "biber"),
  engine_args = NULL,
  emulation = TRUE,
  min_times = 1,
  max_times = 10,
  install_packages = emulation && tlmgr_writable(),
  pdf_file = gsub("tex$", "pdf", file),
  clean = TRUE
)

pdflatex(...)

xelatex(...)

lualatex(...)

Value

A character string of the path of the output file (i.e., the value of the pdf_file argument).

Arguments

file

A LaTeX file path.

engine

A LaTeX engine (can be set in the global option tinytex.engine, e.g., options(tinytex.engine = 'xelatex')).

bib_engine

A bibliography engine (can be set in the global option tinytex.bib_engine).

engine_args

Command-line arguments to be passed to engine (can be set in the global option tinytex.engine_args, e.g., options(tinytex.engine_args = '-shell-escape').

emulation

Whether to emulate the executable latexmk using R. Note that this is unused when engine == 'tectonic'.

min_times, max_times

The minimum and maximum number of times to rerun the LaTeX engine when using emulation. You can set the global options tinytex.compile.min_times or tinytex.compile.max_times, e.g., options(tinytex.compile.max_times = 3).

install_packages

Whether to automatically install missing LaTeX packages found by parse_packages() from the LaTeX log. This argument is only for the emulation mode and TeX Live. Its value can also be set via the global option tinytex.install_packages, e.g., options(tinytex.install_packages = FALSE).

pdf_file

Path to the PDF output file. By default, it is under the same directory as the input file and also has the same base name. When engine == 'latex', this will be a DVI file.

clean

Whether to clean up auxiliary files after compilation (can be set in the global option tinytex.clean, which defaults to TRUE).

...

Arguments to be passed to latexmk() (other than engine and emulation).

Details

The latexmk emulation works like this: run the LaTeX engine once (e.g., pdflatex), run makeindex to make the index if necessary (the *.idx file exists), run the bibliography engine bibtex or biber to make the bibliography if necessary (the *.aux or *.bcf file exists), and finally run the LaTeX engine a number of times (the maximum is 10 by default) to resolve all cross-references.

By default, LaTeX warnings will be converted to R warnings. To suppress these warnings, set options(tinytex.latexmk.warning = FALSE).

If emulation = FALSE, you need to make sure the executable latexmk is available in your system, otherwise latexmk() will fall back to emulation = TRUE. You can set the global option options(tinytex.latexmk.emulation = FALSE) to always avoid emulation (i.e., always use the executable latexmk).

The default command to generate the index (if necessary) is makeindex. To change it to a different command (e.g., zhmakeindex), you may set the global option tinytex.makeindex. To pass additional command-line arguments to the command, you may set the global option tinytex.makeindex.args (e.g., options(tinytex.makeindex = 'zhmakeindex', tinytex.makeindex.args = c('-z', 'pinyin'))).

If you are using the LaTeX distribution TinyTeX, but its path is not in the PATH variable of your operating system, you may set the global option tinytex.tlmgr.path to the full path of the executable tlmgr, so that latexmk() knows where to find executables like pdflatex. For example, if you are using Windows and your TinyTeX is on an external drive Z:/ under the folder TinyTeX, you may set options(tinytex.tlmgr.path = "Z:/TinyTeX/bin/windows/tlmgr.bat"). Usually you should not need to set this option because TinyTeX can add itself to the PATH variable during installation or via use_tinytex(). In case both methods fail, you can use this manual approach.