latexmk (1) - Linux Manuals
latexmk: generate LaTeX document
NAME
latexmk - generate LaTeX document
SYNOPSIS
latexmk [options] [file ...]DESCRIPTION
Latexmk completely automates the process of compiling a LaTeX document. Essentially, it is like a specialized relative of the general make utility, but one which determines dependencies automatically and has some other very useful features. In its basic mode of operation latexmk is given the name of the primary source file for a document, and it issues the appropriate sequence of commands to generate a .dvi, .ps, .pdf and/or hardcopy version of the document.By default latexmk will run the commands necessary to generate a .dvi file, which copies the behavior of earlier versions when only latex was available.
Latexmk can also be set to run continuously with a suitable previewer. In that case the latex program (or one of its relatives), etc, are rerun whenever one of the source files is modified, and the previewer automatically updates the on-screen view of the compiled document.
Latexmk determines which are the source files by examining the log file. (Optionally, it also examines the list of input and output files generated by the -recorder option of modern versions of latex (and pdflatex, xelatex, lualatex). See the documentation for the -recorder option of latexmk below.) When latexmk is run, it examines properties of the source files, and if any have been changed since the last document generation, latexmk will run the various LaTeX processing programs as necessary. In particular, it will repeat the run of latex (or a related program)) often enough to resolve all cross references; depending on the macro packages used. With some macro packages and document classes, four, or even more, runs may be needed. If necessary, latexmk will also run bibtex, biber, and/or makeindex. In addition, latexmk can be configured to generate other necessary files. For example, from an updated figure file it can automatically generate a file in encapsulated postscript or another suitable format for reading by LaTeX.
Latexmk has two different previewing options. With the simple -pv option, a dvi, postscript or pdf previewer is automatically run after generating the dvi, postscript or pdf version of the document. The type of file to view is selected according to configuration settings and command line options.
The second previewing option is the powerful -pvc option (mnemonic: "preview continuously"). In this case, latexmk runs continuously, regularly monitoring all the source files to see if any have changed. Every time a change is detected, latexmk runs all the programs necessary to generate a new version of the document. A good previewer will then automatically update its display. Thus the user can simply edit a file and, when the changes are written to disk, latexmk completely automates the cycle of updating the .dvi (and/or the .ps and .pdf) file, and refreshing the previewer's display. It's not quite WYSIWYG, but usefully close.
For other previewers, the user may have to manually make the previewer update its display, which can be (e.g., with some versions of xdvi and gsview) as simple as forcing a redraw of its display.
Latexmk has the ability to print a banner in gray diagonally across each page when making the postscript file. It can also, if needed, call an external program to do other postprocessing on generated dvi and postscript files. (See the options -dF and -pF, and the documentation for the $dvi_filter and $ps_filter configuration variables.) These capabilities are leftover from older versions of latexmk, but are currently non-functional. More flexibility can be obtained in current versions, since the command strings for running *latex can now be configured to run multiple commands. This also extends the possibility of postprocessing generated files.
Latexmk is highly configurable, both from the command line and in configuration files, so that it can accommodate a wide variety of user needs and system configurations. Default values are set according to the operating system, so latexmk often works without special configuration on MS-Windows, cygwin, Linux, OS-X, and other UNIX systems. See the section "Configuration/Initialization (rc) Files", and then the later sections "How to Set Variables in Initialization Files", "Format of Command Specifications", "List of Configuration Variables Usable in Initialization Files", "Custom Dependencies", and "Advanced Configuration"
A very annoying complication handled very reliably by latexmk, is that LaTeX is a multiple pass system. On each run, LaTeX reads in information generated on a previous run, for things like cross referencing and indexing. In the simplest cases, a second run of LaTeX suffices, and often the log file contains a message about the need for another pass. However, there is a wide variety of add-on macro packages to LaTeX, with a variety of behaviors. The result is to break simple-minded determinations of how many runs are needed and of which programs. Latexmk has a highly general and efficient solution to these issues. The solution involves retaining between runs information on the source files, and a symptom is that latexmk generates an extra file (with extension .fdb_latexmk, by default) that contains the source file information.
LATEXMK OPTIONS AND ARGUMENTS ON COMMAND LINE
In general the command line to invoke latexmk has the form
All options can be introduced by single or double "-" characters, e.g., "latexmk -help" or "latexmk --help".
Note 1: In the documentation, '*latex' means any of the supported engines, i.e., currently latex, lualatex, pdflatex, xelatex. Mention of a specific one of these normally refers that specific engines. Earlier versions of this documentation weren't so consistent. Which of these is used to compile a document, depends on the configuration and the command line arguments.
Note 2: In addition to the options in the list below, latexmk recognizes almost all the options recognized by the *latex programs in their current TeXLive and MiKTeX implementations. Some of the options for these programs trigger special action or behavior by latexmk, in which case they have specific explanations in this document; in this case they may or may not be passed to *latex as well.
Run latexmk with the -showextraoptions to get a list of the options that latexmk accepts and that are simply passed through to *latex. See also the explanation of the -showextraoptions option for more information.
Definitions of options and arguments
- file
-
One or more files can be specified. If no files are specified,
latexmk will, by default, run on all files in the current working directory
with a ".tex" extension. This behavior can be changed: see the
description concerning the @default_files variable in the
section "List of configuration variables usable in initialization
files".
If a file is specified without an extension, then the ".tex" extension is automatically added, just as LaTeX does. Thus, if you specify:
then latexmk will operate on the file "foo.tex".
There are certain restrictions on what characters can be in a filename; certain characters are either prohibited or problematic for the latex etc programs. These characters are: "$", "%", "\", "~", the double quote character, and the control characters null, tab, form feed, carriage return, line feed, and delete. In addition "&" is prohibited when it is the first character of a filename.
Latexmk gives a fatal error when it detects any of the above characters in the TeX filename(s) specified on the command line. However before testing for illegal characters, latexmk removes matching pairs of double quotes from a filename. This matches the behavior of latex etc, and deals with problems that occasionally result from filenames that have been incorrectly quoted on the command line. In addition, under Microsoft Windows, the forward slash character "\" is a directory separator, so latexmk replaces it by a backward slash "/", which is also a legal directory separator in Windows, and is accepted by latex etc.
- -auxdir=FOO or -aux-directory=FOO
-
Sets the directory for auxiliary output files of *latex
(.aux, .log etc). This
achieves its effect by the -aux-directory option of *latex,
which currently is only implemented on the MiKTeX version of
*latex.
See also the -outdir/-output-directory options, and the $aux_dir, $out_dir, and $search_path_separator configuration variables of latexmk. In particular, see the documentation of $out_dir for some complications on what directory names are suitable.
If you also use the -cd option, and the specified auxiliary output directory is a relative path, then the path is interpreted relative to the document directory.
- -bibtex
-
When the source file uses bbl files for bibliography, run bibtex or
biber as needed to regenerate the bbl files.
This property can also be configured by setting the $bibtex_use variable to 2 in a configuration file.
- -bibtex-
-
Never run bibtex or biber. Also, always treat .bbl files as precious,
i.e., do not delete them in a cleanup operation.
A common use for this option is when a document comes from an external source, complete with its bbl file(s), and the user does not have the corresponding bib files available. In this situation use of the -bibtex- option will prevent latexmk from trying to run bibtex or biber, which would result in overwriting of the bbl files.
This property can also be configured by setting the $bibtex_use variable to 0 in a configuration file.
- -bibtex-cond
-
When the source file uses bbl file(s) for the bibliography, run
bibtex or biber as needed to regenerate the bbl files, but
only if the
relevant bib file(s) exist. Thus when the bib files are not
available, bibtex or biber is not run, thereby avoiding
overwriting of
the bbl file(s).
Also, always treat .bbl files as precious,
i.e., do not delete them in a cleanup operation.
This is the default setting. It can also be configured by setting the $bibtex_use variable to 1 in a configuration file.
The reason for using this setting is that sometimes a .bbl file is available containing the bibliography for a document, but the .bib file is not available. An example would be for a scientific journal where authors submit .tex and .bbl files, but not the original .bib file. In that case, running bibtex or biber would not work, and the .bbl file should be treated as a user source file, and not as a file that can be regenerated on demand.
(Note that it is possible for latexmk to decide that the bib file does not exist, even though the bib file does exist and bibtex or biber finds it. The problem is that the bib file may not be in the current directory but in some search path; the places latexmk and bibtex or biber cause to be searched need not be identical. On modern installations of TeX and related programs this problem should not arise, since latexmk uses the kpsewhich program to do the search, and kpsewhich should use the same search path as bibtex and biber. If this problem arises, use the -bibtex option when invoking latexmk.)
Note that this value does not work properly if the document uses biber instead of bibtex. (There's a long story why not.)
- -bibtex-cond1
-
The same as -bibtex-cond except that .bbl files are only
treated as precious if one or more bibfiles fails to exist.
Thus if all the bib files exist, bibtex or biber is run to generate .bbl files as needed, and then it is appropriate to delete the bbl files in a cleanup operation since they can be re-generated.
This property can also be configured by setting the $bibtex_use variable to 1.5 in a configuration file.
- -bibtexfudge or -bibfudge
-
Turn on the change-directory fudge for bibtex. See documentation of
$bibtex_fudge for details.
- -bibtexfudge- or -bibfudge-
-
Turn off the change-directory fudge for
bibtex. See documentation of $bibtex_fudge for details.
- -bm <message>
-
A banner message to print diagonally across each page when converting
the dvi file to postscript. The message must be a single argument on
the command line so be careful with quoting spaces and such.
Note that if the -bm option is specified, the -ps option is assumed.
- -bi <intensity>
-
How dark to print the banner message. A decimal number between 0 and 1.
0 is black and 1 is white. The default is 0.95, which is OK unless your
toner cartridge is getting low.
- -bs <scale>
-
A decimal number that specifies how large the banner message will be
printed. Experimentation is necessary to get the right scale for your
message, as a rule of thumb the scale should be about equal to 1100
divided by the number of characters in the message. The default is 220.0
which is just right for 5 character messages.
- -commands
-
List the commands used by latexmk for processing files, and then
exit.
- -c
-
Clean up (remove) all regeneratable files generated by latex and
bibtex or biber except dvi, postscript and pdf. These files are a
combination of log files, aux files, latexmk's database file of
source file information,
and those with extensions
specified in the @generated_exts configuration variable. In addition,
files specified by the $clean_ext and @generated_exts
configuration variables are removed.
This cleanup is instead of a regular make. See the -gg option if you want to do a cleanup followed by a make.
Treatment of .bbl files: If $bibtex_use is set to 0 or 1, bbl files are always treated as non-regeneratable. If $bibtex_use is set to 1.5, bbl files are counted as non-regeneratable conditionally: If the bib file exists, then bbl files are regeneratable, and are deleted in a clean up. But if $bibtex_use is 1.5 and a bib file doesn't exist, then the bbl files are treated as non-regeneratable and hence are not deleted.
In contrast, if $bibtex_use is set to 2, bbl files are always treated as regeneratable, and are deleted in a cleanup.
Treatment of files generated by custom dependencies: If $cleanup_includes_cusdep_generated is nonzero, regeneratable files are considered as including those generated by custom dependencies and are also deleted. Otherwise these files are not deleted.
- -C
-
Clean up (remove) all regeneratable files generated by latex and
bibtex or biber. This is the same as the -c option with the
addition of dvi, postscript and pdf files, and those specified
in the $clean_full_ext configuration variable.
This cleanup is instead of a regular make. See the -gg option if you want to do a cleanup followed by a make.
See the -c option for the specification of whether or not .bbl files are treated as non-regeneratable or regeneratable.
If $cleanup_includes_cusdep_generated is nonzero, regeneratable files are considered as including those generated by custom dependencies and are also deleted. Otherwise these files are not deleted.
- -CA
-
(Obsolete). Now equivalent to the -C option. See that option
for details.
- -cd
-
Change to the directory containing the main source file before processing
it. Then all the generated files (.aux, .log, .dvi, .pdf, etc) will be
relative to the source file.
This option is particularly useful when latexmk is invoked from a GUI configured to invoke latexmk with a full pathname for the source file.
This option works by setting the $do_cd configuration variable to one; you can set that variable if you want to configure latexmk to have the effect of the -cd option without specifying it on the command line. See the documentation for that variable.
- -cd-
-
Do NOT change to the directory containing the main source file before processing
it. Then all the generated files (.aux, .log, .dvi, .pdf, etc) will be
relative to the current directory rather than the source file.
This is the default behavior and corresponds to the behavior of the *latex programs. However, it is not desirable behavior when latexmk is invoked by a GUI configured to invoke latexmk with a full pathname for the source file. See the -cd option.
This option works by setting the $do_cd configuration variable to zero. See the documentation for that variable for more information.
- -CF
-
Remove the file containing the database of source file information,
before doing the other actions requested.
- -d
-
Set draft mode. This prints the banner message "DRAFT" across your
page when converting the dvi file to postscript. Size and intensity
can be modified with the -bs and -bi options. The -bm
option will override this option as this is really just a short way of
specifying:
Note that if the -d option is specified, the -ps option is assumed.
- -deps
-
Show a list of dependent files after processing. This is in the form
of a dependency list of the form used by the make program, and
it is therefore suitable for use in a Makefile. It gives an overall
view of the files without listing intermediate files, as well as
latexmk can determine them.
By default the list of dependent files is sent to stdout (i.e., normally to the screen unless you've redirected latexmk's output). But you can set the filename where the list is sent by the -deps-out= option.
See the section "USING latexmk WITH make" for an example of how to use a dependency list with make.
Users familiar with GNU automake and gcc will find that the -deps option is very similar in its purpose and results to the -M option to gcc. (In fact, latexmk also has options -M, -MF, and -MP options that behave like those of gcc.)
- -dependents
-
Equivalent to -deps.
- -deps-
-
Do not show a list of dependent files after processing. (This is the
default.)
- -dependents-
-
Equivalent to -deps-.
- -deps-out=FILENAME
-
Set the filename to which the list of dependent files is written. If
the FILENAME argument is omitted or set to "-", then the output is
sent to stdout.
Use of this option also turns on the output of the list of dependent files after processing.
- -dF
-
Dvi file filtering. The argument to this option is a filter which will
generate a filtered dvi file with the extension ".dviF". All extra
processing (e.g. conversion to postscript, preview, printing) will then
be performed on this filtered dvi file.
Example usage: To use dviselect to select only the even pages of the dvi file:
- -diagnostics
-
Print detailed diagnostics during a run. This may help for debugging
problems or to understand latexmk's behavior in difficult
situations.
- -dir-report
-
For each .tex file processed, list the settings for aux and out
directories, after they have been normalized from the settings specified
during initialization. See the description of the variable
$aux_out_dir_report for more details.
- -dir-report-
-
Do not report the settings for aux and out directories. (Default)
- -dvi
-
Generate dvi version of document.
- -dvi-
-
Turn off generation of dvi version of document. (This may get
overridden, if some other file is made (e.g., a .ps file) that is
generated from the dvi file, or if no generated file at all is
requested.)
- -e <code>
-
Execute the specified initialization code before processing. The code
is Perl code of the same form as is used in latexmk's
initialization files. For more details,
see the information on the
-r option, and the section about "Configuration/initialization
(RC) files". The code is typically a sequence of assignment
statements separated by semicolons.
The code is executed when the -e option is encountered during latexmk's parsing of its command line. See the -r option for a way of executing initialization code from a file. An error results in latexmk stopping. Multiple instances of the -r and -e options can be used, and they are executed in the order they appear on the command line.
Some care is needed to deal with proper quoting of special characters in the code on the command line. For example, suppose you want to set the latex command to use its -shell-escape option, then under UNIX/Linux you could use the line
Note that the single quotes block normal UNIX/Linux command shells from treating the characters inside the quotes as special. (In this example, the q/.../ construct is a Perl idiom equivalent to using single quotes. This avoids the complications of getting a quote character inside an already quoted string in a way that is independent of both the shell and the operating-system.)
The above command line will NOT work under MS-Windows with cmd.exe or command.com or 4nt.exe. For MS-Windows with these command shells you could use
or
The last two examples will NOT work with UNIX/Linux command shells.
(Note: the above examples show are to show how to use the -e to specify initialization code to be executed. But the particular effect can be achieved also by the use of the -latex option with less problems in dealing with quoting.)
- -emulate-aux-dir
-
Emulate -aux-directory instead of leaving it to the *latex programs
to do it. (MiKTeX supports -aux-directory, but TeXLive doesn't.)
For more details see the explanation for the configuration variable $emulate_aux.
- -emulate-aux-dir-
-
Turn off emulatation -aux-directory and leave it to the *latex program
to handle the case that aux_dir is not equal to out_dir. Note that if you
use TeXLive, which doesn't support -aux-directory, latexmk will
automatically switch aux_dir emulation on after the first run of *latex,
because it will find the .log file in the wrong place.
- -f
-
Force latexmk to continue document processing despite errors.
Normally, when latexmk detects that LaTeX or another program has
found an error which will not be resolved by further processing, no
further processing is carried out.
Note: "Further processing" means the running of other programs or the rerunning of latex (etc) that would be done if no errors had occurred. If instead, or additionally, you want the latex (etc) program not to pause for user input after an error, you should arrange this by an option that is passed to the program, e.g., by latexmk's option -interaction=nonstopmode (which latexmk passes to *latex).
- -f-
-
Turn off the forced processing-past-errors such as is set by the
-f option. This could be used to override a setting in a
configuration file.
- -g
-
Force latexmk to process document fully, even under situations
where latexmk would normally decide that no changes in the
source files have occurred since the previous run.
This option is useful, for example, if you change some options and
wish to reprocess the files.
- -g-
-
Turn off -g.
- -gg
-
"Super go mode" or "clean make": clean out generated files as if
-C had been given, and then do a regular make.
- -h or-non-help
-
Print help information.
- -jobname=STRING
-
Set the basename of output files(s) to STRING, instead of the default,
which is the basename of the specified TeX file. (At present, STRING
should not contain spaces.)
This is like the same option for current implementations of the *latex, and the passing of this option to these programs is part of latexmk's implementation of -jobname.
There is one enhancement, that the STRING may contain the placeholder '%A'. This will be substituted by the basename of the TeX file. The primary purpose is when multiple files are specified on the command line to latexmk, and you wish to use a jobname with a different file-dependent value for each file. For example, suppose you had .tex files test1.tex and test2.tex, and you wished to compare the results of compilation by *latex and those with xelatex. Then under a unix-type operating system you could use the command line
latexmk -pdf -jobname=%A-pdflatex *.tex
latexmk -pdfxe -jobname=%A-xelatex *.tex Then the .aux, .log, and .pdf files from the use of pdflatex would have basenames test1-pdflatex and test2-pdflatex, while from xelatex, the basenames would be test1-xelatex and test2-xelatex.
Under MS-Windows with cmd.exe, you would need to double the percent sign, so that the percent character is passed to latexmk rather than being used to substitute an environment variable:
latexmk -pdf -jobname=%%A-pdflatex *.tex
latexmk -pdfxe -jobname=%%A-xelatex *.tex - -l
- Run in landscape mode, using the landscape mode for the previewers and the dvi to postscript converters. This option is not normally needed nowadays, since current previewers normally determine this information automatically.
- -l-
- Turn off -l.
- -latex
- This sets the generation of dvi files by latex, and turns off the generation of pdf and ps files.
Note: to set the command used when latex is specified, see the -latex="COMMAND" option.
- -latex=COMMAND
- This sets the string specifying the command to run latex, and is typically used to add desired options. Since the string normally contains spaces, it should be quoted, e.g.,
latexmk -latex="latex --shell-escape %O %S" foo.tex The specification of the contents of the string are the same as for the $latex configuration variable. Depending on your operating system and the command-line shell you are using, you may need to change the single quotes to double quotes (or something else).
Note: This option when provided with the COMMAND argument only sets the command for invoking latex; it does not turn on the use of latex. That is done by other options or in an initialization file.
To set the command for running pdflatex (rather than the command for latex) see the -pdflatex option.
- -logfilewarninglist
- -logfilewarnings After a run of *latex, give a list of warnings about undefined citations and references (unless silent mode is on).
See also the $silence_logfile_warnings configuration variable.
- -logfilewarninglist-
- -logfilewarnings- After a run of *latex, do not give a list of warnings about undefined citations and references. (Default)
See also the $silence_logfile_warnings configuration variable.
- -lualatex
- Use lualatex. That is, use lualatex to process the source file(s) to pdf. The generation of dvi and postscript files is turned off.
This option is equivalent to using the following set of options
-pdflua -dvi- -ps- (Note: Note that the method of implementation of this option, but not its intended effect, differ from some earlier versions of latexmk.)
- -lualatex=COMMAND
- This sets the string specifying the command to run lualatex. It behaves like the -pdflatex option, but sets the variable $lualatex.
Note: This option when provided with the COMMAND argument only sets the command for invoking lualatex; it does not turn on the use of lualatex. That is done by other options or in an initialization file.
- -M
- Show list of dependent files after processing. This is equivalent to the -deps option.
- -MF file
- If a list of dependents is made, the -MF specifies the file to write it to.
- -MP
- If a list of dependents is made, include a phony target for each source file. If you use the dependents list in a Makefile, the dummy rules work around errors the program make gives if you remove header files without updating the Makefile to match.
- -makeindexfudge
- Turn on the change-directory fudge for makeindex. See documentation of $makeindex_fudge for details.
- -makeindexfudge-
- Turn off the change-directory fudge for makeindex. See documentation of $makeindex_fudge for details.
- -MSWinBackSlash
- This option only has an effect when latexmk is running under MS-Windows. This is that when latexmk runs a command under MS-Windows, the Windows standard directory separator "\" is used to separate directory components in a file name. Internally, latexmk uses "/" for the directory separator character, which is the character used by Unix-like systems.
This is the default behavior. However the default may have been overridden by a configuration file (latexmkrc file) which sets $MSWin_back_slash=0.
- -MSWinBackSlash-
- This option only has an effect when latexmk is running under MS-Windows. This is that when latexmk runs a command under MS-Windows, the substitution of "\" for the separator character between directory components of a file name is not done. Instead the forward slash "/" is used, the same as on Unix-like systems. This is acceptable in most situations under MS-Windows, provided that filenames are properly quoted, as latexmk does by default.
See the documentation for the configuration variable $MSWin_back_slash for more details.
- -new-viewer
- When in continuous-preview mode, always start a new viewer to view the generated file. By default, latexmk will, in continuous-preview mode, test for a previously running previewer for the same file and not start a new one if a previous previewer is running. However, its test sometimes fails (notably if there is an already-running previewer that is viewing a file of the same name as the current file, but in a different directory). This option turns off the default behavior.
- -new-viewer-
- The inverse of the -new-viewer option. It puts latexmk in its normal behavior that in preview-continuous mode it checks for an already-running previewer.
- -nobibtex
- Never run bibtex or biber. Equivalent to the -bibtex- option.
- -nobibtexfudge or -nobibfudge
- Turn off the change-directory fudge for bibtex. See documentation of $bibtex_fudge for details.
- -noemulate-aux-dir
- Turn aux_dir emulation off. Same as -emulate-aux-dir-.
- -nomakeindexfudge
- Turn off the change-directory fudge for makeindex. See documentation of $makeindex_fudge for details.
- -norc
- Turn off the automatic reading of initialization (rc) files.
N.B. Normally the initialization files are read and obeyed, and then command line options are obeyed in the order they are encountered. But -norc is an exception to this rule: it is acted on first, no matter where it occurs on the command line.
- -outdir=FOO or -output-directory=FOO
Sets the directory for the output files of *latex. This achieves its effect by the -output-directory option of *latex, which currently (Dec. 2011 and later) is implemented on the common versions of *latex, i.e., MiKTeX and TeXLive. It may not be present in other versions.
See also the -auxdir/-aux-directory options, and the $aux_dir, $out_dir, and $search_path_separator configuration variables of latexmk. In particular, see the documentation of $out_dir for some complications on what directory names are suitable.
If you also use the -cd option, and the specified output directory is a relative path, then the path is interpreted relative to the document directory.
- -output-format=FORMAT
- This option is one that is allowed for latex, lualatex, and pdflatex. But it is not passed to these programs. Instead latexmk emulates it in a way suitable for the context of latexmk and its workflows.
If FORMAT is dvi, then dvi output is turned on, and postscript and pdf output are turned off. This is equivalent to using the options -dvi -ps- -pdf-.
If FORMAT is pdf, then pdf output is turned on, and dvi and postscript output are turned off. This is equivalent to using the options -pdf -ps- -dvi-.
If FORMAT is anything else, latexmk gives an error.
- -p
- Print out the document. By default the file to be printed is the first in the list postscript, pdf, dvi that is being made. But you can use the -print=... option to change the type of file to be printed, and you can configure this in a start up file (by setting the $print_type variable).
However, printing is enabled by default only under UNIX/Linux systems, where the default is to use the lpr command and only on postscript files. In general, the correct behavior for printing very much depends on your system's software. In particular, under MS-Windows you must have suitable program(s) available, and you must have configured the print commands used by latexmk. This can be non-trivial. See the documentation on the $lpr, $lpr_dvi, and $lpr_pdf configuration variables to see how to set the commands for printing.
This option is incompatible with the -pv and -pvc options, so it turns them off.
- -pdf
- Generate pdf version of document using pdflatex. (If you wish to use lualatex or xelatex, you can use whichever of the options -pdflua, -pdfxe, -lualatex or -xelatex applies.) To configure latexmk to have such behavior by default, see the section on "Configuration/initialization (rc) files".
- -pdfdvi
- Generate pdf version of document from the dvi file, by default using dvipdf.
- -pdflua
- Generate pdf version of document using lualatex.
- -pdfps
- Generate pdf version of document from the .ps file, by default using ps2pdf.
- -pdfxe
- Generate pdf version of document using xelatex. Note that to optimize processing time, latexmk uses xelatex to generate an .xdv file rather than a pdf file directly. Only after possibly multiple runs to generate a fully up-to-date .xdv file does latexmk then call xdvipdfmx to generate the final .pdf file.
(Note: The reason why latexmk arranges for xelatex to make an .xdv file instead of the xelatex's default of a .pdf file is as follows: When the document includes large graphics files, especially .png files, the production of a .pdf file can be quite time consuming, even when the creation of the .xdv file by xelatex is fast. So the use of the intermediate .xdv file can result in substantial gains in procesing time, since the .pdf file is produced once rather than on every run of xelatex.)
- -pdf-
- Turn off generation of pdf version of document. (This can be used to override a setting in a configuration file. It may get overridden if some other option requires the generation of a pdf file.)
If after all options have been processed, pdf generation is still turned off, then generation of a dvi file will be turned on, and then the program used to compiled a document will be latex (or, more precisely, whatever program is configured to be used in the $latex configuration variable).
- -pdflatex
- This sets the generation of pdf files by pdflatex, and turns off the generation of dvi and ps files.
Note: to set the command used when pdflatex is specified, see the -pdflatex="COMMAND" option.
- -pdflatex=COMMAND
- This sets the string specifying the command to run pdflatex, and is typically used to add desired options. Since the string normally contains spaces, it should be quoted, e.g.,
latexmk -pdf -pdflatex="pdflatex --shell-escape %O %S" foo.tex The specification of the contents of the string are the same as for the $pdflatex configuration variable. (The option -pdflatex in fact sets the variable $pdflatex.) Depending on your operating system and the command-line shell you are using, you may need to change the single quotes to double quotes (or something else).
Note: This option when provided with the COMMAND argument only sets the command for invoking pdflatex; it does not turn on the use of pdflatex. That is done by other options or in an initialization file.
To set the command for running latex (rather than the command for pdflatex) see the -latex option.
- -pdflualatex=COMMAND
- Equivalent to -lualatex="COMMAND".
- -pdfxelatex=COMMAND
- Equivalent to -xelatex="COMMAND".
- -pretex=CODE
Given that CODE is some TeX code, this options sets that code to be executed before inputting source file. This only works if the command for invoking the relevant *latex is suitably configured. See the documentation of the variable $pre_tex_code, and the substitution strings %P and %U for more details. This option works by setting the variable $pre_tex_code.
See also the -usepretex option.
An example:
latexmk -pretex='\AtBeginDocument{Message\par}' -usepretex foo.tex But this is better written
latexmk -usepretex='\AtBeginDocument{Message\par}' foo.tex If you already have a suitable command configured, you only need
latexmk -pretex='\AtBeginDocument{Message\par}' foo.tex - -print=dvi, -print=ps, -print=pdf, -print=auto,
- Define which kind of file is printed. This option also ensures that the requisite file is made, and turns on printing.
The (default) case -print=auto determines the kind of print file automatically from the set of files that is being made. The first in the list postscript, pdf, dvi that is among the files to be made is the one used for print out.
- -ps
- Generate postscript version of document.
- -ps-
- Turn off generation of postscript version of document. This can be used to override a setting in a configuration file. (It may get overridden by some other option that requires a postscript file, for example a request for printing.)
- -pF
- Postscript file filtering. The argument to this option is a filter which will generate a filtered postscript file with the extension ".psF". All extra processing (e.g. preview, printing) will then be performed on this filtered postscript file.
Example of usage: Use psnup to print two pages on the one page:
or
Whether to use single or double quotes round the "psnup -2" will depend on your command interpreter, as used by the particular version of perl and the operating system on your computer.
- -pv
- Run file previewer. If the -view option is used, this will select the kind of file to be previewed (.dvi, .ps or .pdf). Otherwise the viewer views the "highest" kind of file selected, by the -dvi, -ps, -pdf, -pdfps options, in the order .dvi, .ps, .pdf (low to high). If no file type has been selected, the dvi previewer will be used. This option is incompatible with the -p and -pvc options, so it turns them off.
- -pv-
- Turn off -pv.
- -pvc
- Run a file previewer and continually update the .dvi, .ps, and/or .pdf files whenever changes are made to source files (see the Description above). Which of these files is generated and which is viewed is governed by the other options, and is the same as for the -pv option. The preview-continuous option -pvc can only work with one file. So in this case you will normally only specify one filename on the command line. It is also incompatible with the -p and -pv options, so it turns these options off.
The -pvc option also turns off force mode (-f), as is normally best for continuous preview mode. If you really want force mode, use the options in the order -pvc -f.
With a good previewer the display will be automatically updated. (Under some but not all versions of UNIX/Linux "gv -watch" does this for postscript files; this can be set by a configuration variable. This would also work for pdf files except for an apparent bug in gv that causes an error when the newly updated pdf file is read.) Many other previewers will need a manual update.
Important note: the acroread program on MS-Windows locks the pdf file, and prevents new versions being written, so it is a bad idea to use acroread to view pdf files in preview-continuous mode. It is better to use a different viewer: SumatraPDF and gsview are good possibilities.
There are some other methods for arranging an update, notably useful for many versions of xdvi and xpdf. These are best set in latexmk's configuration; see below.
Note that if latexmk dies or is stopped by the user, the "forked" previewer will continue to run. Successive invocations with the -pvc option will not fork new previewers, but latexmk will normally use the existing previewer. (At least this will happen when latexmk is running under an operating system where it knows how to determine whether an existing previewer is running.)
- -pvc-
- Turn off -pvc.
- -pvctimeout
- Do timeout in pvc mode after period of inactivity, which is 30 min. by default. Inactivity means a period when latexmk has detected no file changes and hence has not taken any actions like compiling the document.
- -pvctimeout-
- Don't do timeout in pvc mode after inactivity.
- -pvctimeoutmins=<time>
- Set period of inactivity in minutes for pvc timeout.
- -quiet
- Same as -silent
- -r <rcfile>
- Read the specified initialization file ("RC file") before processing.
Be careful about the ordering: (1) Standard initialization files -- see the section below on "Configuration/initialization (RC) files" -- are read first. (2) Then the options on the command line are acted on in the order they are given. Therefore if an initialization file is specified by the -r option, it is read during this second step. Thus an initialization file specified with the -r option can override both the standard initialization files and previously specified options. But all of these can be overridden by later options.
The contents of the RC file just comprise a piece of code in the Perl programming language (typically a sequence of assignment statements); they are executed when the -r option is encountered during latexmk's parsing of its command line. See the -e option for a way of giving initialization code directly on latexmk's command line. An error results in latexmk stopping. Multiple instances of the -r and -e options can be used, and they are executed in the order they appear on the command line.
- -rc-report
- After initialization, give a list of the RC files read. (Default)
- -rc-report-
- After initialization, do not give a list of the RC files read.
- -recorder
- Give the -recorder option with *latex. In (most) modern versions of these programs, this results in a file of extension .fls containing a list of the files that these programs have read and written. Latexmk will then use this file to improve its detection of source files and generated files after a run of *latex. This is the default setting of latexmk, unless overridden in an initialization file.
For further information, see the documentation for the $recorder configuration variable.
- -recorder-
- Do not supply the -recorder option with *latex.
- -rules
- Show a list of latemk's rules and dependencies after processing.
- -rules-
- Do not show a list of latexmk's rules and dependencies after processing. (This is the default.)
- -showextraoptions
- Show the list of extra *latex options that latexmk recognizes, but that it simply passes through to the programs *latex when they are run. These options are (currently) a combination of those allowed by the TeXLive and MiKTeX implementations. (If a particular option is given to latexmk but is not handled by the particular implementation of *latex that is being used, that program will probably give a warning or an error.) These options are very numerous, but are not listed in this documentation because they have no effect on latexmk's actions.
There are a few options (e.g., -includedirectory=dir, -initialize, -ini) that are not recognized, either because they don't fit with latexmk's intended operations, or because they need special processing by latexmk that isn't implemented (at least, not yet).
There are certain options for *latex (e.g., -recorder) that trigger special actions or behavior by latexmk itself. Depending on the action, they may also be passed in some form to the called *latex program, and/or may affect other programs as well. These options do have entries in this documentation. Among these options are: -jobname=STRING, -aux-directory=dir, -output-directory=DIR, -quiet, and -recorder.
There are also options that are accepted by *latex, but instead trigger actions purely by latexmk: -help, -version.
- -silent
- Run commands silently, i.e., with options that reduce the amount of diagnostics generated. For example, with the default settings, the command "latex -interaction=batchmode" is used for latex, and similarly for its friends.
See also the -logfilewarninglist and -logfilewarninglist- options.
Also reduce the number of informational messages that latexmk itself generates.
To change the options used to make the commands run silently, you need to configure latexmk with changed values of its configuration variables, the relevant ones being $bibtex_silent_switch, $biber_silent_switch, $dvipdf_silent_switch, $dvips_silent_switch, $latex_silent_switch, $lualatex_silent_switch $makeindex_silent_switch, $pdflatex_silent_switch, and $xelatex_silent_switch
- -stdtexcmds
- Sets the commands for latex, etc, so that they are the standard ones. This is useful to override special configurations.
The result is that $latex = 'latex %O %S', and similarly for $pdflatex, $lualatex, and $xelatex. (The option -no-pdf needed for $xelatex is provided automatically, given that %O appears in the definition.)
- -time
- Show CPU time used. See also the configuration variable $show_time.
- -time-
- Do not show CPU time used. See also the configuration variable $show_time.
- -use-make
- When after a run of *latex, there are warnings about missing files (e.g., as requested by the LaTeX \input, \include, and \includgraphics commands), latexmk tries to make them by a custom dependency. If no relevant custom dependency with an appropriate source file is found, and if the -use-make option is set, then as a last resort latexmk will try to use the make program to try to make the missing files.
Note that the filename may be specified without an extension, e.g., by \includegraphics{drawing} in a LaTeX file. In that case, latexmk will try making drawing.ext with ext set in turn to the possible extensions that are relevant for latex (or as appropriate pdflatex, lualatex, xelatex).
See also the documentation for the $use_make_for_missing_files configuration variable.
- -use-make-
- Do not use the make program to try to make missing files. (Default.)
- -usepretex
- Sets the command lines for latex, etc, so that they use the code that is defined by the variable $pre_tex_code or that is set by the option -pretex=CODE to execute the specified TeX code before the source file is read. This option overrides any previous definition of the command lines.
The result is that $latex = 'latex %O %P', and similarly for $pdflatex, $lualatex, and $xelatex. (The option -no-pdf needed for $xelatex is provided automatically, given that %O appears in the definition.)
- -usepretex=CODE
- Equivalent to -pretex=CODE -usepretex. Example
latexmk -usepretex='\AtBeginDocument{Message\par}' foo.tex - -v or -version
- Print version number of latexmk.
- -verbose
- Opposite of -silent. This is the default setting.
- -view=default, -view=dvi, -view=ps, -view=pdf, -view=none
- Set the kind of file used when previewing is requested (e.g., by the -pv or -pvc switches). The default is to view the "highest" kind of requested file (in the low-to-high order .dvi, .ps, .pdf).
Note the possibility -view=none where no viewer is opened at all. One example of is use is in conjunction with the -pvc option, when you want latexmk to do a compilation automatically whenever source file(s) change, but do not want a previewer to be opened.
- -Werror
- This causes latexmk to return a non-zero status code if any of the files processed gives a warning about problems with citations or references (i.e., undefined citations or references or about multiply defined references). This is after latexmk has completed all the runs it needs to try and resolve references and citations. Thus -Werror causes latexmk to treat such warnings as errors, but only when they occur on the last run of *latex and only after processing is complete. Also can be set by the configuration variable $warnings_as_errors.
- -xelatex
- Use xelatex. That is, use xelatex to process the source file(s) to pdf. The generation of dvi and postscript files is turned off.
This option is equivalent to using the following set of options
-pdfxe -dvi- -ps- [Note: Note that the method of implementation of this option, but not its intended primary effect, differ from some earlier versions of latexmk. Latexmk first uses xelatex to make an .xdv file, and does all the extra runs needed (including those of bibtex, etc). Only after that does it make the pdf file from the .xdv file, using xdvipdfmx. See the documentation for the -pdfxe for why this is done.]
- -xelatex=COMMAND
- This sets the string specifying the command to run xelatex. It sets the variable $xelatex.
Warning: It is important to ensure that the -no-pdf is used when xelatex is invoked, since latexmk expects xelatex to produce an .xdv file, not a .pdf file. If you provide %O in the command specification, this will be done automatically. See the documentation for the -pdfxe option for why latexmk makes a .xdv file rather than a .pdf file when xelatex is used.
An example of the use of the -pdfxelatex option:
latexmk -pdfxe -pdfxelatex="xelatex --shell-escape %O %S" foo.tex Note: This option when provided with the COMMAND argument only sets the command for invoking lualatex; it does not turn on the use of lualatex. That is done by other options or in an initialization file.
Compatibility between options
The preview-continuous option -pvc can only work with one file. So in this case you will normally only specify one filename on the command line.
Options -p, -pv and -pvc are mutually exclusive. So each of these options turns the others off.
EXAMPLES
% latexmk thesis # run latex enough times to resolve cross-references % latexmk -pvc -ps thesis# run latex enough times to resolve cross-references, make a postscript file, start a previewer. Then watch for changes in the source file thesis.tex and any files it uses. After any changes rerun latex the appropriate number of times and remake the postscript file. If latex encounters an error, latexmk will keep running, watching for source file changes. % latexmk -c # remove .aux, .log, .bbl, .blg, .dvi, .pdf, .ps & .bbl files
DEALING WITH ERRORS, PROBLEMS, ETC
Some possibilities:
a. If you get a strange error, do look carefully at the output that is on the screen and in log files. While there is much that is notoriously verbose in the output of latex (and that is added to by latexmk), the verbosity is there for a reason: to enable the user to diagnose problems. Latexmk does repeat some messages at the end of a run that it thinks would otherwise be easy to miss in the middle of other output.
b. Generally, remember that latexmk does its work by running other programs. Your first priority in dealing with errors should be to examine what went wrong with the individual programs. Then you need to correct the causes of errors in the runs of these programs. (Often these come from errors in the source document, but they could also be about missing LaTeX packages, etc.)
c. If latexmk doesn't run the programs the way you would like, then you need to look in this documentation at the list of command line options and then at the sections on configuration/initialization files. A lot of latexmk's behavior is configurable to deal with particular situations. (But there is a lot of reading!)
The remainder of these notes consists of ideas for dealing with more difficult situations.
d. Further tricks can involve replacing the standard commands that latexmk runs by other commands or scripts.
e. For possible examples of code for use in an RC file, see the directory example_rcfiles in the distribution of latexmk (e.g., at http://mirror.ctan.org/support/latexmk/example_rcfiles). Even if these examples don't do what you want, they may provide suitable inspiration.
f. There's a useful trick that can be used when you use lualatex instead of pdflatex (and in some related situations). The problem is that latexmk won't notice a dependency on a file, bar.baz say, that is input by the lua code in your document instead of by the LaTeX part. (Thus if you change bar.baz and rerun latexmk, then latexmk will think no files have changed and not rerun lualatex, whereas if you had '\input{bar.baz}' in the LaTeX part of the document, latexmk would notice the change.) One solution is just to put the following somewhere in the LaTeX part of the document:
This puts a line in the log file that latexmk will treat as
implying that the file bar.baz was read. (At present I don't know a
way of doing this automatically.) Of course, if the file has a
different name, change bar.baz to the name of your file.
g. See also the section "Advanced Configuration: Some extra resources".
h. Look on tex.stackexchange, i.e., at
http://tex.stackexchange.com/questions/tagged/latexmk Someone may
have already solved your problem.
i. Ask a question at tex.stackexchange.com.
j. Or ask me (the author of latexmk). My e-mail is at the end
of this documentation.
When one of the latex engines is run, the usual situation is that
latex produces a .dvi file, while pdflatex and
lualatex produce a .pdf file. For xelatex the default is
to produce a .pdf file, but to optimize processing time latexmk
runs xelatex its -no-pdf option so that it produces
an .xdv file. Further processing by latexmk takes this as a
starting point.
However, the actual output file may differ from the normal
expectation; and then latexmk can adjust its processing to
accommodate this situation. The difference in output file type can
happen for two reasons: One is that for latex, pdflatex
and lualatex the document itself can override the defaults. The
other is that there may be a configuration, or misconfiguration, such
that the program that latexmk invokes to compile the document is
not the expected one, or is given options incompatible with what
latexmk initially expects.
Under latex and pdflatex, control of the output format by
the document is done by setting the \pdfoutput macro. Under
lualatex, the \outputmode macro is used instead.
One example of an important use-case for document control of the
output format is a document that uses the psfrag package to insert
graphical elements in the output file. The psfrag package achieves its
effects by inserting postscript code in the output of the compilation
of the document. This entails the use of compilation to a .dvi file,
followed by the use of conversion to a postscript file (either
directly, as by dvips or implicitly, as an intermediate step by
dvipdf). Then it is useful to force output to be of the .dvi
format by inserting \pdfoutput=0 in the preamble of the document.
Another example is where the document uses graphics file of
the .pdf, .jpg, and png types. With the default setting for the
graphicx package, these can be processed in compilation to .pdf but
not with compilation to .dvi. In this case, it is useful to insert
\pdfoutput=1 in the preamble of the document to force compilation
to .pdf output format.
In all of these cases, it is needed that latexmk has to adjust
its processing to deal with a mismatch between the actual output
format (out of .pdf, .dvi, .xdv) and the initially expected output, if
possible. Latexmk does this provided the following conditions
are met.
The first is that latexmk's $allow_switch configuration
variable is set to a non-zero value as it is by default. If this
variable is zero, a mismatch of filetypes in the compilation results
in an error.
The second condition for latexmk to be able to handle a change
of output type is that no explicit requests for .dvi or .ps output
files are made. Explicit requests are by the -dvi and
-ps, -print=dvi, -print=ps, -view=dvi, and
-view=ps options, and by corresponding settings of the
$dvi_mode, $postscript_mode, $print_type, and
$view configuration variables. The print-type and view-type
restrictions only apply when printing and viewing are explicitly
requested, respectively. For this purpose, the use of the
-pdfdvi and -pdfps options (and the corresponding setting
of the $pdf_mode variable) does not count as an explicit request
for the .dvi and .ps files; they are merely regarded as a request for
making a .pdf file together with an initial proposal for the
processing route to make it.
Note that when accommodating a change in output file type, there is
involved a substantial change in the network of rules that
latexmk uses in its actions. The second condition applied to
accommodate a change is to avoid situations where the change in the
rule network is too radical to be readily handled automatically.
In this section is explained which configuration files are read by
latexmk. Subsequent sections "How to Set Variables in
Initialization Files", "Format of Command Specifications", "List of
Configuration Variables Usable in Initialization Files", "Custom
Dependencies", and "Advanced Configuration" give details on what can
be configured and how.
Latexmk can be customized using initialization files, which are
read at startup in the following order:
1) The system RC file, if it exists.
If the environment variable LATEXMKRCSYS is set, its value is used as
the name of the system RC file, instead of any of the above.
2) The user's RC file, if it exists. This can be in one of two
places. The traditional one is ".latexmkrc" in the user's home
directory. The other possibility is "latexmk/latexmkrc" in the user's
XDG configuration home directory. The actual file read is the first
of "$XDG_CONFIG_HOME/latexmk/latexmkrc" or "$HOME/.latexmkrc" which
exists. (See
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
for details on the XDG Base Directory Specification.)
Here $HOME
is the user's home directory. [Latexmk determines the user's
home directory as follows: It is the value of the environment variable
HOME, if this variable exists, which normally is the case on UNIX-like
systems (including Linux and OS-X). Otherwise the environment
variable USERPROFILE is used, if it exists, which normally is the case
on MS-Windows systems. Otherwise a blank string is used instead of
$HOME, in which case latexmk does not look for an RC file in
it.]
$XDG_CONFIG_HOME is the value of the environment variable
XDG_CONFIG_HOME if it exists. If this environment variable does not
exist, but $HOME is non-blank, then $XDG_CONFIG_HOME is set to the
default value of $HOME/.config. Otherwise $XDG_CONFIG_HOME is blank,
and latexmk does not look for an RC file under it.
3) The RC file in the current working directory. This file can be
named either "latexmkrc" or ".latexmkrc", and the first of these to be
found is used, if any.
4) Any RC file(s) specified on the command line with the -r
option.
Each RC file is a sequence of Perl commands. Naturally, a user can use
this in creative ways. But for most purposes, one simply uses a
sequence of assignment statements that override some of the built-in
settings of Latexmk. Straightforward cases can be handled
without knowledge of the Perl language by using the examples in this
document as templates. Comment lines are introduced by the "#"
character.
Note that command line options are obeyed in the order in which
they are written; thus any RC file specified on the command line with
the -r option can override previous options but can be itself
overridden by later options on the command line. There is also the
-e option, which allows initialization code to be specified in
latexmk's command line.
For possible examples of code for in an RC file, see the directory
example_rcfiles in the distribution of latexmk (e.g., at
http://mirror.ctan.org/support/latexmk/example_rcfiles).
The important variables that can be configured are described in the
section "List of configuration variables usable in initialization
files". (See the earlier section "Configuration/Initialization (rc)
Files" for the files where the configurations are done.) Syntax for
setting these variables is of the following forms:
for the setting of a string variable,
for the setting of a numeric variable, and
for the setting of an array of strings. It is possible to append an
item to an array variable as follows:
Note that simple "scalar" variables have names that begin with a $
character and array variables have names that begin with a @
character. Each statement ends with a semicolon.
Strings should be enclosed in single quotes. (You could use double
quotes, as in many programming languages. But then the Perl
programming language brings into play some special rules for
interpolating variables into strings. People not fluent in Perl
will want to avoid these complications.)
You can do much more complicated things, but for this you will need to
consult a manual for the Perl programming language.
Some of the variables set the commands that latexmk uses for
carrying out its work, for example to generate a .dvi file from a .tex
file or to view a postscript file. This section describes some
important features of how the commands are specified.
(Note that some of the possibilities listed here do not apply to
the $kpsewhich variable; see its documentation.)
Placeholders: Supposed you wanted latexmk to use the
command elatex in place of the regular latex command, and suppose
moreover that you wanted to give it the option "--shell-escape". You
could do this by the following setting:
The two items starting with the % character are placeholders. These
are substituted by appropriate values before the command is run. Thus
%S will be replaced by the source file that elatex will be applied to,
and %O will be replaced by any options that latexmk has decided
to use for this command. (E.g., if you used the -silent option in the
invocation of latexmk, it results in the replacement of %O by
"-interaction=batchmode".)
The available placeholders are:
If the variable $pre_tex_code is the empty string, then %P is
equivalent to %S.
By default this is the basename of the main tex file. However the
value can be changed by the use of the -jobname option or the
$jobname configuration variable.
If for some reason you need a literal % character in your string not
subject to the above rules, use "%%".
Appropriate quoting will be applied to the filename substitutions, so
you mustn't supply them yourself even if the names of your files have
spaces in them. (But if your TeX filenames have spaces in them,
beware that some older versions of the TeX program cannot correctly handle
filenames containing spaces.) In case latexmk's quoting does not work
correctly on your system, you can turn it off -- see the documentation
for the variable $quote_filenames.
See the default values in the section "List of configuration variables
usable in initialization files" for what is normally the most
appropriate usage.
If you omit to supply any placeholders whatever in the specification
of a command, latexmk will supply what its author thinks are
appropriate defaults. This gives compatibility with configuration
files for previous versions of latexmk, which didn't use
placeholders.
"Detaching" a command: Normally when latexmk runs a
command, it waits for the command to run to completion. This is
appropriate for commands like latex, of course. But for previewers,
the command should normally run detached, so that latexmk gets
the previewer running and then returns to its next task (or exits if
there is nothing else to do). To achieve this effect of detaching a
command, you need to precede the command name with "start ", as in
This will be translated to whatever is appropriate for your operating
system.
Notes: (1) In some circumstances, latexmk will always run a
command detached. This is the case for a previewer in preview
continuous mode, since otherwise previewing continuously makes no
sense. (2) This precludes the possibility of running a command named
start. (3) If the word start occurs more than once at the beginning
of the command string, that is equivalent to having just one. (4)
Under cygwin, some complications happen, since cygwin amounts to a
complicated merging of UNIX and MS-Windows. See the source code for
how I've handled the problem.
Command names containing spaces: Under MS-Windows it is common
that the name of a command includes spaces, since software is often
installed in a subdirectory of "C:\Program Files". Such command names
should be enclosed in double quotes, as in
(Note about the above example: Under MS-Windows forward slashes are
equivalent to backslashes in a filename under almost all circumstances,
provided that the filename
is inside double quotes. It is easier to use forward slashes in
examples like the one above, since then one does not have to worry
about the rules for dealing with forward slashes in strings in the
Perl language.)
Command names under Cygwin: If latexmk is executed by Cygwin's
Perl, be particularly certain that pathnames in commands have
forward slashes not the usual backslashes for the separator
of pathname components. See the above examples. Backslashes often
get misinterpreted by the Unix shell used by Cygwin's Perl to execute
external commands. Forward slashes don't suffer from this problem,
and (when quoted, as above) are equally acceptable to MS-Windows.
Using MS-Windows file associations: A useful trick under modern
versions of MS-Windows (e.g., WinXP) is to use just the
command 'start' by itself:
Under MS-Windows, this will cause to be run
whatever program the system has associated with dvi files. (The same
applies for a postscript viewer and a pdf viewer.) But note that this
trick is not always suitable for the pdf previwer, if your system has
acroread for the default pdf viewer. As explained elsewhere, acroread
under MS-Windows does not work well with latex and
latexmk, because acroread locks the pdf file.
Not using a certain command: If a command is not to be run, the
command name NONE is used, as in
This typically is used when an appropriate command does not exist on
your system. The string after the "NONE" is effectively a comment.
Options to commands:
Setting the name of a command can be used not only for changing the
name of the command called, but also to add options to command.
Suppose you want latexmk to use latex with source specials
enabled. Then you might use the following line in an initialization
file:
Running a subroutine instead of an external command: Use a
specification starting with "internal", as in
For some of the more exotic possibilities that then become available,
see the section "ADVANCED CONFIGURATION: Some extra resources and
advanced tricks". Also see some of the examples in the directory
example_rcfiles in the latexmk distribution.
Advanced tricks: Normally one specifies a single command for the
commands invoked by latexmk. Naturally, if there is some
complicated additional processing you need to do in your special
situation, you can write a script (or batch file) to do the
processing, and then configure latexmk to use your script in
place of the standard program.
You can also use a Perl subroutine instead of a script -- see above.
This is generally the most flexible and portable solution.
It is also possible to configure latexmk to run multiple
commands. For example, if when running pdflatex to generate a pdf
file from a tex file you need to run another program after pdflatex to
perform some extra processing, you could do something like:
This definition assumes you are using a UNIX-like system (which
includes Linux and OS-X), so that the
two commands to be run are separated by the semicolon in the middle of
the string.
If you are using MS-Windows, you would replace the above line by
Here, the UNIX command separator ; is replaced by &&. In addition,
there is a problem that some versions of Perl on MS-Windows do
not obey the command separator; this problem is overcome by explicitly
invoking the MS-Windows command-line processor cmd.exe.
In this section are specified the variables whose values can be
adjusted to configure latexmk. (See the earlier section
"Configuration/Initialization (rc) Files" for the files where the
configurations are done.)
Default values are indicated in brackets. Note that for variables
that are boolean in character, concerning whether latexmk does
or does not behave in a certain way, a non-zero value, normally 1,
indicates true, i.e., the behavior occurs, while a zero value
indicates a false value, i.e., the behavior does not occur.
This controls what happens when the output extension of latex,
pdflatex, lualatex or xelatex differs from what is expected. (The
possible extensions are .dvi, .pdf, .xdv.) This can happen with the
use of the \pdfoutput macro in a document compiled under latex
or pdflatex, or with the use of the \outputmode macro under
lualatex. It can also happen with certain kinds of incorrect
configuration.
In such a case, latexmk can appropriately adjust its network of
rules. The adjustment is made if $allow_switch is on, and if no
request for a dvi or ps file has been made.
See the section ALLOWING FOR CHANGE OF OUTPUT EXTENSION.
This use of a temporary file solves a problem that the making of these
files can occupy a substantial time. If a viewer (notably gv)
sees that the file has changed, it may read the new file before
the program writing the file has not yet finished its work, which can
cause havoc.
See the $pvc_view_file_via_temporary variable for a setting that
applies only if preview-continuous mode (-pvc option) is used. See
$tmpdir for the setting of the directory where the temporary
file is created.
After a run of latex (etc), always analyze .log for input files in the
<...> and (...) constructions. Otherwise, only do the analysis when
fls file doesn't exist or is out of date.
Under normal circumstances, the data in the fls file is reliable, and
the test of the log file gets lots of false positives; usually
$analyze_input_log_always is best set to zero. But the test of the
log file is needed at least in the following situation: When a user
needs to persuade latexmk that a certain file is a source file, and
latexmk doesn't otherwise find it. Then the user can write code that
causes a line with (...) to be written to log file. One important
case is for lualatex, which doesn't always generate lines in the .fls
file for input lua files. (The situation with lualatex is HIGHLY
version dependent, e.g., there was a big change between TeXLive 2016
and TeXLive 2017.)
To keep backward compatibility with older versions
of latexmk, the default is to set
$analyze_input_log_always to 1.
This variable does not affect the reading of RC files specified on the
command line by the -r option.
Important note: The effect of $aux_dir, if different from
$out_dir, is achieved by giving *latex the
-aux-directory. Currently (Dec. 2011 and later) this only works on the
MiKTeX version of *latex.
See also the documentation of $out_dir for some complications on
what directory names are suitable.
If you also use the -cd option, and $out_dir (or $aux_dir) contains a
relative path, then the path is interpreted relative to the document
directory.
This report gives a reminder of where to look for output.
The report has to be done per file, because of possible directory changes
for each file. In the simplest cases, the result is the same as originally
specified. In general, e.g., with an absolute directory specified, the
normalization helps performance and cleans up output to the screen. It also
avoids situations where a file in the current directory is referred to by
different names, e.g., "file.aux" and "./file.aux", which can be annoying.
Note that if $banner is nonzero, the $postscript_mode is
assumed and the postscript file is always generated, even if it is newer
than the dvi file.
Note that under MS Windows, either a forward slash "/" or a backward
slash "\" can be used to separate pathname components, so the first
two and the second two examples are equivalent. Each backward slash
should be doubled to avoid running afoul of Perl's rules for writing
strings.
Important note: This variable is now mostly obsolete in the
current version of latexmk,
since it has a better method of searching for files using the
kpsewhich command. However, if your system is an unusual one without
the kpsewhich command, you may need to set the variable @BIBINPUTS.
The need arises as follows:
a. With bibtex before about 2019, if the filename given to it contains a
path component, there was a bug that bibtex would not find extra aux files,
as produced by the \include command in TeX.
b. With all moderately recent versions of bibtex, bibtex may refuse to
write its bbl and blg files, for security reasons, for certain cases of the
path component of the filename given to it.
However, there are also rare cases where the change-directory method
prevents bibtex from finding certain bib or bst files. Then
$bibtex_fudge needs to be set to 0.
The possible values of $bibtex_use are:
Note that the value 1.5 does not work properly if the document
uses biber instead of bibtex. (There's a long story why
not.)
This operation is somewhat dangerous, and can have unintended
consequences, since the files to be deleted are determined from a file
created by *latex, which can contain erroneous
information. Therefore this variable is turned off by default, and
then files to be deleted are restricted to those explicitly specified
by patterns configured in the variables clean_ext,
clean_full_ext, and @generated_exts, together with those
very standard cases that are hardwired into latexmk (e.g., .log
files).
This variable is equivalent to specifying one of
the -c or -C options. But there should be no need
to set this variable from an RC file.
It is also possible to specify a more general pattern of file to be
deleted, by using the place holder %R, as in commands, and it is also
possible to use wildcards. Thus setting
in an initialization file will imply that when a clean-up operation is
specified, not only is the standard set of files deleted, but also
files of the form FOO.out, FOO-blx.bib, FOO-figures*.log, and
pythontex-files-FOO/*, where FOO stands for the basename of the file
being processed (as in FOO.tex).
The files to be deleted are relative to the directory specified by
$aux_dir. (Note that if $out_dir but not $aux_dir
is set, then in its initialization, latexmk sets $aux_dir
equal to $out_dir. A normal situation is therefore that $aux_dir
equals $out_dir, which is the only case supported by
TeXLive, unlike MiKTeX.)
The filenames specified for a clean-up operation can refer not only to
regular files but also to directories. Directories are only deleted
if they are empty. An example of an application is to pythontex, which
creates files in a particular directory. You can arrange to remove
both the files and the directory by setting
See also the variable @generated_exts.
More general patterns are allowed, as for $clean_ext.
The files specified by $clean_full_ext to be deleted are
relative to the directory specified by $out_dir.
These variables specify commands that are executed at certain points
of compilations. One motivation for
their existence is to allow very useful convenient visual indications of
compilation status even when the window receiving the screen output of
the compilation is hidden. This is particularly useful in
preview-continuous mode.
The commands are executed at the following points:
$compiling_cmd at the start of compilation, $success_cmd
at the end of a completely successful compilation, $failure_cmd
at the end of an unsuccessful compilation, $warning_cmd at the
of an otherwise successful compilation that gives warnings about
undefined citations or references or about multiply defined
references. If any of above variables is undefined or blank (the
default situation), then the corresponding command is not executed.
However, when $warning_cmd is not set, then in the case of a
compilation with warnings about references or citations, but with no
other error, one or other of $success_cmd or $failure_cmd
is used (if it is set) according to the setting of
$warnings_as_errors.
An example of a simple setting of these variables is as follows
These assume that the program xdotool is installed, that the
previewer is using an X-Window system for display, and that the title
of the window contains the name of the displayed file, as it normally
does. When the commands are executed, the placeholder string %D is replaced by
the name of the destination file, which is the previewed file. The
above commands result in an appropriate string being appended to the
filename in the window title: " compiling", " OK", or " FAILURE".
Other placeholders that can be used are %S, %T, and %R, with %S and %T
normally being identical. These can be useful for a command changing
the title of the edit window. The visual indication in a window title
can useful, since the user does not have to keep shifting attention to
the (possibly hidden) compilation window to know the status of the
compilation.
More complicated situations can best be handled by defining a Perl
subroutine to invoke the necessary commands, and using the "internal"
keyword in the definitions to get the subroutine to be invoked. (See
the section "Format of Command Specifications" for how to do this.)
Naturally, the above settings that invoke the xdotool program
are only applicable when the X-Window system is used for the relevant
window(s). For other cases, you will have to find what software
solutions are available.
But sometimes you want to exclude particular files from this default
list. In that case you can specify the excluded files in the array
@default_excluded_files. For example if you wanted to process
all .tex files with the exception of common.tex, which is a not a
standard alone LaTeX file but a file input by some or all of the
others, you could do
If you have a variable or large number of files to be processed, this
method saves you from having to list them in detail in
@default_files and having to update the list every time you
change the set of files to be processed.
Notes: 1. This variable has no effect except when no files are
specified on the latexmk command line. 2. Wildcards are allowed
in @default_excluded_files.
If no filenames are specified on the command line,
latexmk processes all tex files specified in the @default_files
variable, which by default is set to all tex files ("*.tex") in the
current directory. This is a convenience: just run latexmk and
it will process an appropriate set of files. But sometimes you want
only some of these files to be processed. In this case you can list
the files to be processed by setting
@default_files in an initialization file
(e.g., the file "latexmkrc" in the current directory). Then if no
files are specified on the command line then the files you specify by
setting @default_files are processed.
Three examples:
ALLOWING FOR CHANGE OF OUTPUT FILE TYPE
CONFIGURATION/INITIALIZATION (RC) FILES
HOW TO SET VARIABLES IN INITIALIZATION FILES
FORMAT OF COMMAND SPECIFICATIONS
LIST OF CONFIGURATION VARIABLES USABLE IN INITIALIZATION FILES