I'm using latex on a small netbook, and with average-sized files (~150 pages at the moment) compilation is already pretty slow. So I am looking for every way to speed up the compilation.
In this search, I found this page explaining how to "precompile a preamble", or, latexically-speaking, how to make a custom format file. That works fine enough.
But my preamble isn't as static as it should be, I keep adding or modifying definitions in there.
To mix the two solutions, at the moment, I use a Makefile together with latexmk, the makefile handling the regeneration of the .fmt file if needed, and latexmk taking good care of the rest.
But I have two problems with this :
- integration with
emacsto compile the whole document when working on a single file (makeneeds to be called in the proper directory) latexmkdoesn't recompile the file every time the preamble is modified, because it doesn't count as a dependency.
So I'd like to find a way to get rid of this Makefile, and get all the stuff done by latexmk.
I edited my .latexmkrc to include this :
pdflatex = 'pdflatex -fmt main %O %S';
add_input_ext('pdflatex','fmt');
add_cus_dep('tex', 'fmt', 1, 'compilepreamble');
sub compilepreamble {
print "Preamble compiling...\n";
$command = '&.pdflatex ./fmt/preamble.tex\dump';
system("pdflatex -ini -jobname='$_[0]' '$command'");
};
But with this, if the file main.fmt is not present or if fmt/preamble.tex is updated, the main.fmt file won't be regenerated.
Actually, in the first case, I get an error from pdflatex saying the it can't find main.fmt format file. So I understand latexmk doesn't even try to build main.fmt, it's probably not a problem in my custom dependency. However, I think I've added everything necessary for this to work.
So... Did I forget something? Is there a way round? Or is it a hopeless quest?
-recorderoption for latexmk to acknowledgepdflatexwas readingmain.fmt, and my poor knowledge of perl didn't result in proper string management, but now it works.:)– T. Verron Dec 09 '11 at 18:25latexmk, to avoid having to callpdflatex -ini ...manually? I have triedadd_cus_dep('fmt', 'tex', 1, 'my_noop');with a dummy functionmy_noop, but this didn't change anything. I would likelatexmkto callpdflatex -ini ...when the.fmtfile is missing, too. – krlmlr Mar 28 '12 at 08:47pdflatex -inimakes the format file. – John Collins Apr 02 '12 at 20:28pdflatexso that if the format file exists, it runspdflatex, but if the format file doesn't exist it makes a 2 line dummy log file. The first line of the dummy log file starts "This is ", and the second line has the name of the format file in parentheses. This will provokelatexmkrcinto thinking there is a correct log file and that the format file is a source file of the run ofpdflatex; it will then make the format file. – John Collins Apr 02 '12 at 21:25lang-perl, notperl-lang:)– doncherry Apr 02 '12 at 22:32latexmkso that if the format file exists, it runslatexmk, ...? I'm afraid I don't quite understand your comment as it is. Also, wouldn't it be possible to implement this logic in Perl, as a part oflatexmkrc? – krlmlr Apr 03 '12 at 19:09\input{main.ltx}with these instructions is not needed; I use '^&main' in the first line and then drop the-fmt mainpart. – Blaisorblade Jul 18 '17 at 20:55add_input_ext('pdflatex','fmt');by$input_extensions{'pdflatex'}{'fmt'} = 1;; one can also paste a copy ofadd_input_extfrom the oldlatexmk. @JohnCollins maybe this code should be part of your test suite? – Blaisorblade Jun 24 '19 at 15:51latexmk, particularly theadd_input_extbit. Secondly, may I request you to please consider editing your answer to incorporate your hint of avoiding the manual first call topdftex -ini, i.e. how can we accomodate the case of creating thefmtfile if it doesn't already exist? – Dr Krishnakumar Gopalakrishnan Sep 30 '19 at 22:15