LATEXMK(1)
okay so welcome to LATEXMK(1), bestie β itβs from the General Commands Manual, and itβs literally the whole vibe for latexmk, the LaTeX document generator. π
πΈ NAME πΈ
latexmkβ generate LaTeX document
β¨ SYNOPSIS β¨
latexmk [options] [file ...]
π DESCRIPTION π
okay so latexmk is the bestie who completely automates the process of compiling a LaTeX document. Think of it as a specialized relative of the general make utility, except it 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
latexmk [options] [file]
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 engine. 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,latexmkwill, by default, run on all files in the current working directory with a.texextension. This behavior can be changed: see the description concerning the@default_filesvariable 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:
latexmk foo
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 forward slash /, which is also a legal directory separator in Windows, and is accepted by latex etc. π
-auxdir=FOOor-aux-directory=FOOβ Sets the directory for auxiliary output files of*latex(.aux,.logetc.). These are all the generated files, with the exception of final output files (.dvi,.ps,.pdf,.synctex.gz,.synctex). See the-outdir/-output-directoryoption for directories for the main output files, and the-out2diroption for the final output files.
If the directory specified for the -aux/-aux-directory option is blank, then the default is used, which is to be the same as the output directory.
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.
See the section AUXILIARY AND OUTPUT DIRECTORIES for more details. π
-bibtexβ When the source file usesbblfiles for bibliography, runbibtexorbiberas needed to regenerate thebblfiles.
This property can also be configured by setting the $bibtex_use variable to 2 in a configuration file.
-bibtex-β Never runbibtexorbiber. Also, always treat.bblfiles 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 abblfile for the bibliography andbibtexis used to generate the bibliography, runbibtexas needed to regenerate thebblfiles only if the relevantbibfile(s) exist. Thus when thebibfile(s) are not available,bibtexis not run, thereby avoiding overwriting of thebblfile. Also, always treat.bblfiles 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. π«Ά
...bestie, the why behind this setting is honestly so real: it lets latexmk auto-switch between using bibtex and not using bibtex depending on whether a bib file exists or not. And second β when you're submitting an article to a scientific journal, it's super common to submit only .tex and .bbl files (plus your graphics files), but not a .bib file. So yeah, it's often useful to treat .bbl files as true source files, which means they should be preserved during a clean-up operation. π«Ά
You can also configure this property by setting the $bibtex_use variable to 1 in a configuration file.
Heads up π β when biber is used and a bib file doesn't exist, this option does not prevent biber from being run, and the bbl file ends up incorrect. See the documentation on $bibtex_use for the full details. However, a bbl file is treated as precious in a clean-up operation. π
-bibtex-cond1β same as-bibtex-condexcept that.bblfiles are only treated as precious if one or more bibfiles fails to exist.
So like, if all the bib files exist, bibtex gets run to generate .bbl files as needed, and then it's totally appropriate to delete the bbl files in a cleanup operation, since they can just be re-generated. β¨
This property can also be configured by setting the $bibtex_use variable to 1.5 in a configuration file.
Same biber caveat as above, fr fr π β when biber is used and a bib file doesn't exist, this option does not prevent biber from being run, with the bbl file then being incorrect. See the documentation on $bibtex_use for more details. However, a bbl file is treated as precious in a clean up operation.
-bibtexfudge,-bibfudgeβ turn on the change-directory fudge for bibtex. See the documentation of$bibtex_fudgefor details. π§-bibtexfudge-,-bibfudge-β turn off the change-directory fudge for bibtex. See the documentation of$bibtex_fudgefor 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, bestie. π
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 between0and1.0is black and1is white. The default is0.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 to1100divided by the number of characters in the message. The default is220.0, which is just right for 5 character messages. π-commandsβ list the commands used by latexmk for processing files, and then exit. Iconic little peek behind the curtain. π-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_extsconfiguration variable. In addition, files specified by the$clean_extand@generated_extsconfiguration variables are removed. πΈ
This cleanup is instead of a regular make. See the -gg option if you want 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 get 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 those files are not deleted.
-Cβ clean up (remove) all regeneratable files generated by latex and bibtex or biber. This is the same as the-coption, with the addition of dvi, postscript and pdf files, and those specified in the$clean_full_extconfiguration variable. π§Ή
This cleanup is instead of a regular make. See the -gg option if you want 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-Coption. See that option for details. She's retired, but she still shows up to the group chat. π-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-bsand-bioptions. The-bmoption will override this option, since this is really just a short way of specifying:
latexmk -bm DRAFT
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 that behave like those of gcc.) β¨
-dependentsβ equivalent to-deps. Same energy, different name. π¦-deps-β do not show a list of dependent files after processing. (This is the default.) πΈ-dependents-β equivalent to-deps-. π-deps-escape=<string>β set the kind of escaping used for spaces in the dependency list. The possible values are"none","unix","nmake", corresponding respectively to no escaping, escaping with a"\" suitable for standard Unix make, and escaping with"^", suitable for Microsoft's nmake. π-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:
latexmk -dF "dviselect even" foo.tex
-diagnosticsβ print detailed diagnostics during a run. This may help for debugging problems or to understand latexmk's behavior in difficult situations. π she's showing you her whole thought process, bestie.-dir-reportβ for each.texfile 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_reportfor more details. π-dir-report-β do not report the settings for aux and out directories. (Default) π€-dir-report-onlyβ after all initialization is complete, give the settings for the aux and out directories, and then halt. This option is primarily used for debugging configuration issues. π§-dviβ generate dvi version of document using latex. (And turn off any incompatible requests.) π-dviluaβ generate dvi version of document using lualatex instead of latex. (And turn off any incompatible requests.) π-dvi-β turn off generation of dvi version of document. (This may get overridden if some other file is made (e.g., a.psfile) that is generated from the dvi file, or if no generated file at all is requested.) π-dvilualatex="COMMAND"β sets the string that says which command runs dvi lualatex π. Works exactly like-pdflatexdoes, except it sets the variable$dvilualatex.
Heads up bestie: giving this option a COMMAND argument only sets the command used for invoking dvilualatex β it does not switch on dvilualatex usage. That's somebody else's job (other options, or an initialization file). π
-e<code>β runs the initialization code you gave it right before processing β¨. The code is Perl code, same form as what you'd put in latexmk's initialization files. For the full tea, go look at the-roption and the section about "Configuration/initialization (RC) files". Usually the code is just a sequence of assignment statements separated by semicolons.
The code runs the moment the -e option gets hit while latexmk is parsing its command line. (Psst β see -r if you'd rather execute initialization code from a file.) If there's an error, latexmk stops, full stop π. You can use multiple -r and -e options, and they run in the order they show up on the command line.
You gotta be careful with quoting special characters in the code on the command line, it's lowkey tricky. Say you want the latex command to use its -shell-escape option β under UNIX/Linux you could go with:
latexmk -e '$latex=q/latex %O -shell-escape %S/' file.tex
The single quotes stop normal UNIX/Linux command shells from treating the characters inside the quotes as special. (In this example, q/.../ is a Perl idiom equivalent to using single quotes. It dodges the whole mess of getting a quote character inside an already-quoted string, and it works independently of both the shell and the operating system.)
That exact command line will NOT work under MS-Windows with cmd.exe or command.com or 4nt.exe. For MS-Windows with those command shells you'd use:
latexmk -e "$latex=q/latex %O -shell-escape %S/" file.tex
or
latexmk -e "$latex='latex %O -shell-escape %S'" file.tex
Those last two examples will NOT work with UNIX/Linux command shells. π
(Note: those examples are there to show how to use-eto specify initialization code that gets executed. But you can get that same effect with the-latexoption too, with way fewer quoting headaches.)
-emulate-aux-dirβ emulates using an aux directory instead of leaving it to the *latex programs to handle π¦. (MiKTeX supports-aux-directory, but TeXLive doesn't.)
See the section AUXILIARY AND OUTPUT DIRECTORIES for more details.
-emulate-aux-dir-β turns the aux-directory emulation off, and leaves it to the *latex program to deal with the case where the aux directory differs from the output directory. Lowkey important: if you're on TeXLive, which doesn't support-aux-directory, latexmk will automatically flip aux_dir emulation on after the first run of *latex, because it'll find the.logfile in the wrong place. π-fβ forces latexmk to keep processing the document even when errors happen π. Normally, when latexmk detects that LaTeX or another program hit an error that further processing won't fix, no further processing happens.
Note: "further processing" means running other programs, or rerunning latex (etc), the stuff that would've happened if no errors occurred. If instead (or also) you want the latex (etc) program to not pause for user input after an error, set that up with an option you pass to the program β e.g. latexmk's -interaction=nonstopmode option (which latexmk passes to *latex).
-f-β turns off the forced processing-past-errors that-fsets up. Use it to override a setting from a configuration file π.-gβ go mode! Forces latexmk to run each rule at least once, even in situations where latexmk would normally decide nothing in the source files changed since the last run π₯. Super useful if, say, you changed the configuration and want everything reprocessed.
Equivalently: all rules are initially treated as out of date. Downside? If you have, like, a ton of custom dependencies for making graphics files, all of them get run, which could be a huge time sink π. See also the -gt option, which only forces a rerun of *latex.
-g-β turns off-g.-ggβ "super go mode", aka "clean make": cleans out generated files as if-Chad been given, then does a regular make π .-gtβ requires at least one run of *latex. So basically process as normal, except at least one run of the *latex rule happens, even when latexmk's normal methods conclude a *latex run isn't needed.
Equivalently, treat the *latex rule as initially out-of-date. Note that latexmk may separately detect that other rules are out-of-date by its normal methods β if those normally run before *latex, this still happens.
This one's iconic when you've made config changes, or under certain error conditions where latexmk wouldn't correctly detect the need to run *latex, but the run is definitely needed β.
-hor-helpβ prints help info π«Ά.-hntβ generates the hnt (HINT) version of the document using hilatex π§. (And turns off any incompatible requests.)-jobname=STRINGβ sets the basename of output file(s) toSTRING, instead of the default (which is the basename of the TeX file you specified). (At present,STRINGshould not contain spaces. π)
This is like the same option in current implementations of *latex, and passing this option along to those programs is part of how latexmk implements -jobname.
There's one enhancement: STRING may contain the placeholder %A, which gets substituted by the basename of the TeX file. The main reason is when multiple files are specified on the latexmk command line and you want a jobname with a different file-dependent value for each file. For example, say you had test1.tex and test2.tex, and you wanted to compare compilation results from *latex against xelatex. Under a unix-type operating system you could use:
latexmk -pdf -jobname=%A-pdflatex *.tex
latexmk -pdfxe -jobname=%A-xelatex *.tex
Then the .aux, .log, and .pdf files from the pdflatex run would have basenames test1-pdflatex and test2-pdflatex, while from xelatex the basenames would be test1-xelatex and test2-xelatex. Slay. β¨
Under MS-Windows with cmd.exe you'd need to double the percent sign, so the percent character gets passed to latexmk instead of being used to substitute an environment variable:
latexmk -pdf -jobname=%%A-pdflatex *.tex
latexmk -pdfxe -jobname=%%A-xelatex *.tex
-lβ runs in landscape mode, using landscape mode for the previewers and the dvi-to-postscript converters πΈ. Not normally needed nowadays since current previewers usually figure this out on their own.-l-β turns off-l.-latexβ sets dvi file generation by latex, and turns off generation of pdf and ps files π.
Note: to set the command used when latex is specified, see the -latex="COMMAND" option.
-latex="COMMAND"β sets the string specifying the command to run latex, typically used to add the options you want. Since the string normally contains spaces, quote it, like:
latexmk -latex="latex --shell-escape %O %S" foo.tex
What goes in the string is specified the same way as for the $latex configuration variable. Depending on your operating system and command-line shell you may need to swap those single quotes for double quotes (or something else π« ).
Note: giving this option a COMMAND argument only sets the command for invoking latex β it does not turn on the use of latex. Other options or an initialization file do that.
To set the command for running pdflatex (instead of the command for latex) see the -pdflatex option.
-logfilewarninglist,-logfilewarningsβ after a run of *latex, gives you 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, don't give a list of warnings about undefined citations and references. (Default π )
See also the $silence_logfile_warnings configuration variable.
-lualatexβ use lualatex. Like, use lualatex to process the source file(s) to pdf π. Generation of dvi, hnt, postscript and xdv files is turned off.
This option is equivalent to using this set of options:
-pdflua -dvi- -ps-
(Note: the method of implementation of this option β though not its intended effect β differs from some earlier versions of latexmk.)
-lualatex="COMMAND"β sets the string specifying the command to run lualatex. Behaves like the-pdflatexoption, but sets the variable$lualatexπ.
Note: providing the COMMAND argument here only sets the command for invoking lualatex; it does not turn on the use of lualatex. Other options or an initialization file do that.
-Mβ shows the list of dependent files after processing. Equivalent to the-depsoption π.-MFfileβ if a list of dependents is made,-MFspecifies the file to write it to π.-MPβ bestie, if a dependents list is being made, this makes a phony target for every source file. Why do you care? Because if you drop the dependents list into aMakefile, those little dummy rules work around the errors thatmakethrows at you when you go and delete header files without updating theMakefileto match. It's giving damage control β¨-makeindexfudgeβ turns the change-directory fudge on formakeindex. The deets live in the docs for$makeindex_fudgeπ-makeindexfudge-β turns that same change-directory fudge off formakeindex. Again, see$makeindex_fudgefor the full story π$min_sleep_time [0.01]β this is the minimum nonzero value allowed for$sleep_time. That's it, that's the whole vibe. Default is0.01π¦-MSWinBackSlashβ okay so this one only does anything whenlatexmkis running under MS-Windows. What it does: whenlatexmkruns a command under MS-Windows, the Windows standard directory separator"\"gets used to separate directory components in a file name. Internallylatexmkuses"/"as the separator, which is what Unix-like systems use.
This is the default behavior, bestie β but heads up, the default may have been overridden by a configuration file (latexmkrc file) that sets $MSWin_back_slash=0 π
-MSWinBackSlash-β again, only does anything under MS-Windows. This one means: whenlatexmkruns 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, same as on Unix-like systems. Lowkey fine in most situations under MS-Windows, provided the filenames are properly quoted β whichlatexmkdoes by default anyway π
See the docs for the config variable $MSWin_back_slash for more β¨
-new-viewerβ in continuous-preview mode, this makeslatexmkalways start a new viewer to look at the generated file. Default behaviour is that in continuous-preview modelatexmkchecks whether a previously running previewer already has the same file open, and doesn't start a new one if there is. But not gonna lie, that test sometimes fails β notably when there's an already-running previewer viewing a file with the same name as the current file but in a different directory. This option turns that default behaviour off π-new-viewer-β the inverse of-new-viewer. It putslatexmkback in its normal behaviour, where in preview-continuous mode it checks for an already-running previewer π«Ά-nobibtexβ never runbibtexorbiber. Equivalent to the-bibtex-option. Periodt π-nobibtexfudgeor-nobibfudgeβ turns off the change-directory fudge forbibtex. See the docs of$bibtex_fudgefor the details π-noemulate-aux-dirβ turnsaux_diremulation off. Same as-emulate-aux-dir-πΈ-nomakeindexfudgeβ turns off the change-directory fudge formakeindex. Docs for$makeindex_fudge, as always π-norcβ turns off the automatic reading of initialization (rc) files.
N.B. Normally the initialization files are read and obeyed first, and then command line options are obeyed in the order they're encountered. But -norc is the exception to that rule: it gets acted on first, no matter where it shows up on the command line. Main character energy fr fr π
-outdir=FOOor-output-directory=FOO
Sets the directory for the output files of *latex π
If the aux directory is not set, or is the same as the output directory, then all output files of *latex are sent to the output directory.
If the aux directory is set β say by the option -auxdir β and it's not equal to the output directory, then only the primary output files (.dvi, .ps, .pdf, .synctex, .synctex.gz) are sent to the output directory. Other generated files go to the aux directory β¨
See the section AUXILIARY AND OUTPUT DIRECTORIES for more details π¦
-out2dir=FOO
(Experimental new feature. You've been warned, bestie π)
Sets the directory for the final output files of a whole round of compilations.
Using this directory solves, among other things, the problem where multiple runs of *latex and other programs are needed, so files like the main pdf file from pdflatex etc. get changed multiple times. A viewer like SumatraPDF that reloads the file whenever it detects changes will then show you a distracting sequence of intermediate states of the pdf file, instead of just the final version after all the repeated runs of *latex etc. are done. But when a distinct final-output directory is set β by the -out2dir option or by setting the equivalent $out2_dir variable β the viewer only sees a changed pdf (etc.) file after the full sequence of repeated runs of *latex etc. has finished. Slay π
By default the final output directory is the same as the output directory (as specified by the -outdir option or the setting of the variable $out_dir configuration variable) π
-output-format=FORMATβ this one's allowed forlatex,lualatex, andpdflatex, but it is not passed to those programs. Insteadlatexmkemulates it in a way that suits the context oflatexmkand its workflows π
-If FORMAT is dvi, then dvi output is turned on, and postscript, pdf and xdv output are turned off. This is equivalent to using the options -dvi -ps- -pdf- -xdv-.
If FORMAT is pdf, then pdf output is turned on, and dvi, postscript and xdv output are turned off. This is equivalent to using the options -pdf -ps- -dvi- -xdv-.
If FORMAT is anything else, latexmk gives an error π
-pβ prints out the document. By default the file to be printed is the first in the listpostscript,pdf,dvithat 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_typevariable) πΈ
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 behaviour 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, ngl. 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 the pdf version of the document usingpdflatex. (And turn off any incompatible requests.)
(If you wanna use lualatex or xelatex, you can use whichever of the options -pdflua, -pdfxe, -lualatex or -xelatex applies.) To configure latexmk to have such behaviour by default, see the section on "Configuration/initialization (rc) files" π
-pdfdviβ generate a dvi file and then the pdf version of the document from that dvi file, by default usingdvipdf. (And turn off any incompatible requests.) π¦
The program used to compile the document to dvi is latex by default, but this can be changed to dvilualatex by the use of the -dvilua option or by setting $dvi_mode to 2 β¨
-pdfluaβ generate the pdf version of the document usinglualatex. (And turn off any incompatible requests.) π-pdfpsβ generate a dvi file, a ps file from the dvi file, and then a pdf file from the ps file. (And turn off any incompatible requests.) π
The program used to compile the document to dvi is latex by default, but this can be changed to dvilualatex by the use of the -dvilua option or by setting $dvi_mode to 2 πΈ
-pdfxeβ generate the pdf version of the document usingxelatex. (And turn off any incompatible requests.) π₯
Heads up: 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 latexmk arranges for xelatex to make an .xdv file instead of 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 processing time, since the .pdf file is produced once rather than on every run of xelatex. iykyk π)
-pdf-β turn off generation of the pdf version of the document. (You can use this 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 gets turned on, and then the program used to compile a document will be latex (or, more precisely, whatever program is configured to be used in the $latex configuration variable) π
-pdflatexβ set the generation of pdf files bypdflatex. (And turn off any incompatible requests.)
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 runpdflatex, and it's typically used to add whatever options you want. 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 is 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're using, you may need to change the single quotes to double quotes (or something else) π
Note: this option, when provided with theCOMMANDargument, only sets the command for invokingpdflatexβ it does not turn on the use ofpdflatex. That is done by other options or in an initialization file. Don't get it twisted bestie π
To set the command for running latex (rather than the command for pdflatex) see the -latex option. π
-pdflualatex="COMMAND"β literally the same thing as-lualatex="COMMAND". Twins. No cap.-pdfxelatex="COMMAND"β and this one is exactly equivalent to-xelatex="COMMAND". Same energy, different name. β¨-pretex=CODEβ okay soCODEis some TeX code, and this option says "run that code before inputting the source file." Important vibe check: this only works if the command for invoking the relevant*latexis suitably configured. See the docs for the variable$pre_tex_code, and the substitution strings%Pand%Ufor the deets. Mechanically, this option works by setting the variable$pre_tex_code.
Also peep the -usepretex option π
Here's an example:
latexmk -pretex='\AtBeginDocument{Message\par}' -usepretex
foo.tex
But bestie, this is better written as
latexmk -usepretex='\AtBeginDocument{Message\par}' foo.tex
And if you already have a suitable command configured? You literally only need
latexmk -pretex='\AtBeginDocument{Message\par}' foo.tex
-print=dvi,-print=ps,-print=pdf,-print=autoβ define which kind of file gets printed. This option also makes sure the requisite file is made, and turns on printing. π¨οΈ
The default case, -print=auto, figures out the kind of print file automatically from the set of files being made. The first in the list postscript, pdf, dvi that's among the files to be made is the one used for the print out.
-psβ generate a postscript version of the document. (And it turns off any incompatible requests. Team player behavior.)-ps-β turn off generation of the postscript version of the document. This is your go-to for overriding a setting in a configuration file. (Tho 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:
latexmk -ps -pF 'psnup -2' foo.tex
or
latexmk -ps -pF "psnup -2" foo.tex
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. (iykyk π)
-pvβ run the file previewer. If the-viewoption is used, that selects the kind of file to be previewed (.pdf,.psor.dvi). Otherwise the viewer views the "highest" kind of output file that is made, with the ordering being.pdf,.ps,.dvi(high to low). This option is incompatible with the-pand-pvcoptions, so it turns them off.-pv-β turn off-pv.-pvcβ run a file previewer and continually update the.dvi,.ps, and/or.pdffiles 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-pvoption. The preview-continuous option-pvccan only work with one file. So in this case you'll normally only specify one filename on the command line. It's also incompatible with the-pand-pvoptions, 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: theacroreadprogram on MS-Windows locks the pdf file, and prevents new versions being written, so it is a bad idea to useacroreadto view pdf files in preview-continuous mode. It's better to use a different viewer βSumatraPDFandgsvieware 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 a 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 the period of inactivity, in minutes, for the pvc timeout. β°-quietβ same as-silent.-r <rcfile>β read the specified initialization file ("RC file") before processing.
Be careful about the ordering, bestie, this is important: (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. (This is the default.)-rc-report-β after initialization, do not give a list of the RC files read.-recorderβ give the-recorderoption with*latex. In (most) modern versions of these programs, this results in a file of extension.flscontaining 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-recorderoption with*latex.-rulesβ show a list of latemk's rules and dependencies after processing. (Yes, "latemk" β that's literally how it's spelled in the original, we keep it π)-rules-β do not show a list of latexmk's rules and dependencies after processing. (This is the default.)-showextraoptionsβ show the list of extra*latexoptions that latexmk recognizes, but that it simply passes through to the programs*latexwhen 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*latexthat is being used, that program will probably give a warning or an error.) These options are very numerous, but they 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 commandlatex -interaction=batchmodeis 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, $dvilualatex_silent_switch, $latex_silent_switch, $lualatex_silent_switch $makeindex_silent_switch, $pdflatex_silent_switch, and $xelatex_silent_switch. (Yes, that missing comma between $lualatex_silent_switch and $makeindex_silent_switch is canon β we don't fix it, we respect the source. π«Ά)
-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.) Slay. π
-timeβ show me the time, bestie β±οΈ (on MS Windows what you get is clock time; everywhere else it's CPU time). Also see the config variable$show_time.-time-β no time display, thank you. Also see$show_time.-use-makeβ okay so here's the situation: after a run of*latex, sometimes you get warnings about missing files (like the ones LaTeX's\input,\include, and\includgraphicscommands asked for). latexmk tries to make those via a custom dependency. But if no relevant custom dependency with an appropriate source file turns up, and-use-makeis set, then as a literal last resort latexmk will hand it to themakeprogram and be like "pls make these missing files happen." π«Ά
Lowkey important: the filename might come with no extension, e.g. \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).
Also peep the docs for the $use_make_for_missing_files configuration variable.
-use-make-β do not use themakeprogram to try to make missing files. (This is the default, no cap.)-usepretexβ sets the command lines for latex, etc., so they use the code defined by the variable$pre_tex_code, or the code set by the option-pretex=CODE, to execute the specified TeX code before the source file is read. Heads up: 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. slay.)
-usepretex=CODEβ equivalent to-pretex=CODE -usepretex. Example:
latexmk -usepretex='\AtBeginDocument{Message\par}' foo.tex
-vor-versionβ print the version number of latexmk. π-verboseβ the opposite of-silent. This is the default setting, bestie.-view=default,-view=dvi,-view=hnt,-view=ps,-view=pdf,-view=noneβ set the kind of file used when previewing is requested (e.g., by the-pvor-pvcswitches). The default is to view the "highest" kind of requested file (in the low-to-high order.dvi,.hnt,.ps,.pdf). β¨
Note the possibility -view=none where no viewer is opened at all. One example of its use is in conjunction with the -pvc option, when you want latexmk to do a compilation automatically whenever source file(s) change, but you do not want a previewer to be opened. iconic behaviour honestly.
-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). And this is after latexmk has completed all the runs it needs to try and resolve references and citations. So-Werrormakes latexmk treat such warnings as errors β but only when they occur on the last run of*latexand only after processing is complete. Also can be set by the configuration variable$warnings_as_errors. π¨-xdvβ generate the xdv version of the document usingxelatex. (And turn off any incompatible requests.)-xelatexβ usexelatex. That is, usexelatexto process the source file(s). This will cause generation of a pdf (but indirectly, through an xdv file). (And turn off any incompatible requests.)
This option is equivalent to using the following option:
-pdfxe
[Note: the method of implementation of this option, but not its intended primary effect, differs 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 -pdfxe for why this is done. π]
-xelatex="COMMAND"β this sets the string specifying the command to runxelatex. It sets the variable$xelatex.
β οΈ Warning: it is important to ensure that-no-pdfis used whenxelatexis invoked, since latexmk expectsxelatexto produce an.xdvfile, not a%Oin the command specification, this will be done automatically. See the documentation for the-pdfxeoption for why latexmk makes an.xdvfile rather than axelatexis used.
An example of the use of the -xelatex option:
latexmk -pdfxe -xelatex="xelatex --shell-escape %O %S"
foo.tex
π Note: this option when provided with the COMMAND argument only sets the command for invoking xelatex; 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. one (1) file. that's the vibe check.
Options -p, -pv and -pvc are mutually exclusive. So each of these options turns the others off. pick a lane bestie π
π 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, bestie β let's go through them:
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. π it's looking out for you.
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.) fr fr, it's usually the source file.
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:
\typeout{(bar.baz)}
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. π
π AUXILIARY AND OUTPUT DIRECTORIES π
okay bestie so here's the tea β β when you run *latex and all its little friends, they generate a bunch of files, and it's honestly so much nicer to shove those generated files into a different directory than the source file(s) of your document. For our purposes here, we're splitting the generated files into two classes, and you're gonna want to know both π
One class is what we call the final output files β like, the actual deliverables. That's the .pdf file you get from running pdflatex, or the .dvi file from latex. Also in this class? The ps file generated by applying dvips to a .dvi file. And don't forget the .synctec or .synctex.gz files β those are the ones programs that display .pdf files and the like use to relate positions in the PDF to positions in your source files. iconic behavior honestly π₯
The second class is literally everything else that gets generated β the intermediate girlies. These include notably .aux files that are used for implementing cross referencing (and the way that these are both generated on one run and read on a later run is so extra of them π). Many packages generate yet more such intermediate files, plus there's programs like bibtex, makeindex, etc. And of course there are .log files from *latex and corresponding files from other programs.
So let's define our terms, iykyk π
- "output directory" β the directory that receives the final output files
- "aux directory" β the directory for the other generated files
If you don't pass any special options to the *latex programs, these directories just default to the current directory, and then the generated files aren't segregated at all β they're all just vibing together. If the two directories are the same, which is the simplest situation, then all generated files get written to the same directory, and honestly people often just say "the output directory" without ever mentioning a separate aux directory. fair π«Ά
Support for all this is provided in the *latex programs themselves: by the single option -output-directory for the TeXLive implementations, and by the options -aux-directory and -output-directory for the MiKTeX implementations. Special support like this is needed for two reasons, bestie:
- There are so many packages that write files, and it needs to be arranged that these are automatically written to the appropriate directory without any rewriting of the packages' code. no cap.
- The files are often read in again on subsequent runs of
*latex, so the program has to know where to find them. periodt.
Now here's the plot twist π A complication: the TeXLive implementation does not allow for separate aux and output directories. Latexmk deals with this by being able to emulate a separate aux directory. Here's how that method works β it invokes *latex with just an -output-directory option, but with the directory set not to the desired output directory, but to the aux directory. Then, after running *latex, it moves the relevant final output file(s) to the intended output directory. Sneaky. Clever. We love her π
You can turn emulation on by setting the configuration variable $emulate_aux to one in a configuration file, or by using latexmk's -emulate-aux-dir option. And the emulation method works equally well if MiKTeX is used. versatile queen π
Latexmk also turns emulation on if it's found to be needed, like this: suppose emulation is initially off, but the aux and output directories are different. Then latexmk invokes *latex with an -aux-directory option, and after the run finds that it hasn't been obeyed β notably because the .log file is in the output directory rather than the aux directory. Rude. So latexmk then sets emulation on, and retries. π
Conceivably, it could move all the appropriate generated files from the output directory to the aux directory; but there is such a large variety of possibilities for these files that this is hard to identify all of them reliably except for simple cases. so she doesn't. respect.
β Note that the emulation issue only arises when the user has arranged for the aux and output directories to be different. When instead they're equal β e.g. because the user only set the$out_dirvariable β then latexmk invokes*latexwith only an-output-directoryoption, which works as intended with both TeXLive and MiKTeX. no drama. πΈ
In addition, latexmk arranges the invocations of any auxiliary programs like bibtex and makeindex so that they will read and write the relevant files from and to the aux directory. And programs like dvips, dvipdf, ps2pdf, and xdvipdfmx are invoked so that they read from the appropriate places and write their output to the output directory. everyone knows their assignment π
Files considered as final output files β i.e. those that belong in the output directory rather than the aux directory β these have the extensions .dvi, .ps., .pdf, .synctex, and .synctex.gz. A special case, because of compatibility issues, is .fls files: see below. π
Now, a lil note about xelatex: when it's invoked with its -no-pdf option, as latexmk does, it generates an .xdv file, which would appear to have the same status as a .dvi file generated by latex. Nevertheless, latexmk treats .xdv as an intermediate file that is found in the aux directory. Why? To match MiKTeX's treatment of the -aux-directory option. And as further justification, one can say that under modern conditions an .xdv file is (almost) always an intermediate file. Historically, the situation with .dvi files from latex was different, and currently dvi previewers do exist. so there. π¦
π Variables and options for directories π
The variables for setting the aux and output directories are $aux_dir and $out_dir, with corresponding command line options -auxdir (or -aux-directory) and -outdir (or -output-directory).
When a value for these is blank (which is the default value), it implies the use of a default:
- For the aux directory, the default is to set it equal to the output directory.
- For the output directory, the default is to be the current directory.
For the turning on and off of the emulation mode, there's the configuration variable $emulate_aux and the options -emulate-aux-dir, -emulate-aux-dir-, -noemulate-aux-dir. (yes, one of them is the same name with a dash glued on the end. she's quirky like that π
)
π Interaction with -cd option π
When the -cd option is used (or the equivalent setting of the $do_cd variable), then latexmk changes the working directory to the document directory before invoking *latex.
So if the aux and/or output directories are given by relative paths β e.g. by -outdir=output for a directory named "output" β then the directories are relative to the document directory, rather than relative to the working directory that was in effect when latexmk was invoked. This matches the behavior of *latex as invoked with the provided command line directory argument(s) after the change of working directory to the document directory. consistent icon β¨
π«Ά Automatic creation of aux and output directories π«Ά
Unlike *latex, if latexmk finds the requested directory/ies don't exist, it creates it/them β thereby avoiding errors when *latex is invoked. she's a problem solver, we stan ππ
If the document uses the \include macro to read a .tex file from a subdirectory, *latex will attempt to write an extra aux file to the corresponding subdirectory of the aux directory. If the subdirectory doesn't exist, then *latex will complain that it can't write the aux file. So after the run of *latex, latexmk detects this situation, creates the necessary directory, and reruns *latex with the error situation corrected. fixed it, next π
π Choice of aux and output directories π
Often the aux and output directories are given as subdirectories of the document directory, e.g. by -outdir=output. But it is possible to provide, for example, an absolute path or a path relative to a parent directory β e.g. "/tmp/foo" or "../output".
π Be aware that in general this can cause problems, notably withmakeindexorbibtex. This is because modern versions of these programs, by default, will refuse to work when they find that they're asked to write to a file in a directory that appears not to be the current working directory or one of its subdirectories. This is part of security measures by the whole TeX system that try to prevent malicious or errant TeX documents from incorrectly messing with a user's files. protective queen behavior, honestly.
By default, latexmk evades this issue: before running bibtex and makeindex, latexmk changes working directory to the aux directory, with appropriate settings of search paths. The use or non-use of this trick is governed by the variables $bibtex_fudge and $makeindex_fudge. Unfortunately, the trick sometimes makes bibtex and makeindex unable to find files. π it's giving "can't win"
If necessary the trick can be turned off. But this is incompatible with an aux directory like "/tmp/foo" or "../output". If you really have to deal with this situation, and only if you have to deal with it, then you need to disable the security measures (and assume any risks). One way of doing this is to temporarily set an operating system environment variable openout_any to "a" (as in "all"), to override the default "paranoid" setting. π proceed with caution bestie
π Certain names of aux and output directories not allowed on Microsoft Windows π
It's so natural to want to use the name "aux" for the aux directory, e.g. by using the option -auxdir=aux. But on Microsoft operating systems "aux" is one of the names that is not allowed for a file or directory. rip. π
I find it useful to standardize on a name like "auxdir" (e.g. by -auxdir=auxdir); this works independently of operating system. life hack, you're welcome π«Άβ¨
π¦ Location of .fls file π¦
Much of the dependency information that latexmk uses comes from the .fls file generated when *latex is invoked with the -recorder option β which latexmk does by default.
It may seem rational that this is written to the aux directory. But in fact, versions of MiKTeX prior to Oct. 2020 wrote it to the output directory. Later versions do write it to the aux directory. chaos. π
To deal with this, latexmk does two things:
- First, if latexmk finds that the
.flsfile has only been generated in the "wrong" directory, then latexmk copies it to the expected directory, after which latexmk's operation continues correctly, independently of the behavior of*latex. she adapts π - Second, it allows its idea of the "correct" (or expected) directory to be configured by the variable
$fls_uses_aux_dir. This defaults to zero, to correspond to MiKTeX's current behavior. β
π¦ ALLOWING FOR CHANGE OF OUTPUT FILE TYPE π¦
okay so bestie, here's the tea on output file types β 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. β¨
But lowkey, 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. π
π§ CONFIGURATION/INITIALIZATION (RC) FILES π§
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:
- The system RC file, if it exists. On a UNIX system,
latexmksearches the following directories for a system RC file, which may be named either"LatexMk"or"latexmkrc". The directories are searched in the following order, andlatexmkuses the first such file it finds (if any):"/etc","/opt/local/share/latexmk","/usr/local/share/latexmk","/usr/local/lib/latexmk". On a MS-Windows system it looks just in"C:\latexmk". On a cygwin system (i.e., a MS-Windows system in which Perl is that of cygwin),latexmklooks in the directories"/cygdrive/c/latexmk","/etc","/opt/local/share/latexmk","/usr/local/share/latexmk","/usr/local/lib/latexmk".
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. π
- 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. (Seehttps://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.htmlfor 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. π
- 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. π - Any RC file(s) specified on the command line with the
-roption. π
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). π
π HOW TO SET VARIABLES IN INITIALIZATION FILES π
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: π
$bibtex = 'bibtex %O %S';
for the setting of a string variable,
$preview_mode = 1;
for the setting of a numeric variable, and
@default_files = ('paper', 'paper1');
for the setting of an array of strings. It is possible to append an item to an array variable as follows:
push @default_files, 'paper2';
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. π
β¨ FORMAT OF COMMAND SPECIFICATIONS β¨
okay so some of these variables are literally the commands latexmk runs to do its thing β like making a .dvi file from a .tex file, or opening a postscript file for you to look at. This section is all about how those command specs work. (Quick heads-up: some of the possibilities listed here do not apply to the $kpsewhich variable; go peep its docs.)
π Placeholders π
Suppose you wanted latexmk to use the command elatex instead of the regular latex command, and you also wanted to give it the option --shell-escape. You could do that with this setting:
$latex = 'elatex --shell-escape %O %S';
The two items starting with the % character are placeholders. They get substituted with the appropriate values before the command runs. So %S gets replaced by the source file that elatex will be applied to, and %O gets replaced by any options latexmk has decided to use for this command. (E.g., if you used the -silent option when invoking latexmk, that makes %O get replaced by "-interaction=batchmode".)
The available placeholders are:
%Aβ basename of the main tex file. Unlike%R, this is unaffected by the setting of a jobname by the-jobnameoption or the$jobnameconfiguration value.%Bβ base of filename for the current command. E.g., if a postscript filedocument.psis being made from the dvi filedocument.dvi, then the basename isdocument.%Dβ destination file (e.g., the name of the postscript file when converting a dvi file to postscript).%Oβ options.%Pβ If the variable$pre_tex_codeis non-empty, then%Pis substituted by the contents of$pre_tex_codefollowed by\input{SOURCE}, where SOURCE stands for the name of the source file. Appropriate quoting is done. This enables TeX code to be passed to one of the*latexengines to be executed before the source file is read. If the variable$pre_tex_codeis the empty string, then%Pis equivalent to%S.%Rβ root filename. By default this is the basename of the main tex file. However the value can be changed by the use of the-jobnameoption or the$jobnameconfiguration variable. This is then the basename for files like the.auxand.logfiles produced by running*latex, as well for the main.dvi,.pdf,.psand/or.xdvifiles.%Sβ source file (e.g., the name of the dvi file when converting a.dvifile to ps).%Tβ the name of the primary tex file.%Uβ If the variable$pre_tex_codeis non-empty, then its value is substituted for%U(appropriately quoted). Otherwise it is replaced by a null string.%Yβ Name of directory for auxiliary output files (see the configuration variable$aux_dir). A directory separation character ('/') is appended if$aux_diris non-empty and does not end in a suitable character, with suitable characters being those appropriate to UNIX and MS-Windows, i.e.,':','/'and'\'. Note that if after initialization,$out_diris set, but$aux_diris not set (i.e., it is blank), then latexmk sets$aux_dirto the same value$out_dir.%Zβ Name of directory for output files (see the configuration variable$out_dir). A directory separation character ('/') is appended if$out_diris non-empty and does not end in a suitable character, with suitable characters being those appropriate to UNIX and MS-Windows, i.e.,':','/'and'\'.
If for some reason you need a literal % character in your string that should not be 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. That's appropriate for commands like latex, obviously. 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 get this detaching effect, you need to precede the command name with "start ", as in:
$dvi_previewer = 'start xdvi %O %S';
This will be translated to whatever is appropriate for your operating system.
Notes:
- 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.
- This precludes the possibility of running a command named
start. - If the word
startoccurs more than once at the beginning of the command string, that is equivalent to having just one. - Under cygwin, some complications happen, since cygwin amounts to a complicated merging of UNIX and MS-Windows. See the source code for how this was handled.
πΈ 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:
$lpr_pdf = '"c:/Program Files/Ghostgum/gsview/gsview32.exe" /p %S';
$pdf_previewer = 'start "c:/Program Files/SumatraPDF/SumatraPDF.exe" %O %S';
$pdf_previewer = 'start "c:/Program Files/SumatraPDF (x86)/SumatraPDF.exe" %O %S';
(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:
$dvi_previewer = 'start %S';
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 previewer, 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:
$lpr = 'NONE lpr';
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 the command. Suppose you want latexmk to use latex with source specials enabled. Then you might use the following line in an initialization file:
$latex = 'latex --src-specials %O %S';
π§ Running a subroutine instead of an external command π§
Use a specification starting with "internal", as in:
$latex = 'internal mylatex %O %S';
sub mylatex {
my @args = @_;
# Possible preprocessing here
return system 'latex', @args;
}
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:
$pdflatex = 'pdflatex --shell-escape %O %S; pst2pdf_for_latexmk %B';
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:
$pdflatex = 'cmd /c pdflatex --shell-escape %O %S'
. '&& pst2pdf_for_latexmk %B';
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.
π LIST OF CONFIGURATION VARIABLES USABLE IN INITIALIZATION FILES π
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.)
Quick vibe check before we dive into the ~variables~ π
β in everything below, default values are the bits in square brackets. And bestie, listen: for the variables that are boolean-coded (like, "does latexmk do the thing or not"), the rule is non-zero = true (normally 1, meaning yes the behavior happens) and zero = false (meaning nope, it does not happen). Iconic. Simple. We move.
$allow_subdir_creation [1]
This one tells latexmk what to do when messages in the .log file say a *latex run failed to write a file into a subdirectory of the output directory because that subdirectory literally did not exist. Tragic. So:
- Set it to
0β no action taken at all. Nothing happens. We simply vibe. - Set it to
1β the appropriate subdirectory gets created and a rerun of*latexis triggered, but only if the file being written is an.auxfile. (This is the situation where, like, a document includes a file from a subdirectory of the document directory via the\includecommand.) - Set it to
2β the subdirectory creation happens independently of which type of file is in question. No gatekeeping. π«Ά
$allow_switch [1]
This controls what goes down when the output extension of latex, pdflatex, lualatex or xelatex is not what you expected. (The possible extensions, for the record, are .dvi, .pdf, .xdv.) This can happen with the \pdfoutput macro in a document compiled under latex or pdflatex, or with the \outputmode macro under lualatex. It can also justβ¦ happen with certain kinds of incorrect configuration. π
In that case, latexmk can appropriately adjust its network of rules. The adjustment is made if $allow_switch is on and no request for a dvi or ps file has been made.
See the section ALLOWING FOR CHANGE OF OUTPUT EXTENSION.
$always_view_file_via_temporary [0]
Whether .ps and .pdf files are initially made in a temporary directory and then moved to their final location. (This applies to dvips, dvipdf, and ps2pdf operations, plus the filtering operators on .dvi and .ps files. It does not apply to pdflatex, unfortunately, since pdflatex provides no way of specifying a chosen name for the output file. sad.)
Why do we even do this? Because making these files can take a substantial amount of time. If a viewer (notably gv) sees the file has changed, it may go read the new file before the program writing it has actually finished its work β which can cause havoc. π So we sneak the file in via temporary land instead.
See the $pvc_view_file_via_temporary variable for a setting that applies only when preview-continuous mode (the -pvc option) is used. See $tmpdir for setting the directory where the temporary file gets created.
$analyze_input_log_always [1]
After a run of latex (or etc.), always analyze the .log for input files in the <...> and (...) constructions. Otherwise, only do the analysis when the 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 β so usually $analyze_input_log_always is best set to zero. But the log-file test is needed at least in this 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 the log file. One important case is for lualatex, which doesn't always generate lines in the .fls file for input lua files. (The lualatex situation 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 $analyze_input_log_always set to 1.
$auto_rc_use [1]
Whether to automatically read the standard initialization (rc) files, which are: the system RC file, the user's RC file, and the RC file in the current directory. The command line option -norc can turn this setting off. Each RC file could also turn this setting off itself β i.e., it could set $auto_rc_use to zero to prevent the automatic reading of the later RC files.
Heads up: this variable does not affect the reading of RC files specified on the command line by the -r option.
$aux_dir [""]
The aux directory, bestie β i.e. the directory in which auxiliary files (aux, log, etc.) are to be written by a run of *latex.
Here's the chain of events:
- If this variable is not set, but
$out_diris set, then latexmk takes the aux directory to equal the output directory, which is the directory the final output files get written to. - If neither variable is set, then the current directory when
*latexis invoked is used for both the aux and output directories. - If the aux and output directories are distinct, then the aux directory contains all generated files with the exception of "final output files" β which are defined to be
.dvi,.ps,.pdf,.synctex, and.synctex.gzfiles.
See the section AUXILIARY AND OUTPUT DIRECTORIES for more details.
$aux_out_dir_report [0]
If you set this to 1, then before the processing of each primary .tex file, latexmk lists the settings for the aux and output directories β after they've been normalized from the settings specified during initialization. It's basically a little reminder of where to go look for your generated files. π
The report happens per primary .tex file, because directories can possibly change for each file (when the -cd option is used). In the simplest cases, the directory names are the same as originally specified β but in general, some clean up/normalization is performed, which helps performance and cleans up the output to your screen. β¨
If you set it to 2, then latexmk halts after reporting the aux and out directory settings, instead of continuing with processing of tex files. That setting is primarily used for debugging configuration issues. See the -dir-report-only option.
$bad_warning_is_error [0]
Whether to treat "bad warnings" reported by *latex in the log file as errors. The specifications of those warning messages live in @bad_warnings.
@bad_warnings
An array of regular expressions specifying messages in the log file that are officially treated as warnings rather than errors by *latex, but which a user may choose to treat as errors β see $bad_warning_is_error.
Currently the default set of these warnings is those about \end occurring inside constructs. π«
$banner [0]
If nonzero, the banner message is printed across each page when converting the dvi file to postscript. Without modifying the variable $banner_message, this is equivalent to specifying the -d option.
Note that if $banner is nonzero, $postscript_mode is assumed and the postscript file is always generated β even if it's newer than the dvi file. (No skipping. We commit. π
)
$banner_intensity [0.95]
Equivalent to the -bi option: a decimal number between 0 and 1 that specifies how dark to print the banner message. 0 is black, 1 is white. The default is just right, assuming your toner cartridge isn't running too low. π¨οΈ
$banner_message ["DRAFT"]
The banner message printed across each page when converting the dvi file to postscript. Equivalent to the -bm option.
$banner_scale [220.0]
A decimal number specifying how large the banner message will be printed. You will need to experiment to get the right scale for your message β as a rule of thumb, the scale should be about 1100 divided by the number of characters in the message. The default is just right for 5-character messages. Equivalent to the -bs option.
@BIBINPUTS
An array variable β now mostly obsolete β that specifies directories where latexmk should look for .bib files. By default it's set from the BIBINPUTS environment variable of the operating system. If that environment variable is not set, you get a single-element list consisting of the current directory. The format of the directory names depends on your operating system, obviously. Examples for setting this variable:
@BIBINPUTS = ( ".", "C:\\bibfiles" );
@BIBINPUTS = ( ".", "\\server\bibfiles" );
@BIBINPUTS = ( ".", "C:/bibfiles" );
@BIBINPUTS = ( ".", "//server/bibfiles" );
@BIBINPUTS = ( ".", "/usr/local/texmf/bibtex/bib" );
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. Generally, it's simplest to always use forward slashes instead of backward slashes. π
Important note: This variable is now mostly obsolete in the current version of latexmk, since it now uses a better method of searching for files using thekpsewhichcommand. However, if your system is an unusual one without thekpsewhichcommand, you may need to set@BIBINPUTS.
$biber ["biber %O %S"]
The biber processing program.
$biber_silent_switch ["--onlylog"]
Switch(es) for the biber processing program when silent mode is on.
$bibtex ["bibtex %O %S"]
The BibTeX processing program.
$bibtex_fudge [1]
When using bibtex, whether to change directory to $aux_dir before running bibtex.
The need for this arises like so:
a. With bibtex before about 2019, if the filename given to it contains a path component, there was a bug where 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 β in certain cases of the path component of the filename given to it.
That said, there are also rare cases where the change-directory method prevents bibtex from finding certain bib or bst files. In those cases, $bibtex_fudge needs to be set to 0. π
$bibtex_silent_switch["-terse"]β the switch(es) handed to your BibTeX processing program when silent mode is on. quiet era β¨$bibtex_use[1]β the big question: under what conditions do we even runbibtexorbiber?? π so like, whenlatexmkpeeps in the log file and sees that one (or more) bibtex/biber-generated bibliographies are being used, it can totally runbibtexorbiberwhenever it looks like the.bblfile(s) need regenerating from their source bib database file(s). but bestie β sometimes the bib file(s) just aren't there (classic external-archive-document moment π) and only the.bblfiles are provided. in that case runningbibtex/biberwould straight-up incorectly overwrite your precious.bblfiles π so this variable controls whether that happens, and also controls whether.bblfiles get yeeted in a cleanup operation.
the possible values of $bibtex_use are, in order, lowkey iconic:
0: never usebibtexorbiber; never delete.bblfiles in a cleanup.1: only usebibtexorbiberif the bib file(s) exist; never delete.bblfiles in a cleanup.1.5: only usebibtexorbiberif the bib files exist; conditionally delete.bblfiles in a cleanup (i.e., delete them only when the bib files all exist).2: runbibtexorbiberwhenever it appears necessary to update the.bblfile(s), without testing for the existence of the bib files; always delete.bblfiles in a cleanup.
Note: whenbiberis being used, conditional use ofbibercan be problematic π¬ fromlatexmk's point of view the problem is that, because of howbiberworks, a full knowledge of its source files can only be obtained after runningbiber. in contrast, for bibtex, full information on which bib files are used is obtained from the.auxfile(s) after a run of*latex. but forbiber, the corresponding information is somewhat incomplete β this [sic] the information obtained in the.bcffile that is generated by thebiblatexpackage during a run of*latex.
$cleanup_includes_cusdep_generated[0]β if nonzero, it says cleanup also deletes files generated by custom dependencies π§Ή (when doing a clean up, e.g. by use of the-Coption, custom dependencies are those listed in the.fdb_latexmkfile from a previous run).$cleanup_includes_generated[0]β if nonzero, cleanup also deletes files that are detected in the fls file (or, failing that, in the log file) as being generated π it'll also include files made from these first-generation generated files.
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. that's why this variable is turned off by default π«Ά and then the files to be deleted are restricted to those explicitly specified by patterns configured in the variablesclean_ext,clean_full_ext, and@generated_exts. standard cases (e.g..logfiles) appear inlatexmk's initial value for the array@generated_exts.
$cleanup_mode[0]β if nonzero, specifies cleanup mode:1for full cleanup,2for cleanup except for.dvi,.psand.pdffiles,3for cleanup except for dep and aux files. (there's also extra cleaning as specified by the$clean_ext,$clean_full_extand@generated_extsvariables.) this variable is equivalent to specifying one of the-cor-Coptions β¨ but honestly there should be no need to set this variable from an RC file.$clean_ext[""]β extra extensions of files forlatexmkto remove when any of the clean-up options (-cor-C) is selected π the value of this variable is a string containing the extensions separated by spaces.
it's also possible to specify a more general pattern of file to be deleted, by using the place holder %R, as in commands, and wildcards are fair game too π so setting
$clean_ext = "out %R-blx.bib %R-figures*.log pythontex-files-%R/*";
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) π
most of 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. so a normal situation is that $aux_dir equals $out_dir, which is the only case directly supported by TeXLive, unlike MiKTeX π note that even with TeXLive latexmk does now support different values for the directories β see the explanation of the $emulate_aux variable.
if $out_dir and $aux_dir are different, latexmk actually deletes any files of the specified names in both $aux_dir and $out_dir π«Ά this is because under certain error conditions, the files may be put in $out_dir instead of $aux_dir. this also handles the case of deleting any fls file, since that file is in $out_dir.
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
$clean_ext = "pythontex-files-%R/* pythontex-files-%R";
see also the (array) variable @generated_exts. in the past, this variable had certain uses beyond that of $clean_ext. but now, they accomplish the same things π in fact, after initialization including the processing of command line options, latexmk simply appends the list of extensions in $clean_ext to the array @generated_exts.
$clean_full_ext[""]β extra extensions of files forlatexmkto remove when the-Coption is selected, i.e. extensions of files to remove when the.dvi, etc. files are to be cleaned-up β¨ more general patterns are allowed, as for$clean_ext. the files specified by$clean_full_extto be deleted are relative to the directory specified by$out_dir.$compiling_cmd[""],$failure_cmd[""],$warning_cmd[""],$success_cmd[""]β these variables specify commands that get 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 [sic] 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:
$compiling_cmd = "xdotool search --name \"%D\" set_window --name \"%D compiling\"";
$success_cmd = "xdotool search --name \"%D\" set_window --name \"%D OK\"";
$warning_cmd = "xdotool search --name \"%D\" ".
"set_window --name \"%D CITE/REF ISSUE\"";
$failure_cmd = "xdotool search --name \"%D\" set_window --name \"%D FAILURE\"";
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 [sic] 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.
@cus_dep_list[()]β custom dependency list π see section on "Custom Dependencies".@default_excluded_files[()]β whenlatexmkis invoked with no files specified on the command line, then, by default, it will process all files in the current directory with the extension.texπ (in general, it will process the files specified in the@default_filesvariable.)@default_excluded_filesβ the "nope, not that one" list π Sometimes you want to leave particular files out of the default list, and this array is where you name them. Say you wanted to process all the.texfiles exceptcommon.texβ which isn't a standalone LaTeX file, it's one that getsinputby some or all of the others β you'd write:
@default_files = ("*.tex");
@default_excluded_files = ("common.tex");
If you've got a whole variable or a big pile of files to process, this trick saves you from listing every single one in @default_files and from having to update that list every time the set of files you're processing changes. lowkey a lifesaver π«Ά
Notes, because there are always notes: 1. This variable does nothing except when no files are specified on the latexmk command line. 2. Wildcards are allowed in @default_excluded_files. β¨
@default_files[("*.tex")] β the default roster of files to be processed π If no filenames are given on the command line,latexmkprocesses every tex file listed in@default_files, which by default is set to all tex files ("*.tex") in the current directory. It's a convenience thing: just runlatexmkand it'll chew through an appropriate set of files. But sometimes you only want some of them processed β in which case you list the ones you want by setting@default_filesin an initialization file (e.g. the file"latexmkrc"in the current directory). Then if no files are specified on the command line, the files you specified via@default_filesget processed. Three examples, because three is a blessed number:
@default_files = ("paper_current");
@default_files = ("paper1", "paper2.tex");
@default_files = ("*.tex", "*.dtx");
Note that more than one file may be given, and that the default extension is ".tex". Wild cards are allowed. The parentheses are there because @default_files is an array variable β i.e. a sequence of filename specifications is possible, periodt. π
If you want latexmk to process all .tex files with a few exceptions, go see the @default_excluded_files array variable. π
$dependents_phony[0] β if a list of dependencies gets output, this variable decides whether to include a phony target for each source file. If you use the dependents list in a Makefile, those dummy rules work around the errorsmakethrows at you when you delete header files without updating the Makefile to match. fr fr, it's a peacekeeping mission ποΈ$dependents_list[0] β whether to display a list (or lists!) of dependencies at the end of a run. π¦$deps_escape["none"] β this one picks which kind of escaping of space characters you want in dependency lists. The possible values are"none","unix","nmake"β corresponding respectively to no escaping, escaping with a"\"suitable for standard Unixmake, and escaping with"^", suitable for Microsoft'snmake. Currently the only character escaped is a space, since that's particularly common in file names and directory names. There are other characters that would need escaping if a dependency list is to be used as-is by amakeprogram β but those characters (e.g."$") commonly cause difficulties when used for.texdocuments. Moreover, the detailed rules for which characters need escaping depend on the version ofmake. so basically: vibes vary, check yourmakeπ$deps_file["-"] β name of the file that receives the list(s) of dependencies at the end of a run, used if$dependents_listis set. If the filename is"-", then the dependency list goes to stdout (i.e. normally the screen). β¨$do_cd[0] β whether to change the working directory to the directory specified for the main source file before processing it. The default behavior is to not do this, which is the same as what the*latexprograms do. This variable gets set by the-cdand-cd-options onlatexmk's command line. π§$dvi_filter[empty] β the dvi file filter to run on the newly produced dvi file, before any other processing. Equivalent to specifying the-dFoption. π$dvilualatex["dvilualatex %O %S"] β specifies the command line used to invoke thedvilualatexprogram. And note: like with other programs, you can use this variable not just to change the name of the program used, but also to specify options to the program. E.g.:
$dvilualatex = "dvilualatex --src-specials %O %S";
To do a coordinated setting of all of $dvilualatex, $hilatex, $latex, $pdflatex, $lualatex, and $xelatex, see the section "Advanced Configuration". π
$dvi_mode[See below for default] β if one, generate a dvi version of the document by use oflatex. Equivalent to the-dvioption. If2, generate a dvi version of the document by use ofdvilualatex. Equivalent to the-dviluaoption. The variable$dvi_modedefaults to0, but if no explicit requests are made for other types of file (postscript, pdf), then$dvi_modewill be set to1. In addition, if a request is made for a file for which a.dvifile is a prerequisite and$dvi_modeis zero, then$dvi_modeis set to1. the way it just quietly fills itself in ππ$dvilualatex_silent_switch["-interaction=batchmode"] β switch(es) for thedvilualatexprogram (specified in the variable$dvilualatex) when silent mode is on. See details of the$latex_silent_switchfor other information that equally applies to$dvilualatex_silent_switch. π¦$dvi_previewer["start xdvi %O %S"under UNIX] β the command to invoke a dvi-previewer. [Under MS-Windows the default is"start"; thenlatexmkarranges to use the MS-Windows start program, which will cause whatever command the system has associated with.dvifiles to be run.]
Important note, bestie, listen up: normally you'll want a previewer to run detached, so that latexmk doesn't sit there waiting for the previewer to terminate before continuing its work. So normally you should prefix the command with "start ", which flags to latexmk that it should do the detaching of the previewer itself (by whatever method is appropriate to the operating system). But sometimes letting latexmk do the detaching isn't appropriate (for a variety of non-trivial reasons), so you should put the "start " bit in yourself, whenever it's needed. π
$dvi_previewer_landscape["start xdvi %O %S"] β the command to invoke a dvi-previewer in landscape mode. [Under MS-Windows the default is"start"; thenlatexmkarranges to use the MS-Windows start program, which will cause whatever command the system has associated with.dvifiles to be run.] π$dvipdf["dvipdf -dALLOWPSTRANSPARENCY %O %S %D"] β command to convert.dvito.pdffile. A common reconfiguration is to use thedvipdfmcommand, which needs its arguments in a different order:
$dvipdf = "dvipdfm %O -o %D %S";
WARNING: the defaultdvipdfscript generates pdf files with bitmapped fonts, which do not look good when viewed byacroread. That script should be modified to givedvipsthe options"-P pdf"to ensure that type 1 fonts are used in the pdf file. π
$dvipdf_silent_switch["-q"] β switch(es) for thedvipdfprogram when silent mode is on. N.B. The standarddvipdfprogram runs silently, so adding the silent switch has no effect β but it's actually innocuous. If an alternative program is used, e.g.dvipdfmx, then the silent switch does have an effect. The default setting is correct fordvipdfmanddvipdfmx. π$dvips["dvips %O -o %D %S"] β the program to be used as a filter to convert a.dvifile to a.psfile. If pdf is going to be generated from ps, then the value of the$dvips_pdf_switchvariable β see below β will be included in the options substituted for"%O". β¨$dvips_landscape["dvips -tlandscape %O -o %D %S"] β the program to be used as a filter to convert a.dvifile to a.psfile in landscape mode. πΈ$dvips_pdf_switch["-P pdf"] β switch(es) for thedvipsprogram when a pdf file is to be generated from a.psfile. π$dvips_silent_switch["-q"] β switch(es) for thedvipsprogram when silent mode is on. π¦$dvi_update_command[""] β when the dvi previewer is set to be updated by running a command, this is the command that gets run. See the info for the variable$dvi_update_methodfor further information, and see the info on the variable$pdf_update_methodfor an example of the analogous case with a pdf previewer. π$dvi_update_method[2under UNIX,1under MS-Windows] β how the dvi viewer updates its display when the dvi file has changed. The values here apply equally to the$pdf_update_methodand to the$ps_update_methodvariables. π0=> update is automatic,1=> manual update by user, which may only mean a mouse click on the viewer's window or may mean a more serious action.2=> Send the signal, whose number is in the variable$dvi_update_signal. The default value under UNIX is suitable forxdvi.3=> Viewer cannot do an update, because it locks the file. (As withacroreadunder MS-Windows.)4=> run a command to do the update. The command is specified by the variable$dvi_update_command.
See information on the variable $pdf_update_method for an example of updating by command. π
$dvi_update_signal[Under UNIX:SIGUSR1, which is a system-dependent value] β the number of the signal that gets sent to the dvi viewer when it's updated by sending a signal β see the info on the variable$dvi_update_method. The default value is the one appropriate forxdvion a UNIX system. β$emulate_aux[1] β whether to emulate the use of the aux directory when$aux_dirand$out_dirare different, rather than using the-aux-directoryoption for the*latexprograms. (MiKTeX supports-aux-directory, but TeXLive doesn't.) π«Ά
okay so if you're using a version of *latex that doesn't support -aux-directory β like, say, TeXLive β latexmk will automatically switch aux_dir emulation on after the first run of *latex, because it finds the .log file in the wrong place. But bestie, it's better to set $emulate_aux to 1 in an rc file, or equivalently use the -emulate-aux-dir option. This emulation mode works equally well with MiKTeX. β¨
Aux directory emulation means that when *latex is invoked, the output directory provided to *latex is set to be the desired aux directory. After that, any files that need to be in the output directory will be moved there by latexmk. (These are the files with extensions .dvi, .ps, .pdf, .synctex, .synctex.gz, and, depending on the setting of the $fls_uses_out_dir variable, also the .fls file.)
$failure_cmd[undefined] β See the documentation for$compiling_cmd.$fdb_ext["fdb_latexmk"] β The extension of the file whichlatexmkgenerates to contain a database of information on source files. You will not normally need to change this. π@file_not_foundβ This is an array of Perl regular expressions that are patterns to find messages in the.logfile from a run of*latexthat indicate that a file was looked for and not found. To see the current default set, you should look at the definition of@file_not_foundin thelatexmk.plfile.
In the regular expression, the string for the name of the missing file should be enclosed in parentheses. That carries the implication that after latexmk gets a successful match to the pattern, the variable $1 is set to the filename, which is then picked up by latexmk.
If you happen to encounter a package that gives a missing file message of a different form than one that matches one of the built-in patterns, you can add another pattern to the array. An example would be
push @file_not_found, '^No file\\s+(.+)\\s*$';
The regular expression itself is
^Missing file\s+(.+)\s*$
But the corresponding string specification in the push statement has to have the backslashes doubled. (iykyk)
This regular expression matches a line that starts with 'No file', then has one or more white space characters, then any number of characters forming the filename, then possible white space, and finally the end of the line. (See documentation on Perl regular expressions for details.)
$filetime_causality_threshold[5] β The use of this variable is as follows: at a number of places,latexmkneeds to determine whether a particular file has been produced during a just-concluded run of some rule/program or is leftover from a previous run. (An example is the production of a.bcffile by thebiblatexpackage during a run of*latexto provide bibliographic information to thebiberprogram. If a.bcffile is not produced during a current run of*latex, but is leftover from a previous run, thenlatexmkhas to conclude that the.texdocument has changed so thatbiberis no longer to be used.)
latexmk's criterion that a file has been produced during a run is that the modification time of the file is more recent than the system time at the beginning of the run. Basically, if the modification time is earlier than this, then it is a leftover from a previous run. However, a naive use of the criterion can, among other things, run afoul of the granularity of how file times are stored in some file systems, which means it is possible that the filesystem's reported time for a file might be a second or more earlier than the actual modification time, the exact difference being quite random.
The variable $filetime_causality_threshold allows an appropriate sloppiness in latexmk's use of file modification time. It can be quite generous; it should merely be less than the time scale on which a human user makes changes to source files for a document (or to configuration files, etc). π«Ά
$fls_uses_out_dir[0] β This variable determines whether or not the.flsfile should be in the output directory instead of the natural directory, which is the aux directory. If the variable is nonzero, the.flsfile is to be in the output directory. See the section AUXILIARY AND OUTPUT DIRECTORIES for more details about these directories. The rationale for the existence of the variable$fls_uses_aux_diris explained there.
In all cases, if latexmk finds that an .fls file has been generated in the opposite directory to the one specified by $fls_uses_out_dir, it copies the file to the other directory (aux or output directory as appropriate). The file is copied rather than simply moved, to avoid potential clashes with other software that assumes the .fls file is generated in the directory it was written to by *latex. Thus the effect an incorrect setting of $fls_uses_out_dir is only to cause a superfluous copy of the .fls file to be generated. π
$force_mode[0] β If nonzero, continue processing past minor latex errors including unrecognized cross references. Equivalent to specifying the-foption.@generated_exts[( 'aux', 'bcf', 'fls', 'idx', 'ind', 'lof', 'lot', 'out', 'toc', 'blg', 'ilg', 'log', 'xdv' )] β This contains a list of extensions for files that are generated during processing, and that should be deleted during a main clean up operation, as invoked by the command line option-c. (The use of-Cor-gggives this clean up and more.)
The default values are extensions for standard files generated by *latex, bibtex, and the like. (Note that the clean up also deletes the fdb_latexmk file, but that's separately coded into latexmk, currently.)
After initialization of latexmk and the processing of its command line, the items in clean_ext are appended to @generated_exts. So these two variables have the same meaning (contrary to older versions of latexmk).
The items in @generated_exts are normally extensions of files, whose base name is the same as the main tex file. But it is also possible to specify patterns including that basename β see the explanation of the variable $clean_ext.
In addition to specifying files to be deleted in a clean up, latexmk uses the same specification to assist its examination of changes in source files: under some situations it needs to find those changes in files (since a previous run) that are expected to be due to the user editing a file. This contrasts with the cases of files that are generated by some program run by latexmk and that differ from the results of the previous run. This use of @generated_exts is normally unimportant, given the usual accuracy of latexmk's other ways of determining these generated files.
A convenient way to add an extra extension to the list, without losing the already defined ones, is to use a push command in the line in an RC file. E.g.,
push @generated_exts, "end";
adds the extension "end" to the list of predefined generated extensions. (This extension is used by the RevTeX package, for example.) slay
$go_mode[0] β If this variable equals zero, process files as usual, only running rules when they are determined to be out-of-date. This is equivalent to the-g-option.
If this variable equals one, force latexmk to run each rule at least once, even under situations where latexmk would normally decide that no changes in the source files have occurred since the previous run. This behavior is useful, for example, if you change the configuration and wish to reprocess all files. This is equivalent to the -g option.
If this variable equals two, perform a full clean up, as if the -C had been given, and then process normally from a clean initial situation. This is equivalent to the -gg option for "super go mode" or "clean make".
If this variable equals three, require at least one run of *latex. I.e., process as normal, except that initially, the *latex rule that is in use is set to be out-of-date, independently of the state of the files. This is equivalent to the -gt option. π₯
%hash_calc_ignore_patternβ !!!This variable is for experts only!!! π
The general rule latexmk uses for determining when an extra run of some program is needed is that one of the source files has changed. But consider for example a latex package that causes an encapsulated postscript file (an "eps" file) to be made that is to be read in on the next run. The file contains a comment line giving its creation date and time. On the next run the time changes, latex sees that the eps file has changed, and therefore reruns latex. This causes an infinite loop, that is only terminated because latexmk has a limit on the number of runs to guard against pathological situations. π
But the changing line has no real effect, since it is a comment. You can instruct latex to ignore the offending line as follows:
$hash_calc_ignore_pattern{'eps'} = '^%%CreationDate: ';
This creates a rule for files with extension .eps about lines to ignore. The left-hand side is a Perl idiom for setting an item in a hash. Note that the file extension is specified without a period. The value, on the right-hand side, is a string containing a regular expression. (See documentation on Perl for how they are to be specified in general.) This particular regular expression specifies that lines beginning with "%%CreationDate: " are to be ignored in deciding whether a file of the given extension .eps has changed. periodt β¨
lowkey important detail: you only get one regular expression per extension. So if you need more than one pattern to specify lines to ignore, you gotta smoosh them into a single regex. Easiest way? Separate the simple patterns with a vertical bar character (that's "alternation" in regex-speak, iykyk). Like:
$hash_calc_ignore_pattern{'eps'} = '^%%CreationDate: |^%%Title: ';
β¨ that makes lines starting with either ^%%CreationDate: or ^%%Title: get ignored. Slay.
Also a real scenario: someone (maybe a system or user initialization file) set a pattern to ignore, and you wanna remove it in a file that's read later. Perl's delete function is your bestie here, e.g.:
delete $hash_calc_ignore_pattern{'eps'};
$hilatex ["hilatex %O %S"]
specifies the command line for the hilatex program. cute.
$hnt_mode [0]
whether to generate a hnt version of the document by use of hilatex. Can be turned on by using the -hnt option. π
$jobname [""]
this one specifies the jobname, i.e. the basename used for generated files (.aux, .log, .dvi, .ps, .pdf, etc). If this variable is a null string, then the basename is just the basename of the main tex file. (Heads up though: at present, the string in $jobname should not contain spaces. π)
The placeholder %A is permitted β it gets substituted by the basename of the TeX file. The primary purpose is when you have a bunch of tex files to process and you want a different jobname for each, but one that's distinct for each. So if you wanted to compare compilations of a set of files on different operating systems, with distinct filenames for all the cases, you could set:
$jobname = "%A-$^O";
in an initialization file. (Fun fact: $^O is a variable provided by perl that contains perl's name for the operating system. π)
Say you had .tex files test1.tex and test2.tex. Then when you run:
latexmk -pdf *.tex
both files get compiled. The .aux, .log, and .pdf files will have basenames test1-MSWin32 and test2-MSWin32 on a MS-Windows system, test1-darwin and test2-darwin on an OS-X system, and a whole variety of similar cases on linux systems. π
$kpsewhich ["kpsewhich %S"]
the program called to locate a source file when the name alone isn't sufficient. Most filenames used by latexmk have enough path info to be found directly. But sometimes β notably when a .bib or a .bst file is found from the log file of a bibtex or biber run β only the base name of the file is known, not its path. The program specified by $kpsewhich is what finds it. π΅οΈ
(For the advanced users, because of the different way latexmk uses the command specified in $kpsewhich, some of the possibilities listed in the FORMAT OF COMMAND SPECIFICATIONS don't apply. The internal and start keywords are not available. A simple command specification with possible options and then "%S" is all that's guaranteed to work. Note that for other commands, "%S" is substituted by a single source file. In contrast, for $kpsewhich, "%S" may be substituted by a long list of space-separated filenames, each of which is quoted. The result on STDOUT of running the command is then piped to latexmk. π«Ά)
See also the @BIBINPUTS variable for another way latexmk also uses to try to locate files; it applies only in the case of .bib files.
$kpsewhich_show [0]
whether to show diagnostics about invocations of kpsewhich β the command line used to invoke it and the results. These diagnostics show up if $kpsewhich_show is non-zero or if diagnostics mode is on. (But in that second case, lots of other diagnostics are also shown, fair warning π.) Without these diagnostics there's literally nothing visible in latexmk's screen output about invocations of kpsewhich.
$landscape_mode [0]
if nonzero, run in landscape mode, using the landscape mode previewers and dvi to postscript converters. Equivalent to the -l option. Normally not needed with current previewers. π
$latex ["latex %O %S"]
specifies the command line for the LaTeX processing program. And ngl, as with other programs, you can use this variable not just to change the name of the program used, but also to specify options to the program. E.g.:
$latex = "latex --src-specials %O %S";
To do a coordinated setting of all of $dvilualatex, $hilatex, $latex, $pdflatex, $lualatex, and $xelatex, see the section "Advanced Configuration". π
%latex_input_extensions
this variable specifies the extensions tried by latexmk when it finds that a LaTeX run resulted in an error that a file has not been found, and the file is given without an extension. This typically happens with LaTeX commands of the form \input{file} or \includegraphics{figure}, when the relevant source file doesn't exist. π¬
In this situation, latexmk searches for custom dependencies to make the missing file(s), but restricts it to the extensions specified by %latex_input_extensions. The default extensions are 'tex' and 'eps'.
(For Perl experts: %latex_input_extensions is a hash whose keys are the extensions. The values are irrelevant.) Two subroutines are provided for manipulating this and the related variable %pdflatex_input_extensions: add_input_ext and remove_input_ext. They're used as in the following examples, which are possible lines in an initialization file:
remove_input_ext( 'latex', 'tex' );
removes the extension 'tex' from latex_input_extensions, and:
add_input_ext( 'latex', 'asdf' );
adds the extension 'asdf' to latex_input_extensions. (Naturally with such an extension, you should have made an appropriate custom dependency for latexmk, and should also have done the appropriate programming in the LaTeX source file to enable the file to be read. The standard extensions are handled by LaTeX and its graphics/graphicx packages. π)
$latex_silent_switch ["-interaction=batchmode"]
switch(es) for the LaTeX processing program when silent mode is on. π€«
If you use MikTeX, you may prefer the results if you configure the options to include -c-style-errors, e.g. by the following line in an initialization file:
$latex_silent_switch = "-interaction=batchmode -c-style-errors";
$lpr ["lpr %O %S" under UNIX/Linux, "NONE lpr" under MS-Windows]
the command to print postscript files. π¨οΈ
Under MS-Windows (unlike UNIX/Linux), there's no standard program for printing files. But there are ways you can do it. For example, if you have gsview installed, you could use it with the option "/p":
$lpr = '"c:/Program Files/Ghostgum/gsview/gsview32.exe" /p';
If gsview is installed in a different directory, you'll need to make the appropriate change. Note the combination of single and double quotes around the name: the single quotes specify that this is a string to be assigned to the configuration variable $lpr; the double quotes are part of the string passed to the operating system to get the command obeyed. That's necessary because one part of the command name ("Program Files") contains a space, which would otherwise be misinterpreted. π
$lpr_dvi ["NONE lpr_dvi"]
the printing program to print dvi files.
$lpr_pdf ["NONE lpr_pdf"]
the printing program to print pdf files.
Under MS-Windows you could set this to use gsview, if it's installed, e.g.:
$lpr = '"c:/Program Files/Ghostgum/gsview/gsview32.exe" /p';
If gsview is installed in a different directory, you'll need to make the appropriate change. Note the double quotes around the name: this is necessary because one part of the command name ("Program Files") contains a space which would otherwise be misinterpreted. π«
$lualatex ["lualatex %O %S"]
specifies the command line for the LaTeX processing program that's to be used when the lualatex program is called for (e.g. by the option -lualatex). β¨
To do a coordinated setting of all of $dvilualatex, $hilatex, $latex, $pdflatex, $lualatex, and $xelatex, see the section "Advanced Configuration".
%lualatex_input_extensions
this variable specifies the extensions tried by latexmk when it finds that a lualatex run resulted in an error that a file has not been found, and the file is given without an extension. This typically happens with LaTeX commands of the form \input{file} or \includegraphics{figure}, when the relevant source file doesn't exist.
In this situation, latexmk searches for custom dependencies to make the missing file(s), but restricts it to the extensions specified by the variable %pdflatex_input_extensions. The default extensions are 'tex', 'pdf', 'jpg', and 'png'. πΈ
See details of the %latex_input_extensions for other information that equally applies to %lualatex_input_extensions.
$lualatex_silent_switch ["-interaction=batchmode"]
switch(es) for the lualatex program (specified in the variable $lualatex) when silent mode is on. π€«
See details of the $latex_silent_switch for other information that equally applies to $lualatex_silent_switch.
$make ["make"]
the make processing program.
$makeindex ["makeindex %O -o %D %S"]
the index processing program.
$makeindex_fudge [0]
when using makeindex, whether to change directory to $aux_dir before running makeindex. Set to 1 if $aux_dir is not an explicit subdirectory of the current directory β otherwise makeindex will flat-out refuse to write its output and log files, for security reasons. π¨
$makeindex_silent_switch ["-q"]
switch(es) for the index processing program when silent mode is on.
$max_repeat [5] β¨
This is the max number of times latexmk will run *latex before itβs like, βokay bestie, this might be an infinite loop, Iβm bailingβ instead of rerunning *latex again to sort out cross-references, etc. The default value covers all normal cases.
(And yeah, the βetcβ is doing a lot of work β it covers a ton of cases where one run of *latex generates files that get read in on a later run.) π
$MSWin_back_slash [1] π¦
Only matters when latexmk is running under MS-Windows. Default is 1. When a command runs under MS-Windows, latexmk substitutes "\" for the separator character between components of a directory name. Internally, latexmk uses "/" as the directory separator character, which is what Unix-like systems use.
For almost all programs and almost all filenames under MS-Windows, both "\" and "/" are acceptable as the directory separator character β as long as filenames are properly quoted. But some programs might exist that only accept "\" on the command line, since thatβs the standard directory separator for MS-Windows. So for safety, latexmk makes the substitution from "/" to "\", by default.
However, there are also programs on MS-Windows for which a back slash "\" is interpreted differently than as a directory separator; for those, the directory separator should be "/". Programs with this behavior include all the *latex programs in the TeXLive implementation (but not the MiKTeX implementation). Hence if you use TeXLive on MS-Windows, then $MSWin_back_slash should be set to zero. π
$new_viewer_always [0] πΈ
This variable applies to latexmk only in continuous-preview mode. If $new_viewer_always is 0, latexmk will check for a previously running previewer on the same file β and if one is running, it wonβt start a new one. If $new_viewer_always is non-zero, this check is skipped, and latexmk behaves as if no viewer is running. π
$out_dir [""] π
If non-blank, this variable specifies the output directory.
This is the directory where the main output files are written (dvi, ps, pdf, synctex, synctex.gz). In addition, if the aux directory equals the output directory β which is the case by default β then other generated files are in effect written to the output directory.
If $out_dir is blank, the output directory is the current directory at the invocation of *latex; this is equivalent to setting $out_dir to '.'.
See the section AUXILIARY AND OUTPUT DIRECTORIES for more details. π₯
$out2_dir [""] π§
(Experimental new feature, bestie.)
If non-blank, this variable specifies the final-output directory β like, the directory for the final output files. If this variable is blank (its default value), the final-output directory is the same as the output directory.
See the description of the option -out2dir for an explanation of the rationale for the idea of separate output and final-output directories.
If the final-output directory is different from the output directory, then after a full round of compilations of the document, the relevant set of files is copied here from the output directory. The files copied are specified by the @out2_exts variable, and by default are those with extensions 'hnt', 'pdf', 'ps', 'synctex', 'synctex.gz', and a basename the same as for the main *latex compilation. π
@out2_exts [( 'hnt', 'pdf', 'ps', 'synctex', 'synctex.gz' )] π
This variable lists the extensions of the files to be copied to the final-output directory. The basename of the files is that for the main *latex compilation (corresponding to the value specified by the placeholder %R). More general names may be specified in the same way as for the @generated_exts variable, by inclusion of %R in a pattern, e.g.,
push @out2_exts, '%R-2up.pdf';
$pdf_mode [0] π
If zero, do NOT generate a pdf version of the document. If equal to 1, generate a pdf version of the document using pdflatex, using the command specified by the $pdflatex variable. If equal to 2, generate a pdf version of the document from the ps file, by using the command specified by the $ps2pdf variable. If equal to 3, generate a pdf version of the document from the dvi file, by using the command specified by the $dvipdf variable. If equal to 4, generate a pdf version of the document using lualatex, using the command specified by the $lualatex variable. If equal to 5, generate a pdf version (and an xdv version) of the document using xelatex, using the commands specified by the $xelatex and xdvipdfmx variables.
In $pdf_mode=2, it is ensured that .dvi and .ps files are also made. In $pdf_mode=3, it is ensured that a .dvi file is also made. But this may be overridden by the document. β
$pdflatex ["pdflatex %O %S"] π
Specifies the command line for the LaTeX processing program in a version that makes a pdf file instead of a dvi file.
An example use of this variable is to add certain options to the command line for the program, e.g.,
$pdflatex = "pdflatex --shell-escape %O %S";
(In some earlier versions of latexmk, you needed to use an assignment to $pdflatex to allow the use of lualatex or xelatex instead of pdflatex. There are now separate configuration variables for the use of lualatex or xelatex. See $lualatex and $xelatex.)
To do a coordinated setting of all of $dvilualatex, $hilatex, $latex, $pdflatex, $lualatex, and $xelatex, see the section βAdvanced Configurationβ. π
%pdflatex_input_extensions π
This variable specifies the extensions tried by latexmk when it finds that a pdflatex run resulted in an error that a file has not been found, and the file is given without an extension. This typically happens when LaTeX commands of the form \input{file} or \includegraphics{figure} β when the relevant source file does not exist.
In this situation, latexmk searches for custom dependencies to make the missing file(s), but restricts it to the extensions specified by the variable %pdflatex_input_extensions. The default extensions are 'tex', 'pdf', 'jpg, and 'png'.
See details of the %latex_input_extensions for other information that equally applies to %pdflatex_input_extensions. π«Ά
$pdflatex_silent_switch ["-interaction=batchmode"] π
Switch(es) for the pdflatex program (specified in the variable $pdflatex) when silent mode is on.
See details of the $latex_silent_switch for other information that equally applies to $pdflatex_silent_switch. π
$pdf_previewer ["start acroread %O %S"] π₯
The command to invoke a pdf-previewer.
On MS-Windows, the default is changed to "cmd /c start """; under more recent versions of Windows, this will cause to be run whatever command the system has associated with .pdf files. But this may be undesirable if this association is to acroread β see the notes in the explanation of the -pvc option.]
On OS-X the default is changed to "open %S", which results in OS-X starting up (and detaching) the viewer associated with the file. By default, for pdf files this association is to OS-Xβs preview, which is quite satisfactory.
WARNING: Problem under MS-Windows: ifacroreadis used as the pdf previewer, and it is actually viewing a pdf file, the pdf file cannot be updated. Thus makesacroreada bad choice of previewer if you use latexmkβs previous-continuous mode (option-pvc) under MS-windows. This problem does not occur if, for example, SumatraPDF or gsview is used to view pdf files.
Important note: Normally you will want to have a previewer run detached, so that latexmk doesnβt wait for the previewer to terminate before continuing its work. So normally you should prefix the command by "start ", which flags to latexmk that it should do the detaching of the previewer itself (by whatever method is appropriate to the operating system). But sometimes letting latexmk do the detaching is not appropriate (for a variety of non-trivial reasons), so you should put the "start " bit in yourself, whenever it is needed. π€
$pdf_update_command [""] π
When the pdf previewer is set to be updated by running a command, this is the command that is run. See the information for the variable $pdf_update_method. π¦
$pdf_update_method [1 under UNIX, 3 under MS-Windows] πΈ
How the pdf viewer updates its display when the pdf file has changed. See the information on the variable $dvi_update_method for the codes. (Note that information needs be changed slightly so that for the value 4, to run a command to do the update, the command is specified by the variable $pdf_update_command, and for the value 2, to specify update by signal, the signal is specified by $pdf_update_signal.)
Note that acroread under MS-Windows (but not UNIX) locks the pdf file, so the default value is then 3.
Arranging to use a command to get a previewer explicitly updated requires three variables to be set. For example:
$pdf_previewer = "start xpdf -remote %R %O %S";
$pdf_update_method = 4;
$pdf_update_command = "xpdf -remote %R -reload";
The first setting arranges for the xpdf program to be used in its βremote server modeβ, with the server name specified as the rootname of the TeX file. The second setting arranges for updating to be done in response to a command, and the third setting sets the update command. β¨
$pdf_update_signal [Under UNIX: SIGHUP, which is a system-dependent value] β
The number of the signal that is sent to the pdf viewer when it is updated by sending a signal β see the information on the variable $pdf_update_method. The default value is the one appropriate for gv on a UNIX system. π
πΈ $pid_position [1 under UNIX, -1 under MS-Windows]
okay so $pid_position is literally the βwhich word in the $pscmd output is the process ID?β dial π
. The first word in the line is numbered 0. The default value of 1 (2nd word in line) is correct for Solaris 2.6, Linux, and OS-X with their default settings of $pscmd.
Setting the variable to -1 is used to indicate that $pscmd is not to be used.
π¦ $postscript_mode [0]
If nonzero, generate a postscript version of the document. Equivalent to the -ps option.
If some other request is made for which a postscript file is needed, then $postscript_mode will be set to 1.
π $pre_tex_code ['']
Sets TeX code to be executed before inputting the source file. This works if the relevant one of $latex, etc contains a suitable command line with a %P or %U substitution. For example you could do
$latex = 'latex %O %P';
$pre_tex_code = '\AtBeginDocument{An initial message\par}';
To set all of $latex, $pdflatex, $lualatex, and $xelatex you could use the subroutine alt_tex_cmds:
&alt_tex_cmds;
$pre_tex_code = '\AtBeginDocument{An initial message\par}';
π§ $preview_continuous_mode [0]
If nonzero, run a previewer to view the document, and continue running latexmk to keep .dvi up-to-date. Equivalent to the -pvc option. Which previewer is run depends on the other settings, see the command line options -view=, and the variable $view.
π $preview_mode [0]
If nonzero, run a previewer to preview the document. Equivalent to the -pv option. Which previewer is run depends on the other settings, see the command line options -view=, and the variable $view.
π $printout_mode [0]
If nonzero, print the document using the command specified in the $lpr variable. Equivalent to the -p option. This is recommended not to be set from an RC file, otherwise you could waste lots of paper.
π $print_type = ["auto"]
Type of file to printout: possibilities are "auto", "dvi", "none", "pdf", or "ps". See the option -print= for the meaning of the "auto" value.
π $pscmd
Command used to get all the processes currently run by the user. The -pvc option uses the command specified by the variable $pscmd to determine if there is an already running previewer, and to find the process ID (needed if latexmk needs to signal the previewer about file changes).
Each line of the output of this command is assumed to correspond to one process. See the $pid_position variable for how the process number is determined.
The default for pscmd is "NONE" under MS-Windows and cygwin (i.e., the command is not used), "ps -ww -u $ENV{USER}" under OS-X, and "ps -f -u $ENV{USER}" under other operating systems (including Linux). In these specifications "$ENV{USER}" is substituted by the username.
β $ps2pdf ["ps2pdf -dALLOWPSTRANSPARENCY %O %S %D"]
Command to convert .ps to .pdf file.
π $ps_filter [empty]
The postscript file filter to be run on the newly produced postscript file before other processing. Equivalent to specifying the -pF option.
π«Ά $ps_previewer ["start gv %O %S", but start %O %S under MS-Windows]
The command to invoke a ps-previewer. (The default under MS-Windows will cause to be run whatever command the system has associated with .ps files.)
Note that gv could be used with the -watch option updates its display whenever the postscript file changes, whereas ghostview does not. However, different versions of gv have slightly different ways of writing this option. You can configure this variable appropriately.
WARNING: Linux systems may have installed one (or more) versions ofgvunder different names, e.g.,ggv,kghostview, etc, but perhaps not one actually calledgv.
Important note: Normally you will want to have a previewer run detached, so thatlatexmkdoesn't wait for the previewer to terminate before continuing its work. So normally you should prefix the command by"start ", which flags tolatexmkthat it should do the detaching of the previewer itself (by whatever method is appropriate to the operating system). But sometimes lettinglatexmkdo the detaching is not appropriate (for a variety of non-trivial reasons), so you should put the"start "bit in yourself, whenever it is needed.
πΈ $ps_previewer_landscape ["start gv -swap %O %S", but start %O %S under MS-Windows]
The command to invoke a ps-previewer in landscape mode.
π¦ $ps_update_command [""]
When the postscript previewer is set to be updated by running a command, this is the command that is run. See the information for the variable $ps_update_method.
π $ps_update_method [0 under UNIX, 1 under MS-Windows]
How the postscript viewer updates its display when the .ps file has changed. See the information on the variable $dvi_update_method for the codes. (Note that information needs be changed slightly so that for the value 4, to run a command to do the update, the command is specified by the variable $ps_update_command, and for the value 2, to specify update by signal, the signal is specified by $ps_update_signal.)
π§ $ps_update_signal [Under UNIX: SIGHUP, which is a system-dependent value]
The number of the signal that is sent to the pdf viewer when it is updated by sending a signal -- see $ps_update_method. The default value is the one appropriate for gv on a UNIX system.
π $pvc_timeout [0]
If this variable is nonzero, there will be a timeout in pvc mode after a period of inactivity. Inactivity means a period when latexmk has detected no file changes and hence has not taken any actions like compiling the document. The period of inactivity is in the variable $pvc_timeout_mins.
π $pvc_timeout_mins [30]
The period of inactivity, in minutes, after which pvc mode times out. This is used if $pvc_timeout is nonzero.
π $pvc_view_file_via_temporary [1]
The same as $always_view_file_via_temporary, except that it only applies in preview-continuous mode (-pvc option).
π $quote_filenames [1]
This specifies whether substitutions for placeholders in command specifications (as in $pdflatex) are surrounded by double quotes. If this variable is 1 (or any other value Perl regards as true), then quoting is done. Otherwise quoting is omitted.
The quoting method used by latexmk is tested to work correctly under UNIX systems (including Linux and Mac OS-X) and under MS-Windows. It allows the use of filenames containing special characters, notably spaces. (But note that many versions of *latex cannot correctly deal with TeX files whose names contain spaces. Latexmk's quoting only ensures that such filenames are correctly treated by the operating system in passing arguments to programs.)
β $rc_report [1]
After initialization, whether to give a list of the RC files read.
π $recorder [1]
Whether to use the -recorder option to *latex. Use of this option 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.
It is generally recommended to use this option (or to configure the $recorder variable to be on.) But it only works if *latex supports the -recorder option, which is true for most current implementations.
Note about the name of the .fls file: Most implementations of *latex produce an .fls file with the same basename as the main document's LaTeX, e.g., for Document.tex, the .fls file is Document.fls. However, some implementations instead produce files named for the program, i.e., latex.fls or pdflatex.fls. In this second case, latexmk copies the latex.fls or pdflatex.fls to a file with the basename of the main LaTeX document, e.g., Document.fls.
π«Ά $search_path_separator [See below for default]
The character separating paths in the environment variables TEXINPUTS, BIBINPUTS, and BSTINPUTS. This variable is mainly used by latexmk when the -outdir, -output-directory, -auxdir, and/or -aux-directory options are used. In that case latexmk needs to communicate appropriately modified search paths to bibtex, dvipdf, dvips, and *latex.
[Comment to technically savvy readers:*latexdoesn't actually need the modified search path. But, surprisingly,dvipdfanddvipsdo, because sometimes graphics files get generated in the output or aux directories.]
The default under MSWin and Cygwin is ';' and under UNIX-like operating systems (including Linux and OS-X) is ':'. Normally the defaults give correct behavior. But there can be difficulties if your operating system is of one kind, but some of your software is running under an emulator for the other kind of operating system; in that case you'll need to find out what is needed, and set $search_path_separator explicitly. (The same goes, of course, for unusual operating systems that are not in the MSWin, Linux, OS-X, Unix collection.)
πΈ $show_time [0]
Whether to show time used, both the total and for individual steps.
Note: On MS Windows, this is clock time. On other OSs it is the CPU time used (by latexmk and the child processes it invokes). The OS-dependence is because of a limitation of Windows. If you wish to force the use of clock instead of CPU time, you can set
$times_are_clock = 1;
$silence_logfile_warnings [0]β bestie, this one controls whether, after a run of*latex, latexmk summarizes the warnings in the log file about undefined citations and references. Setting$silence_logfile_warnings=0gives you that summary of warnings (as long as silent mode isn't also on), and that's lowkey useful for locating undefined citations and references without digging through the much more verbose log file or the screen output of*latex. But the summary can also be excessively annoying π. The default is not to give these warnings. The command-line options-silence_logfile_warning_listand-silence_logfile_warning_list-also set this variable. π
Note that multiple occurrences for the same undefined object on the same page and same line will be compressed to a single warning.
$silent [0]β whether to run silently. Setting$silentto1has the same effect as the-quietor-silentoptions on the command line. π€«$sleep_time [2]β the time to sleep (in seconds) between checking for source-file changes when running with the-pvcoption. If non-zero, it's subject to a minimum value given by the$min_sleep_timevariable. But a zero value is also allowed. β³
A value of exactly 0 gives no delay between checks for source-file changes; it typically results in 100% CPU usage, which may not be desirable. π
In old versions of latexmk, the default value of $sleep_time was 2 β this gave -pvc mode a certain amount of CPU usage. On modern computers with fast multi-core CPUs, a smaller value, e.g., 0.1 can give good results, especially when working with small documents whose compilation may take well under a second. β‘
$texfile_search [""]β this is an obsolete variable, replaced by the@default_filesvariable. For backward compatibility, if you choose to set$texfile_search, it is a string of space-separated filenames, and then latexmk replaces@default_fileswith the filenames in$texfile_searchto which is added"*.tex". π§β¨$success_cmd [undefined]β see the documentation for$compiling_cmd. π$tmpdir [See below for default]β directory to store temporary files that latexmk may generate while running. The default under MSWindows (including cygwin) is to set$tmpdirto the value of the first of whichever of the system environment variablesTMPDIRorTEMPexists, otherwise to the current directory. Under other operating systems (expected to be UNIX/Linux, including OS-X), the default is the value of the system environment variableTMPDIRif it exists, otherwise"/tmp". π$use_make_for_missing_files [0]β whether to usemaketo try and make files that are missing after a run of*latex, and for which a custom dependency has not been found. This is generally useful only when latexmk is used as part of a bigger project which is built by using themakeprogram. π οΈ
Note that once a missing file has been made, no further calls to make will be made on a subsequent run of latexmk to update the file. Handling this problem is the job of a suitably defined Makefile. See the section "USING latexmk WITH make" for how to do this. The intent of calling make from latexmk is merely to detect dependencies. π‘
$user_deleted_file_treated_as_changed [0]β whether when testing for changed files, a user file that changes status from existing to non-existing should be regarded as changed. π€
The default value is 0, which implies that if a user file (as opposed to a generated file) has been deleted since the previous run, then no recompilation should be done. The reasoning is that a rerun would simply produce an error. π¬
If the value is 1, then disappearance of a user file is treated as triggering a rerun, but only in non-preview-continuous mode. If the value is 2, then disappearance of a user file is treated as triggering a rerun, always. π
$view ["default"]β which kind of file is to be previewed if a previewer is used. The possible values are"default","dvi","hnt","ps","pdf","none". The value of"default"means that the"highest"of the kinds of file generated is to be used (among.dvi,.hnt,.psand.pdf). πβ¨$warnings_as_errors [0]β normally latexmk copies the behavior of latex in treating undefined references and citations and multiply defined references as conditions that give a warning but not an error. The variable$warnings_as_errorscontrols whether this behavior is modified. π¨
When the variable is non-zero, latexmk at the end of its run will return a non-zero status code to the operating system if any of the files processed gives a warning about problems with citations or references (i.e., undefined citations or references or multiply defined references). This is after latexmk has completed all the runs it needs to try and resolve references and citations. Thus $warnings_as_errors being nonzero 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. A non-zero value $warnings_as_errors can be set by the command-line option -Werror. π€
The default behavior is normally satisfactory in the usual edit-compile-edit cycle. But, for example, latexmk can also be used as part of a build process for some bigger project, e.g., for creating documentation in the build of a software application. Then it is often sensible to treat citation and reference warnings as errors that require the overall build process to be aborted. Of course, since multiple runs of *latex are generally needed to resolve references and citations, what matters is not the warnings on the first run, but the warnings on the last run; latexmk takes this into account appropriately. π«Ά
In addition, when preview-continuous mode is used, a non-zero value for $warnings_as_errors changes the use of the commands $failure_cmd, $warning_cmd, and $success_cmd after a compilation. If there are citation or reference warnings, but no other errors, the behavior is as follows. If $warning_cmd is set, it is used. If it is not set, then if $warnings_as_errors is non-zero and $failure_cmd is set, then $failure_cmd. Otherwise $success_cmd is used, if it is set. (The foregoing explanation is rather complicated, because latexmk has to deal with the case that one or more of the commands isn't set.) π
$xdv_mode [0]β if one, generate an xdv version of the document by use of xelatex. π$xdvipdfmx ["xdvipdfmx -E -o %D %O %S"]β the program to make a pdf file from an xdv file (used in conjunction with xelatex when$pdf_mode=5). π₯$xdvipdfmx_silent_switch ["-q"]β switch(es) for thexdvipdfmxprogram when silent mode is on. π€«$xelatex ["xelatex %O %S"]β specifies the command line for the LaTeX processing program when thexelatexprogram is called for. See the documentation of the-xelatexoption for some special properties of latexmk's use of xelatex. π¦
Note about xelatex: latexmk uses xelatex to make an .xdv rather than .pdf file, with the .pdf file being created in a separate step. This is enforced by the use of the -no-pdf option. If %O is part of the command for invoking xelatex, then latexmk will insert the -no-pdf option automatically, otherwise you must provide the option yourself. See the documentation for the -pdfxe option for why latexmk makes a .xdv file rather than a .pdf file when xelatex is used. π
To do a coordinated setting of all of $dvilualatex, $hilatex, $latex, $pdflatex, $lualatex, and $xelatex, see the section "Advanced Configuration". β¨
%xelatex_input_extensionsβ this variable specifies the extensions tried by latexmk when it finds that an xelatex run resulted in an error that a file has not been found, and the file is given without an extension. This typically happens when LaTeX commands of the form\input{file}or\includegraphics{figure}, when the relevant source file does not exist. π§
In this situation, latexmk searches for custom dependencies to make the missing file(s), but restricts it to the extensions specified by the variable %xelatex_input_extensions. The default extensions are 'tex', 'pdf', 'jpg, and 'png'. See details of the %latex_input_extensions for other information that equally applies to %xelatex_input_extensions. π
$xelatex_silent_switch ["-interaction=batchmode"]β switch(es) for thexelatexprogram (specified in the variable$xelatex) when silent mode is on. See details of the$latex_silent_switchfor other information that equally applies to$xelatex_silent_switch. π€
π CUSTOM DEPENDENCIES π
In any RC file a set of custom dependencies can be set up to convert a file with one extension to a file with another. An example use of this would be to allow latexmk to convert a .fig file to .eps to be included in the .tex file. π¨β¨
π οΈ Defining a custom dependency π οΈ
The old method of configuring latexmk to use a custom dependency was to directly manipulate the @cus_dep_list array that contains information defining the custom dependencies. (See the section "Old Method of Defining Custom Dependencies" for details.) This method still works, but is no longer preferred. π§
A better method is to use the subroutines that allow convenient manipulations of the custom dependency list. These are:
add_cus_dep( fromextension, toextension, must, subroutine )
remove_cus_dep( fromextension, toextension )
show_cus_dep()
The arguments are as follows:
- from extension: The extension of the file we are converting from (e.g.
"fig"). It is specified without a period. π₯ - to extension: The extension of the file we are converting to (e.g.
"eps"). It is specified without a period. π€ mustβ okay so this is the source-file vibe check. If it's non-zero, the file from which we are converting must exist; if it doesn't,latexmkwill give an error message and exit unless the-foption is specified. Ifmustis zero and the file we're converting from doesn't exist, then no action is taken. Generally, the appropriate value ofmustis zero.functionβ the name of the subroutine thatlatexmkshould call to perform the file conversion. The first argument to the subroutine is the base name of the file to be converted without any extension. The subroutines are declared in the syntax of Perl. The function should return0if it was successful and a nonzero number if it failed. return-code understood, no cap β¨
And naturally, add_cus_dep adds a custom dependency with the specified from and to extensions. If a custom dependency has been previously defined (e.g., in an rcfile that was read earlier), then it is replaced by the new one. π
The subroutine remove_cus_dep removes the specified custom dependency. The subroutine show_cus_dep causes a list of the currently defined custom dependencies to be sent to the screen output. π«Ά
π οΈ How custom dependencies are used π οΈ
An instance of a custom dependency rule is created whenever latexmk detects that a run of *latex needs to read a file, like a graphics file, whose extension is the to-extension of a custom dependency. Then latexmk examines whether a file exists with the same name, but with the corresponding from-extension, as specified in the custom-dependency. If it does, then a corresponding instance of the custom dependency is created, after which the rule is invoked whenever the destination file (the one with the to-extension) is out-of-date with respect to the corresponding source file. it's giving dependency pipeline realness
To make the new destination file, the Perl subroutine specified in the rule is invoked, with an argument that is the base name of the files in question. Simple cases just involve a subroutine invoking an external program; this can be done by following the templates below, even by those without knowledge of the Perl programming language. Of course, experts could do something much more elaborate. π§
One item in the specification of each custom-dependency rule, labeled must above, specifies how the rule should be applied when the source file fails to exist. important little checkbox, bestie
When latex reports that an input file (e.g., a graphics file) does not exist, latexmk tries to find a source file and a custom dependency that can be used to make it. If it succeeds, then it creates an instance of the custom dependency and invokes it to make the missing file, after which the next pass of latex etc will be able to read the newly created file. β¨
Note for advanced usage: The operating system's environment variable TEXINPUTS can be used to specify a search path for finding files by latex etc. Correspondingly, when a missing file is reported, latexmk looks in the directories specified in TEXINPUTS as well as in the current directory, to find a source file from which an instance of a custom dependency can be used to make the missing file. iykyk search-path behavior
π§ Function to implement custom dependency, traditional method π§
The function that implements a custom dependency gets the information on the files to be processed in two ways. The first is through its one argument; the argument contains the base name of the source and destination files. The second way is described later. π
A simple and typical example of code in an initialization rcfile using the first method is:
add_cus_dep( 'fig', 'eps', 0, 'fig2eps' );
sub fig2eps {
system( "fig2dev -Leps \"$_[0].fig\" \"$_[0].eps\"" );
}
The first line adds a custom dependency that converts a file with extension fig, as created by the xfig program, to an encapsulated postscript file, with extension eps. The remaining lines define a subroutine that carries out the conversion. If a rule for converting fig to eps files already exists (e.g., from a previously read-in initialization file), latexmk will delete this rule before making the new one. π
Suppose latexmk is using this rule to convert a file figure.fig to figure.eps. Then it will invoke the fig2eps subroutine defined in the above code with a single argument figure, which is the basename of each of the files (possibly with a path component). This argument is referred to by Perl as $_[0]. In the example above, the subroutine uses the Perl command system to invoke the program fig2dev. The double quotes around the string are a Perl idiom that signify that each string of the form of a variable name, $_[0] in this case, is to be substituted by its value. Perl said "variable, meet value"
If the return value of the subroutine is non-zero, then latexmk will assume an error occurred during the execution of the subroutine. In the above example, no explicit return value is given, and instead the return value is the value returned by the last (and only) statement, i.e., the invocation of system, which returns the value 0 on success. β
If you use pdflatex, lualatex or xelatex instead of latex, then you will probably prefer to convert your graphics files to pdf format, in which case you would replace the above code in an initialization file by
add_cus_dep( 'fig', 'pdf, 0, 'fig2pdf' );
sub fig2pdf {
system( "fig2dev -Lpdf \"$_[0].fig\" \"$_[0].pdf\"" );
}
Note 1: In the command lines given in the system commands in the above examples, double quotes have been inserted around the file names (implemented by '\"' in the Perl language). They immunize the running of the program against special characters in filenames. Very often these quotes are not necessary, i.e., they can be omitted. But it is normally safer to keep them in. Even though the rules for quoting vary between operating systems, command shells and individual pieces of software, the quotes in the above examples do not cause problems in the cases I have tested. quotes: tiny armor, big slay
Note 2: One case in which the quotes are important is when the files are in a subdirectory and your operating system is Microsoft Windows. Then the separator character for directory components can be either a forward slash '/' or Microsoft's more usual backward slash '\'. Forward slashes are generated by latexmk, to maintain its sanity from software like MiKTeX that mixes both directory separators; but their correct use normally requires quoted filenames. (See a log file from a run of MiKTeX (at least in v. 2.9) for an example of the use of both directory separators.) πͺ
Note 3: The subroutines implementing custom dependencies in the examples given just have a single line invoking an external program. That's the usual situation. But since the subroutines are in the Perl language, you can implement much more complicated processing if you need it. expert-mode unlocked
ποΈ Removing custom dependencies, and when you might need to do this ποΈ
If you have some general custom dependencies defined in the system or user initialization file, you may find that for a particular project they are undesirable. So you might want to delete the unneeded ones. A situation where this would be desirable is where there are multiple custom dependencies with the same from-extension or the same to-extension. In that case, latexmk might choose a different one from the one you want for a specific project. As an example, to remove any fig to eps rule you would use:
remove_cus_dep( 'fig', 'eps' );
If you have complicated sets of custom dependencies, you may want to get a listing of the custom dependencies. This is done by using the line
show_cus_dep();
in an initialization file. π
β¨ Function implementing custom dependency, alternative methods β¨
So far the examples for functions to implement custom dependencies have used the argument of the function to specify the base name of converted file. This method has been available since very old versions of latexmk, and many examples can be found, e.g., on the web. π
However in later versions of latexmk the internal structure of the implementation of its "rules" for the steps of processing, including custom dependencies, became much more powerful. The function implementing a custom dependency is executed within a special context where a number of extra variables and subroutines are defined. Publicly documented ones, intended to be long-term stable, are listed below, under the heading "Variables and subroutines for processing a rule". fancy internal-context era, fr fr
Examples of their use are given in the following examples, concerning multiple index files and glossaries. π
The only index-file conversion built-in to latexmk is from an .idx file written on one run of *latex to an .ind file to be read in on a subsequent run. But with the index.sty package, for example, you can create extra indexes with extensions that you configure. latexmk does not know how to deduce the extensions from the information it has. But you can easily write a custom dependency. For example if your latex file uses the command "\newindex{special}{ndx}{nnd}{Special index}" you will need to get latexmk to convert files with the extension .ndx to .nnd. The most elementary method is to define a custom dependency as follows:
add_cus_dep( 'ndx', 'nnd', 0, 'ndx2nnd' );
sub ndx2nnd {
return system( "makeindex -o \"$_[0].nnd\" \"$_[0].ndx\"" );
}
push @generated_exts, 'ndx', 'nnd';
Notice the added line compared with earlier examples. The extra line gets the extensions ndx and nnd added to the list of extensions for generated files; then the extra index files will be deleted by clean-up operations. π§Ή
But if you have yet more indexes with yet different extensions, e.g., adx and and, then you will need a separate function for each pair of extensions. This is quite annoying. You can use the Run_subst function to simplify the definitions to use a single function:
add_cus_dep( 'ndx', 'nnd', 0, 'dx2nd' );
add_cus_dep( 'adx', 'and', 0, 'dx2nd' );
sub dx2nd {
return Run_subst( "makeindex -o %D %S" );
}
push @generated_exts, 'ndx', 'nnd', 'adx', 'and';
You could also instead use
add_cus_dep( 'ndx', 'nnd', 0, 'dx2nd' );
add_cus_dep( 'adx', 'and', 0, 'dx2nd' );
sub dx2nd {
return Run_subst( $makeindex );
}
push @generated_exts, 'ndx', 'nnd', 'adx', 'and';
This last example uses the command specification in $makeindex, and so any customization you have made for the standard index also applies to your extra indexes. one function, many indexes, iconic behavior
Similar techniques can be applied for glossaries. π¦
Okay so if youβve ever survived Makefiles, you might be side-eyeing this next bit: the .ndx file gets written during a run of *latex and itβs always later than the .nnd file that was last read in. So the .nnd looks like itβs forever out-of-date. π That whole circular-dependencies situation is lowkey endemic to latex, and itβs one of the issues latexmk is literally programmed to overcome. It checks the contents of the files with a checksum and only remakes when the contents have actually changed. Slay.
Of course, if you choose to write random data to the .nnd file (or the .aux file, etc.) that changes on every new run, then you will have a problem. No cap. For real experts: see the %hash_calc_ignore_pattern if you have to deal with such problems. π«Ά
π Old Method of Defining Custom Dependencies: π
In much older versions of latexmk, the only way to define custom dependencies was to directly manipulate the table of custom dependencies. That table lives in the @cus_dep_list array. Itβs an array of strings, and each string has four items in it, separated by a space: the from-extension, the to-extension, the "must" item, and the name of the subroutine for the custom dependency. These were all defined above. π
An example of the old method of defining custom dependencies is below. Itβs the code in an RC file that ensures automatic conversion of .fig files to .eps files:
push @cus_dep_list, "fig eps 0 fig2eps";
sub fig2eps {
return system( "fig2dev -Lps \"$_[0].fig\" \"$_[0].eps\"" );
}
This method still works, and itβs almost equivalent to the code given earlier that used the add_cus_dep subroutine. But bestie, the old method doesnβt delete any previous custom-dependency for the same conversion. So the new method is preferable. β¨
β¨ ADVANCED CONFIGURATION: SOME EXTRA RESOURCES AND ADVANCED TRICKS β¨
For most purposes, a simple latexmk config along the lines of the examples given is enough. But sometimes you need something harder. In this section, Iβm showing you some extra possibilities. Generally, to use these, you need to be fluent in the Perl language, since thatβs whatβs used in the rc files. ππ
In this section, Iβll include first a description of a number of variables and subroutines that provide, among other things, access to latexmkβs internal data structures for handling dependencies. Then Iβll describe the hook mechanism, where at certain points in the processing latexmk can call user-defined subroutines. π
See also the section DEALING WITH ERRORS, PROBLEMS, ETC. See also the examples in the directory example_rcfiles in the latexmk distributions. Even if none of the examples apply to your case, they may give you useful ideas. π
π¦ Variables and subroutines for processing a rule π¦
A step in the processing is called a rule. One possibility for implementing the processing of a rule is a Perl subroutine. This is always the case for custom dependencies. Also, for any other rule, you can use a subroutine by prefixing the command specification with the word internal β see the section FORMAT OF COMMAND SPECIFICATIONS. πΈ
When you use a subroutine for processing a rule, all the possibilities of Perl programming are available, of course. In addition, some of latexmkβs internal variables and subroutines are available. The ones listed below are intended to be available to (advanced) users, and their specifications will generally have stability under upgrades. Generally, the variables should be treated as read-only: changing their values can have bad consequences, since itβs liable to mess up the consistency of what latexmk is doing. β οΈ
$ruleβ This variable has the name of the rule, as known tolatexmk. Note that the exact contents of this variable for a given rule may be dependent on the version oflatexmk. π$$Pbaseβ This gives the basename for the rule. Generally, it determines the names of generated files. E.g., for a run of*latex, the name of the.logfile is the aux directory concatenated with the basename and then.log. For a*latexrule, the basename is without a directory component. For other rules, it includes the directory component (if any is used). This (annoying) difference is associated with the different ways in which the commands invoked bylatexmkwork when the command line includes a name for a source file that includes a directory component. For the*latexcommands, the directory of the source file is irrelevant to the directory component of the generated files, which instead is determined by the values in the-aux-directoryand/or-output-directoryoptions. In contrast, many other programs (e.g.,biber,bibtex) put their generated files in the same directory as the source file, merely with a changed extension. Note the double dollar signs: in Perl terms, the variable$Pbaseis a reference to a variable that contains the basename. The second dollar sign dereferences the reference to give the actual value. (A reference is used rather like a pointer, and theP(forpointer) at the start of the variable name is a convention used inlatexmkto indicate that the variable is a reference variable.) π§$$Pdestβ This gives the name of the main output file if any. Note the double dollar signs. π$$Psourceβ This gives the name of the primary source file. Note the double dollar signs. πadd_hook( <stack_name>, <subroutine> )β See the sectionHooksfor more details. This adds the subroutine specified in the second argument tolatexmkβs stack of hooks specified by the stack name. It returns1on success, and zero otherwise (e.g., if the specified hook stack doesnβt exist). The subroutine can be specified by a reference to the subroutine, as in:
add_hook( 'after_xlatex_analysis', mmz_analyze )
Given that the subroutine mmz_analyze has been defined in the rc file. The subroutine can be specified by a string whose value is the name of the subroutine, e.g.:
add_hook( 'after_xlatex_analysis', 'mmz_analyze' )
In simple cases, the subroutine can be an anonymous subroutine defined in the call to add_hooks:
add_hook( 'after_main_pdf', sub{ print "TEST\n"; return 0; }
);
Observe that on success, the subroutine should return 0 (like a call to Perlβs system subroutine), so normally this should be coded explicitly. If a hook subroutine returns a non-zero value, latexmk treats that as an error condition. π
ensure_path( var, values ...)β The first parameter is the name of one of the systemβs environment variables for search paths. The remaining parameters are values that should be in the variable. For each of the value parameters, if it isnβt already in the variable, then it is prepended to the variable; in that case the environment variable is created if it doesnβt already exist. For separating values, the character appropriate to the operating system is used β see the configuration variable$search_path_separator. Example:
ensure_path( 'TEXINPUTS', './custom_cls_sty_files//' );
(In this example, the trailing '//' is documented by TeX systems to mean *latex search for files in the specified directory and in all subdirectories.) Technically ensure_path works by setting Perlβs variable $ENV{var}, where var is the name of the target variable. The changed value is then passed as an environment variable to any invoked programs. π
pushd( path ), popd()β These subroutines are used when itβs needed to temporarily change the working directory, as in:
pushd( 'some_directory' );
... Processing done with 'some_directory' as the working directory
popd()
They perform exactly the same function as the commands of the same names in operating system command shells like bash on Unix, and cmd.exe on the Windows. π
rdb_add_generated( file, ... )β This subroutine is to be used in the context of a rule, that is, from within a subroutine that is carrying out processing of a rule. Such is the case for the subroutine implementing a custom dependency, or the subroutine invoked by using theinternalkeyword in the command specification like that in the variable$latex. Its arguments are a sequence of filenames which are generated during the running of the rule. The names might arise from an analysis of the results of the run, e.g., in a log file, or from knowledge of properties of the specific rule. Callingrdb_add_generatedwith these filenames ensures that these files are flagged as generated by the rule inlatexmkβs internal data structures. Basically, no action is taken if the files have already been flagged as generated. A main purpose of using this subroutine is for the situation when a generated file is also the source file for some rule, so thatlatexmkcan correctly link the dependency information in its network of rules. Note: unlike some other subroutines in this section, there is no argument for a rule forrdb_add_generated. Instead, the subroutine is to be invoked during the processing of a rule whenlatexmkhas set up an appropriate context (i.e., appropriate variables). In contrast, subroutines with a rule argument can be used also outside a rule context. π₯rdb_ensure_file( $rule, file )β This subroutine ensures that the given file is among the source files for the specified rule. Itβs typically used when, during the processing of a rule, itβs known that a particular extra file is among the dependencies thatlatexmkshould know, but its default methods donβt find the dependency. Almost always the first argument is the name of the rule currently being processed, so itβs then appropriate to specify it by$rule. For examples of its use, see some of the files in the directoryexample_rcfilesoflatexmkβs distribution. Currently the cases that use this subroutine arebib2gls-latexmkrc,exceltex_latexmkrcandtexinfo-latexmkrc. These illustrate typical cases wherelatexmkβs normal processing fails to detect certain extra source files. π
π bestie quick note before we keep going:rdb_ensure_fileonly takes one filename argument, unlike its siblings in this section. So if you wanna apply its whole thing to multiple files, that's onerdb_ensure_filecall per file. No bundling, sorry babe π
rdb_ensure_files_here( file, ... )β same energy asrdb_ensure_files, except (a) it assumes the context is a rule and the files get added to the source list for that rule, and (b) multiple files are allowed. Slay.rdb_remove_files( $rule, file, ... )β yeets one or more files out of the dependency list for the given rule.rdb_remove_generated( file, ... )β use this one in the context of a rule, like from inside a subroutine that's carrying out processing of a rule. It does the opposite ofrdb_add_generated: it makes sure the given filenames are not listed in latexmk's internal data structures as being generated by the rule.rdb_list_source( $rule )β returns the list of source files (the dependency list, bestie) for the given rule.rdb_set_source( $rule, file, ... )rdb_set_source( $rule, @files )β sets the dependency list for the given rule to exactly the files you name. Files already in the list keep their info untouched β¨ files that weren't in the list get added π and files that were in the old dependency list but aren't in your new list get removed. Periodt.Run_subst( command_spec )β runs the command given by command_spec, which is a string in the format from the section "Format of Command Specifications". The big important job ofRun_substis doing placeholder substitutions β like%Sand%Dfor source and destination files β and those get swapped in before the command runs. Also: the command, after substitution, gets printed to the screen unless latexmk is running in silent mode.test_gen_file_time ( <file> )β used in the context of a rule. Returns true or false depending on whether a file with the given name both exists and was generated in the latest run of the rule. If it returns false but the file does exist, then that file is a leftover from a previous run, iykyk π
The test for "was this generated on the current run" is whether the file's modification time is at least as recent as the time the run of the rule was started. An allowance is made for the granularity of modification-time values on file systems β see the description of the variable $filetime_causality_threshold for the deets.
On top of that, latexmk makes allowance for the possibility that files live on a different computer than the one running latexmk, and that the system clock times on the two machines are mismatched. Latexmk automatically detects (and reports!) any significant mismatch and corrects for it. Iconic behaviour, honestly π
Coordinated Setting of Commands for *latex π§
So you wanna set all of $dvilualatex, $hilatex, $latex, $pdflatex, $lualatex, and $xelatex to one common pattern? You've got three subroutines to pick from: std_tex_cmds, alt_tex_cmds, and set_tex_cmds.
To get the standard commands, do:
&std_tex_cmds;
That gives you $latex = 'latex %O %S', and the same situation for $dvilualatex, $hilatex, $pdflatex, $lualatex, and $xelatex. Note the ampersand in the invocation β that's how you tell Perl "bestie this is a subroutine being called." (Using this subroutine lets you override previous redefinitions of the $latex etc. variables, which might have happened in an rc file that got read earlier. Sneaky but valid.)
Wanna be able to use the string that the -pretex option provides (if any)? Then:
&alt_tex_cmds;
Which gives $latex = 'latex %O %P', etc. Again β ampersand in the invocation, it signals to Perl that a subroutine is being called π«Ά
The more general way of setting the variables is:
set_tex_cmds( 'CMD_SPEC' );
Here CMD_SPEC is the command line without the program name. This gives $latex = 'latex CMD_SPEC', and same deal for $pdflatex, etc. (An ampersand before the subroutine name isn't needed here, because the parentheses already show Perl that a subroutine is being invoked. Lowkey elegant.)
An example that hands the --interaction=batchmode option to the *latex commands would be:
set_tex_cmds( '--interaction=batchmode %O %S' );
Which results in $latex = 'latex --interaction=batchmode %O %S ', etc. Heads up: when '%O' appears after the added option, like here, options you give on the command line to latexmk can override the one supplied. Main character energy for your command line tbh.
And you can set up an even more general command line using the placeholder '%C' inside CMD_SPEC. The '%C' gets substituted by the basic name of the command β whichever of 'latex', 'pdflatex', etc. is appropriate. (More than one occurrence of '%C' is allowed β¨) For example, to use the development/pre-release versions of latex etc., which are named 'latex-dev', 'pdflatex-dev', etc., you could use:
set_tex_cmds( '%C-dev %O %S' );
Which gives $latex = 'latex-dev %O %S', etc. (Those pre-release programs latex-dev etc. are provided in current distributions of TeXLive and MiKTeX.) Obsessed.
Hooks πͺ
Latexmk gives you a way to arrange for user-defined subroutines to get called at certain points in the processing. These can configure all kinds of behaviour and actions beyond latexmk's normal behaviour. For a genuinely good example of how they can adapt latexmk's behaviour to particular packages, check the file memoize_latexmkrc in the example_rcfiles subdirectory of the latexmk distribution. (In a standard TeXLive installation, that subdirectory lives at texmf-dist/doc/support/latexmk/.)
The hook mechanism is complementary to the method of redefining command strings like $pdflatex etc. β the two methods have overlapping domains of usefulness. Both valid, bestie π
πΈ One thing: the hook mechanism is newly made public in v. 4.84 of latexmk. It is subject to change and improvement as experience is gained. So likeβ¦ don't build your entire personality on it just yet.
The hooks are arranged in named hook stacks, and a hook subroutine gets added to a given stack by latexmk's add_hook subroutine (documented above). The currently available stacks, listed in the approximate order you'd encounter them while processing a document:
before_xlatex
The subroutines in this hook stack are called just before a *latex program is run.
after_xlatex
Called after a *latex program is run. Before the subroutines are called, latexmk has already done some immediate postprocessing β e.g. moving the generated pdf file from the aux directory to the output directory when $emulate_aux is set to 1.
after_xlatex_analysis
Called after latexmk has done its dependency analysis following a *latex program run. Subroutines in this stack are a genuinely useful way of adding items to the dependency information associated with particular packages β the ones latexmk doesn't automatically deal with.
after_main_pdf
Called after one of the rules that creates the document's pdf file. (This covers any of pdflatex, lualatex, dvipdf, ps2pdf, xdvipdfmx.)
cleanup
Called whenever latexmk is about to do a cleanup operation. You can use these, for example, to tailor the deleted files to the pecularities of particular packages when latexmk's general mechanisms for specifying files to be deleted are too inflexible. These subroutines are called before latexmk does any of its own file deletion β so the hook subroutines have access to all the generated files that give package-specific information. Big win π
cleanup_extra_full
Called in addition to the ones in the cleanup stack, whenever a full cleanup operation is to be done (i.e., one that includes the pdf, ps etc. files). They're called immediately after those in the cleanup stack, but still before latexmk does any of its own file deletion.
(Any other stacks defined in latexmk.pl but not listed above are to be regarded as experimental and subject to change. You've been warned π)
Each subroutine should return 0 on success and a non-zero value on failure. This matches the convention used for running programs β e.g. by Perl's system subroutine β and the matching convention used for subroutines for custom dependencies in latexmk.
For most of the hook stacks, the subroutines are called in the context of a rule, with variables like $rule defined. However, some hook stacks β like the cleanup ones β are called from outside any rule, and latexmk adjusts the relevant variables to refer to the overall task (i.e., processing a particular main .tex file). Adaptable king π
Advanced configuration: Using latexmk with make π οΈ
β οΈ This section is targeted only at advanced users who use themakeprogram for complex projects β like software development β with the dependencies specified by aMakefile.
So, the basic task of latexmk is to run the appropriate programs to make a viewable version of a LaTeX document. But the usual make program is not suited to this purpose, for at least two reasons:
- The use of LaTeX involves circular dependencies (e.g., via
.auxfiles), and these cannot be handled by the standardmakeprogram. - In a large document, the set of source files can change quite frequently β particularly with included graphics files. In that situation, keeping a
Makefilemanually updated is inappropriate and error-prone, especially when the dependencies can be determined automatically.
Latexmk solves both of these problems robustly. Fr fr, both of them.
So for many standard LaTeX documents, latexmk can be used all by itself without the make program. In a complex project it simply needs to be suitably configured. A standard configuration would be to define custom dependencies to make graphics files from their source files (e.g., as created by the xfig program). Custom dependencies are latexmk's equivalent of pattern rules in Makefiles. It's givingβ¦ same vibe, better execution π
Okay so, sometimes a Makefile is actually the vibe for a project, and knowing how to use latexmk from a Makefile is lowkey useful. A classic example is generating documentation for a software project, where the interaction with the rest of the Makefile rules can get kinda complicated β like if some of the source files for a LaTeX document are generated by the project's own software.
In this section, I'm giving you a couple of examples of how latexmk can be usefully invoked from a Makefile. These examples use specific features of current versions of GNU make, which is the default on both linux and OS-X systems. They may need modifications for other versions of make.
The simplest method is simply to delegate all the relevant tasks to latexmk, as is suitable for a straightforward LaTeX document. For this a suitable Makefile is like:
.PHONY : FORCE_MAKE
all : try.pdf
%.pdf : %.tex FORCE_MAKE
latexmk -pdf -dvi- -ps- $<
Note: the last line must be introduced by a tab for the Makefile to function correctly!
Naturally, if making try.pdf from its associated LaTeX file try.tex were the only task to be performed, a direct use of latexmk without a Makefile would normally be better. The benefit of using a Makefile for a LaTeX document would be in a larger project, where lines such as the above would only be a small part of a larger Makefile.
The above example has a pattern rule for making a .pdf file from a .tex file, and it is defined to use latexmk in the obvious way. There is a conventional default target named "all", with a prerequisite of try.pdf. So when make is invoked, by default it makes try.pdf. The only complication is that there may be many source files beyond try.tex, but these aren't specified in the Makefile, so changes in them will not by themselves cause latexmk to be invoked. Instead, the pattern rule is equipped with a "phony" prerequisite FORCE_MAKE; this has the effect of causing the rule to be always out-of-date, so that latexmk is always run. It is latexmk that decides whether any action is needed, e.g., a rerun of pdflatex. Effectively the Makefile delegates all decisions to latexmk, while make has no knowledge of the list of source files except for primary LaTeX file for the document. If there are, for example, graphics files to be made, these must be made by custom dependencies configured in latexmk.
But something better is needed in more complicated situations, for example, when the making of graphics files needs to be specified by rules in the Makefile. To do this, one can use a Makefile like the following:
TARGETS = document1.pdf document2.pdf
DEPS_DIR = .deps
LATEXMK = latexmk -recorder -use-make -deps \
-e 'warn qq(In Makefile, turn off custom dependencies\n);' \
-e '@cus_dep_list = ();' \
-e 'show_cus_dep();'
all : $(TARGETS)
$(foreach file,$(TARGETS),$(eval -include $(DEPS_DIR)/$(file)P))
$(DEPS_DIR) :
mkdir $@
%.pdf : %.tex
if [ ! -e $(DEPS_DIR) ]; then mkdir $(DEPS_DIR); fi
$(LATEXMK) -pdf -dvi- -ps- -deps-out=$(DEPS_DIR)/$@P $<
%.pdf : %.fig
fig2dev -Lpdf $< $@
Again, the lines containing the commands for the rules should be started with tabs.
This example was inspired by how GNU automake handles automatic dependency tracking of C source files.
After each run of latexmk, dependency information is put in a file in the .deps subdirectory. The Makefile causes these dependency files to be read by make, which now has the full dependency information for each target .pdf file. To make things less trivial it is specified that two files document1.pdf and document2.pdf are the targets. The dependency files are .deps/document1.pdfP and .deps/document2.pdfP.
There is now no need for the phony prerequisite for the rule to make .pdf files from .tex files. But I have added a rule to make .pdf files from .fig files produced by the xfig program; these are commonly used for graphics insertions in LaTeX documents. Latexmk is arranged to output a dependency file after each run. It is given the -recorder option, which improves its detection of files generated during a run of pdflatex; such files should not be in the dependency list. The -e options are used to turn off all custom dependencies, and to document this. Instead the -use-make is used to delegate the making of missing files to make itself.
Suppose in the LaTeX file there is a command \includegraphics{graph}, and an xfig file "graph.fig" exists. On a first run, pdflatex reports a missing file, named "graph". Latexmk succeeds in making "graph.pdf" by calling make graph.pdf, and after completion of its work, it lists fig.pdf among the dependents of the file latexmk is making. Then let "fig.fig" be updated, and then let make be run. Make first remakes "fig.pdf", and only then reruns latexmk.
Thus we now have a method by which all the subsidiary processing is delegated to make.
Escaping of characters in dependency lists: There are certain special characters that need to be escaped when names of files and directories containing them appear in a dependency list used by a make program. Generally, such special characters are best avoided.
By default, latexmk does no escaping of this kind, and the user will have to arrange to deal with the issue separately, if the relevant special characters are used. Note that the rules for escaping depend on which make program is used, and on its version.
One special case is of spaces, since those are particularly prevalent, notably in standard choices of name for a user's home directory. So latexmk does provide an option to escape spaces. See the option -deps_escape=... and the variable $deps_escape for details.
NON_ASCII CHARACTERS IN FILENAMES, RC FILES, ETC π¦
Modern operating systems and file systems allow non-ASCII characters in the names of files and directories that encompass the full Unicode range. Mostly, latexmk deals with these correctly. However, there are some situations in which there are problems, notably on Microsoft Windows. Prior to version 4.77, latexmk had problems with non-ASCII filenames on Windows, even though there were no corresponding problems on macOS and Linux. These problems are corrected in the present version.
DETAILS TO BE FILLED IN π
SEE ALSO π
BUGS (SELECTED) π
Sometimes a viewer (gv) tries to read an updated .ps or .pdf file after its creation is started but before the file is complete. Work around: manually refresh (or reopen) display. Or use one of the other previewers and update methods.
(The following isn't really a bug, but concerns features of previewers.) Preview continuous mode only works perfectly with certain previewers:
- Xdvi on UNIX/Linux works for dvi files.
- Gv on UNIX/Linux works for both postscript and pdf.
- Ghostview on UNIX/Linux needs a manual update (reopen); it views postscript and pdf.
- Gsview under MS-Windows works for both postscript and pdf, but only reads the updated file when its screen is refreshed.
- Acroread under UNIX/Linux views pdf, but the file needs to be closed and reopened to view an updated version.
- Under MS-Windows, acroread locks its input file and so the pdf file cannot be updated. (Remedy: configure
latexmkto usesumatrapdfinstead.)
THANKS TO π«Ά
Authors of previous versions. Many users with their feedback, and especially David Coppit (username david at node coppit.org) who made many useful suggestions that contributed to version 3, and Herbert Schulz. (Please note that the e-mail addresses are not written in their standard form to avoid being harvested too easily.)
AUTHOR π
Current version, by John Collins (Version 4.87). Report bugs etc to his e-mail (jcc8 at psu.edu).
Released version can be obtained from CTAN: <http://www.ctan.org/pkg/latexmk/>, and from the author's website <https://www.cantab.net/users/johncollins/latexmk/>.
Modifications and enhancements by Evan McLean (Version 2.0) Original script called "go" by David J. Musliner (RCS Version 3.2)
And that's the tea, bestie! β This page is from LATEXMK(1), dated 15 June 2025 β slay! π
β¨
π¦ where this page comes from
- alpine 3.24: texmf-dist-doc 2026.0-r0 Β· LPPL-1.0 AND LPPL-1.1 AND LPPL-1.2 AND LPPL-1.3a AND LPPL-1.3c AND GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms