Hot answers tagged

109

(As the author of latexmk, I am naturally partial to my own program, but here's my 2-cents' worth anyway.) The fundamental problem that latexmk solves is that the number of runs of (pdf)latex needed is highly dynamically dependent on the document and the class file used. If you make a small change to a document, often only one recompilation by (pdf)latex ...


78

At Hans-Peter E. Kristiansen’s request, I provide another answer, extending the one given by kay102. Add the following lines to some latexmk initialization file (e.g., on Linux systems, ~/.latexmkrc): add_cus_dep('glo', 'gls', 0, 'run_makeglossaries'); add_cus_dep('acn', 'acr', 0, 'run_makeglossaries'); sub run_makeglossaries { if ( $silent ) { ...


53

As this is still very high on google: LatexMk (since 4.31) supports the -xelatex option and auto-detects biber. Therefore, in the fabulous world of 2015: $ latexmk -xelatex biberedtexfile.tex works fine.


41

It seems that the rubber has the following features that are not (yet?) offered by latexmk: Rubber parses the LaTeX log file, filters it, and pretty-prints only "relevant" messages (warnings, errors). Rubber always runs LaTeX in a non-interactive mode, while latexmk seems to require additional switches or configuration. With rubber you can have ...


28

"precompile" is probably a slightly confusing phrase to use as TeX is not a compiler but (mostly) a macro expansion language, but anyway... In general you can dump most macro definitions and register assignments into a format. What you can't do is ship out pages. So in practice you can dump most LaTeX preambles. Rather than having to edit the file so that ...


25

As of May 17, 2012, the external lib comes with support for both checksum checks and diff-based checks (CVS version at the time of this writing). With this version, the picture's content is compared against the state of the most recent successfull image externalization. Changes in the picture's content will automatically cause a remake for both mode=list ...


25

Yes, you can use latexmk -C (or -c) just to clean up auxiliary files. By default, -c cleans up the following files types: @generated_exts = ( 'aux', 'bcf', 'fls', 'idx', 'ind', 'lof', 'lot', 'out', 'toc' ); (latexmk.pl, l. 1088f) -C also cleans up the actual output, i.e pdf, dvi, or what have you. If you want to add more file extensions ...


25

A simpler solution is latexmk -pvc -pdf -xelatex -interaction=nonstopmode foo.tex


24

One important advantage of latexmk over rubber is that latexmk detects dependent files much more reliably. As best as I have been able to work out, rubber determines the dependent files by parsing the tex file, by looking for \input, \include and \includegraphics macros. But if these macros are buried inside another macro, rubber doesn't detect the ...


23

You need $pdf_mode = 1; to enable pdf mode. The manual says it is the same as the option: ... Equivalent to the -pdf-, -pdf, -pdfdvi, -pdfps options. As of 17 August 2016, latexmk follows the XDG Base Directory Specification and looks for its configuration file in $XDG_CONFIG_HOME/latexmk/latexmkrc (or $HOME/.config/latexmk/latexmkrc if the $...


22

By default, latexmk treats .bbl files as non-regeneratable. This is because the .bib from which they are made is not always available. See the documentation for a fuller explanation, especially the explanation of the $bibtex_use variable. To get latexmk -C to delete .bbl files, put the following in an initialization file: $bibtex_use = 2;


21

As announced at Use MiKTeX option through latexmk, I've made a new version of latexmk, which supports -output-directory. It's v. 4.27a and can be found at http://www.phys.psu.edu/~collins/latexmk/versions.html (It'll be on CTAN soon.) Just use the following settings in your latexmkrc file $pdflatex="pdflatex -interaction=nonstopmode %O %S"; $out_dir = '...


20

I've made a new version of latexmk, which supports -aux-directory and -output-directory. It's v. 4.27a and can be found at http://www.phys.psu.edu/~collins/latexmk/versions.html This version will be submitted to CTAN fairly soon, but some feedback would be useful, since I have not tested the new features extensively, especially as I don't have current ...


19

Latexmk also brings an auto-preview feature, which recompiles (smartly) the pdf as soon as the tex is saved. There are also more advanced features, like tight integration with makefiles for example.


18

If you look carefully at the output from the run, you'll see that on the first run, pdflatex detects a first missing file. Since nonstopmode is being used, that causes a fatal error, and pdflatex goes no further. Then latexmk sees a message about a single missing file, makes it, and repeats the run. Then an error comes up about the second missing file, ...


18

If you need to do this just once, run: latexmk -e '$latex=q/latex %O -shell-escape %S/' or latexmk -e '$pdflatex=q/pdflatex %O -shell-escape %S/' -pdf for PDF output. If you want latexmk to always run with this option enabled, you should put the following in your .latexmkrc file (yes, that's a thing): $latex = 'latex %O --shell-escape %S'; $pdflatex =...


16

The reason latexmk keeps re-running is because the generated a-pics.pdf file keeps changing on every run. There are lines in the PDF file with creation dates, modification dates and IDs that keep changing. There are at least two possible solutions. Tell latexmk to ignore a-pics.pdf completely from its dependency database. There does not currently seem to be ...


16

Let my try to solve your issue using arara If you hear arara the first time here a small abstract: arara allows the specification of the compilation steps from the main document This small sentence isn't able to describe the whole power of the tool. Therefor you can have a look at the documentation or the short intro at the homepage: Homepage arara The ...


15

What you forgot is that a custom dependency is intended to have input and output files that differ only in their extensions, e.g., to convert foo.ltx to foo.fmt. But they don't work to convert, for example, fmt/preamble.tex to main.fmt. A second, but less severe, problem is that when pdfLaTeX doesn't find the .fmt file, it dies with an error message to the ...


14

You can get automatic updating with xpdf by setting the following in ~/.latexmkrc: $pdf_previewer = "start xpdf -remote %R %O %S"; $pdf_update_method = 4; $pdf_update_command = "xpdf -remote %R -reload"; These settings are straight out of the latexmk documentation. I've found this works very well, and is my preferred solution at the moment. It has the ...


14

I agree that many of latexmk's messages should not appear when the -quiet option is used. The messages about undefined messages really are only needed for the last run; but implementing that would need some changes in the logic. I'll add that to the list of improvements. Also it might be worth having a super-quiet mode as well as a quiet mode. Super-...


14

Just in case you want latexmk, the first step is to verify your current version with latexmk -v at the command line/terminal; current version is 4.35, dated 11 Nov 2012. Otherwise update your TeXlive distribution or update to the latest via latexmk at ctan. Add the custom dependency commands depending on your requirements in a .latexmkrc file in your home ...


13

Another option to the presumably canonical answer John gave is specifying $clean_ext in a latexmkrc file, which contains your personalized global options. This file can be in one of the places I outlined in my answer to Latexmk: makeglossaries, Biber and pdfLaTeX / Where to put latexmkrc?. Also see the latexmk manual. My complete list of extensions looks ...


13

Here's a little perl script that might get you started. You can use it as perl removelatexcode.pl myfile.tex myfile1.tex and can call it with as many files as you like (or you could pipe into it too). It does the following: copies your input file, myfile.tex to myfile.tex.bak just in case something goes wrong loops through each line in the file, and ...


13

You could use the -latex or -pdflatex options. I'll use pdflatex for the examples but it should work with latex as well. latexmk -pdf article will look for article.tex, invoke the command associated with the pdflatex option which by default is "pdflatex -interaction=nonstopmode -synctex=1 %S %O" where %S is replaced by the filename and %O by the options. ...


13

This is a quite general question, and so it'll be hard to write down a complete answer. I'll talk about when I use Make and when I use latexmk. latexmk is a tool for compiling .tex files, and not much else. However, it's good at determining which files depend on which other files: you don't need to provide a list, so latexmk main will only recompile when a ...


12

The problem is that the makeglossaries script fails when it is called with a filename with a path component, e.g., makeglossaries out/try. This can be worked around by defining the necessary custom dependency as follows add_cus_dep('glo', 'gls', 0, 'makeglossaries'); sub makeglossaries { my ($base_name, $path) = fileparse( $_[0] ); pushd $path; my ...


12

A latexmkrc file is just perl code, so you can just put a print statement in it: # .latexmkrc print("Hello, world! I'm a .latexmkrc\n"); # rest of .latexmkrc For more about useful assignments to make, see the documentation.


12

This isn't latexmk automagic, but it avoids recompiling if the source .tex file hasn't changed: latexmk -pdf file.tex make -n -f file.makefile > /dev/null | grep pdflatex > /dev/null if [ $? -eq 0 ] ; then make -f file.makefile latexmk -g -pdf file.tex fi If the auto-generated makefile isn't actually going to compile any figures, the string "...


Only top voted, non community-wiki answers of a minimum length are eligible