TransWikia.com

mylatexformat | packages loaded 'after' dump?

TeX - LaTeX Asked by Johnny Canuck on July 5, 2021

I’ve been testing the mylatexformat as a means for speeding up the compilation of various documents that call lots (30-40) of packages in the preamble (including some large packages, like TikZ) — documents where pulling the preamble consumes a significant chunk of the total compilation time. So far, seems to do the trick (cuts compilation times for the document down to ~10-20% of what it was before trying this approach).

However, one thing I’m wondering about. Let’s say that your document uses packages A, B,…E, F. Most of the options/flags for packages A -> E are fixed, so using mylatexformat, you ‘dump’ them to a generated format file. However, what if for package F you need/want to tweak a setting, for a given compilation. Doesn’t seem doable.

For example, if in my .tex document I have (say)

 %&"My.Document.Template"

 usepackage[bunch of tweaked options]{F}

 begin{document}
  ...
 end{document}

then compilation ignores package F. In other words, once the ‘dumped’ format file is pulled in (first line), then everything after that is ignored until begin{document} is parsed.

Am I missing something? Is there any way to put most of the packages into a format file, but have a few loaded after that format file is pulled in? Based on my attempts so far, seems like the answer is ‘no’. I’m unsure, though, because the docs for mylatexformat make reference to the minitoc pacakge as being something that cannot be included in the format ("you must use endofdump before usepackage{minitoc}"), which seems to imply that it is possible to pull in another package (or more) after the format file is read in. If so…how?

Thanks in advance…

2 Answers

It depends on the package.

Some packages use options to set flags that are changeable later, for example options to hyperref are mostly just a convenience and you can do the same using hypersetup{...} after the package is loaded.

Other packages change their behaviour at load time, for example amsmath implements centred or flush left equations but only one set gets defined depending whether or not fleqn is used, so if you pre-load the package with fleqn the code for centred math displays is not available and you can't easily get it back. (If you try to undefine things so you can re-load the package it's theoretically possible but a lot more work than simply using the normal format)

Answered by David Carlisle on July 5, 2021

mylatexformat allows you to keep the preloaded preamble in your file. This allows to keep the source of your preamble and document together, documents which packages are used, helps editors auto-detecting LaTeX files by scanning for documentclass, and makes it easier to use the ame document with and without your custom format. In order to avoid issues when packages or classes are loaded again, it skips your preamble when the format is loaded. This can be avoided by splitting your preamble in a part which is ignored and a non-preloaded part with endofdump:

%&"My.Document.Template"

% This is ignored and might (or might not) contain your original preamble..., e.g.
documentclass{my_super_class}
usepackage{A, B, C, D, E}

endofdump
% This gets executed everytime you compile.

usepackage[bunch of tweaked options]{F}

begin{document}
 ...
end{document}

Answered by Marcel Krüger on July 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP