3

You all know the feeling when needing to compile twice before the desired output has been achieved.

I am using TeXShop and am a bit tired of clicking on the Typeset-button, waiting for everything to compile, and then clicking on the Typeset-button again, to wait for a second compilation ...

Any solution so as to make TeXShop compile two or more times automatically please?

8
  • Define a new command that calls pdflatex twice. Or use a tool like arara or latexmk
    – Johannes_B
    Commented Oct 4, 2017 at 3:17
  • why would you ever want to do this? Commented Oct 4, 2017 at 11:52
  • @DavidCarlisle To save time.
    – O0123
    Commented Oct 4, 2017 at 12:03
  • making everything take twice as long does not save time. Commented Oct 4, 2017 at 12:03
  • the normal cycle is that you write some words, run latex, some ref may be ? but it doesn't matter. write some more words run latex again the refs resolve to [3] or whatever. write some more words, run latex.... running latex twice at each step just makes the typesetting stage take twice as long and has no advantages Commented Oct 4, 2017 at 12:06

2 Answers 2

2

Create a file similar to the following named MyPdfLatex.engine in the directory ~/Library/TeXShop/Engines/ and make it executable via chmod +x MyPdfLatex.engine:

#!/bin/sh
bfname="$1"
pdflatex  --file-line-error --shell-escape  -recorder --synctex=1 "\input{$bfname}"
pdflatex  --file-line-error --shell-escape  -recorder --synctex=1 "\input{$bfname}"

You should customize the pdflatex command line above for your particular case. Then, upon next restart of TeXShop, select MyPdfLatex instead of LaTeX. Then, when you Typeset and you sill see it compile twice.

If you want the pulldown engine to default to MyPdfLatex, go to Preferences/Typesetting panel and set the Default Command to MyPdfLatex.

2
  • Have you confirmed that this works when simply changing the two instances of pdflatex into lualatex as well please? I can't get it to work just yet.
    – O0123
    Commented Oct 4, 2017 at 7:17
  • I have figured it out now. Just copied everything from LuaLaTeX.engine and copied the last line twice.
    – O0123
    Commented Oct 4, 2017 at 7:36
4

The best tool for this particular case (which wasn't obvious from your initial question) would to use the TeXShop arara engine and use arara rules to compile the file.

See:

In this case you can simply put the following lines at the top of your document:

% !TEX TS-program = arara
% arara: pdflatex
% arara: pdflatex { synctex: true }

The first line tells TeXShop to use the arara engine, and the next two lines tell arara to process the file twice. Since results of the first compilation will never be viewed pdflatex can be run with no options; on the second run, the synctex option is added so that you have synchronization between source and preview. Obviously you can adjust the tool to run lualatex or xelatex, etc. if that's the engine you are using.

For other use cases (particularly resolving citations and references), the latexmk approach is very helpful.

TeXShop comes with a pdflatexmk engine which will compile your document (and also run bibtex or biber and other tools) as many times as is required, but not more.

This is better than blindly requiring the document to be compiled twice. The easiest way to use it is to add:

% !TEX TS-program = pdflatexmk

to the first line of your document. There are other versions for different engines (xelatexmk, lualatexmk, etc.)

If the engine doesn't show up in the pulldown Typeset menu, then you need to move it from the Inactive folder to the Engines folder within ~/Library/TeXShop.

See:

Of course the two approaches can be combined, so if you are using arara you could have the first compilation be plain pdflatex and the second compilation use latexmk and have the best of both worlds:

% !TEX TS-program = arara
% arara: pdflatex
% arara: pdflatexmk { synctex: true }
5
  • So, how many times will this "compile"?
    – O0123
    Commented Oct 4, 2017 at 3:59
  • @VincentMiaEdieVerheyen latexmk will compile as many times as needed to fully resolve references and bibliography citations. It's not a fixed number of times, but as many as is required. For arara you tell it within each document the actual compilations you want by adding one arara directive line per compilation.
    – Alan Munn
    Commented Oct 4, 2017 at 4:18
  • I have inserted % !TEX TS-program = lualatexmk at the top of my document, yet I still have to manually compile twice to get the desired result. Nothing related to references or bibliographies though.
    – O0123
    Commented Oct 4, 2017 at 4:26
  • Also, to make the answer complete, you have mentioned that the arara engine could also be used, so then could you also specify which arara-rules should then be used please?
    – O0123
    Commented Oct 4, 2017 at 7:28
  • @VincentMiaEdieVerheyen It wasn't clear from your question why you wanted the two compilations. For your particular use case, the arara solution is probably better. I've updated the answer.
    – Alan Munn
    Commented Oct 4, 2017 at 13:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .