0

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 2

1

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}
1
  • Many thanks -- I didn't see this until I'd pestered Ulrike Fisher (thinking it might be a hyperref issue, more than my misunderstanding how to implement mylatexformat). I believe I have it work: take the 'unchaanging' preamble bits, pop them into a file, and \endofdump to that file, and compile it into a .fmt file. Then, in main .tex document, pull in the compiled .fmt file, add and \endodump, then drop in any 'changing' packages between the \endofdump and \bginn{document}. If this isn't exactly right (although it seems to work), let me know. Mar 10, 2021 at 15:42
0

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)

6
  • Thanks -- as you (probably) guessed, the particular package I tried to 'post-load' after piulling in the format file was hyperref. But, even though I had (I think) tried a version of your suggest (i.e., pull in the .fmt file, then set \hypersetup before the \begin{document}, the various options I'm trying to pass to hyperref seem to be ignored (at least, they're not showing up in the final .pdf I generate at the end of the process). For example, if I try something simple like \hypersetup{pdftitle={This is the title}}, this is not showing up in the properties for the .pdf file. Mar 8, 2021 at 18:09
  • @JohnnyCanuck ah well some options for pdf internal reasons can only set once, I'd have to check the code (or ask Ulrike which is easier) but if the title has already been written to the pdf you can't get it back Mar 8, 2021 at 18:15
  • Thanks again. The inability to send various things to the PDF isn't a deal-breaker (I can add the manually after the fact). Simply trying to automate as much as I can. mylatexformat still saves me a significant amount of time. Mar 8, 2021 at 18:27
  • pdftitle should work in \hypersetup unless some other package (like pdfx) disables it or overwrites it. Mar 8, 2021 at 19:18
  • Not using pdfx, so that isn't the specific conflicting package. I'll try to work up a MWE, but an MWE involving 30-40 packages in the preamble isn't particularly 'minimal'. Might be simpler to simply post a list of packages being called, and the sequence, and seeing if any of them might be an obvious candidate for the problem. I can absolutely guarantee that at present something simple like \hypersetup{pdftitle={This is the title}} isn't working. If its relevant, I do everything through a .dvi -> .ps -> .pdf build sequence. Mar 8, 2021 at 20:21

You must log in to answer this question.

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