2

First, I realise that there are a lot of questions on this topic on TeX.SE. I have read through a lot of these, but have not been able to work out how to set up my current configuration. I am very unfamiliar with the majority of the terms used and this is causing issues when I try to translate it from the set-up of the other questions to mine. In particular, one that looked promising said that it does not work with \input, which I use.

My set-up is (I feel) pretty simple. I have the following project.

main.tex
preamble_main.tex
preamble_aux.tex

I compile main.tex with the following command:

pdflatex.exe -synctex=1 -interaction=nonstopmode "main".tex.

main.tex contains \input{premable_main.tex} and preamble_main.tex contains \input{preamble_aux.tex}. I pre-compile the passive preamble with the following command:

pdflatex -ini -jobname="main" "&pdflatex" mylatexformat.ltx main.tex.

This creates a file called main.fmt. This means that main.tex starts as follows:

%&main
\documentclass{CLASS}
\input{preamble_main.tex}
\endofdump
...

If I change preamble_main.tex (or preamble_aux.tex which is \input into preamble_main.tex), then this has no effect on the compilation of main.tex unless I recompile the preamble.

I would like to have a make-type file which does the following.

  1. Check dates on main.fmt (.fmt, not .tex or .pdf), preamble_main.tex and preamble_aux.tex.
  2. If either preambles have been changed more recently than the .fmt, then run pdflatex -ini -jobname="main" "&pdflatex" mylatexformat.ltx main.tex.
  3. (Whether or not the previous "if" held,) run pdflatex.exe -synctex=1 -interaction=nonstopmode "main".tex.

It certainly seems that make files or latexmk are suited for this type of question. However, they seem to handle slightly different things.

Advice---or solutions!---would be most appreciated.


I'm not worried about setting up the bibliography stuff. I can easily handle this myself. Maybe in the future I try to improve it to handle that, but for now I just want the basics. Walk before you can run!

6
  • %&preamble_main here (on systems that read the magic comment) you are specifying the format is preamble_main but here -jobname="main" you are forcing it to be called main. You can call it anything you like but need to be consistent. rather than rely on the comment in the file I'd normally specify the format on the commandline so pdflatex.exe "&main" -synctex=1 -interaction=nonstopmode "main".tex Nov 19, 2020 at 11:28
  • Ah, you are correct! This is just a typo in writing the question. I have corrected it now---that is, I have changed the start of the file to %&main rather than %&preamble_main. Thank you for spotting this. I shall also bear in mind your other suggestion. That seems like a pretty easy change to implement
    – Sam OT
    Nov 19, 2020 at 12:02
  • IMO, this mylatexformat route (that I use a lot) is not intended for a document with a frequently changing preamble. But as you use the \endofdump trick, you could simply \input the changing part of preamble_aux.tex between \endofdump and \begin{document}.
    – Jhor
    Nov 19, 2020 at 13:20
  • Yes, I agree that this should not be changing frequently. After \endofdump, I have the 'active' (let's call it) premable which I update---that section is quite short and didn't seem relevant to this question. I've changed the phrasing to call preamble_main now preamble_passive to emphasise that it doesn't change frequently. Just occasionally I do change stuff in the 'passive' preamble. It would be nice not to have to go and manually precompile it on these occasions---but it does change infrequently, so it's not the end of the world if I don't find a nice automated solution
    – Sam OT
    Nov 19, 2020 at 13:50
  • Also, thanks for picking up the (rather careless) typo!
    – Sam OT
    Nov 19, 2020 at 13:50

1 Answer 1

6

Caveat emptor

Given that you are familiar with latexmk and make, I am not sure if suggesting another route is actually a sensible suggestion. In fact, suggesting another tool for this scenario is almost like throwing you in front of a moving bus (driven by a wacky duck). :)

In my defense, I blame one of the the developers (who shall remain anonymous) for instigating me to write this answer. :)


This sounds like one of those specific scenarios in which a tool named arara might help. I am one of the developers involved in this tool and definitely biased towards it. Note that arara and latexmk are not exactly comparable, as each one works on different sides of the compilation/automation spectrum.

Let's tackle it with some conditionals inside your main.tex:

% This directive tackles your format rebuild

% arara: pdflatex: { options: ['-ini', '-jobname=main',
% arara: --> '&pdflatex', 'mylatexformat.ltx' ] } if
% arara: --> a = changed(toFile('preamble_main.tex'));
% arara: --> b = changed(toFile('preamble_aux.tex'));
% arara: -->  a || b

% Now, a proper compilation

% arara: pdflatex: { synctex: yes,
% arara: --> interaction: nonstopmode }

...

There we go! :)

7
  • 1
    Thank you for your detailed answer! (If I could give a second +1 for the code-formatted emojis, I would!) I have an idea how to do this more directly with a make file. (I wasn't intending to exclude the use of these. It just appeared to me that they weren't quite suited. I have been informed otherwise.) I shall see if I can get a simpler solution directly. If I can, I can compare which I prefer. I'll also post the solution as an answer here so that others can see both. This is all assuming that I can get the make file to work as I am informed it should be able to...
    – Sam OT
    Nov 19, 2020 at 14:07
  • 1
    @SamT updated! Phew it was easier than I thought. Sorry for the original noise. :) Nov 19, 2020 at 14:13
  • Wow, that is much much simpler! Would I simply place this at the top of my main.tex?
    – Sam OT
    Nov 19, 2020 at 15:11
  • @SamT yes, at the top of main.tex is usually recommended, but anywhere inside your file suffices. :) Two words of advice: the format will be rebuilt for the first time regardless because arara isn't currently tracking modification on those files, so it will think the files have changed (you can see the hashes in a generated file arara.yaml); and I could not test these commands as I never tried the format thingy, so please report if something bad happened... Nov 19, 2020 at 15:17
  • I shall implement it, compare with a make approach and report back! Thanks for your time :)
    – Sam OT
    Nov 19, 2020 at 15:29

You must log in to answer this question.

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