1

For faster compilation, I'm attempting to use a custom format file. However, it seems to misbehave when I try to use \maketitle … even though I use \title{Test}.

MWE

I've created a preamble.tex with the following content:

\documentclass{scrartcl}

\endofdump

I've then compiled it to a .fmt file with pdflatex -output-directory /tmp/ -ini -jobname=preamble "&pdflatex" mylatexformat.ltx /tmp/preamble.tex, and it produces preamble.fmt with no warnings or errors.

Then I create a demo.tex with the following content

%& /tmp/preamble

\author{tec}
\date{2023-02-02}
\title{Test}

\begin{document}

\maketitle

Hello

\end{document}

When I attempt to compile this with latexmk -f -pdf -pdflatex -shell-escape -interaction=nonstopmode -output-directory=/tmp /tmp/demo.tex it fails, with the error:

! LaTeX Error: No \title given.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.10 
     
(/usr/share/texmf/tex/latex/microtype/mt-cmr.cfg)

LaTeX Warning: No \author given.

If I remove the \maketitle, it works as expected and I get a PDF containing "Hello".

I also tried setting the title and author with

\makeatletter
\gdef\@title{Test}
\gdef\@author{tec}
\makeatother

however, I still ran into the error above.


If anybody could help me work out what is going on, and how I might fix this, that would be much appreciated.

3
  • This maybe isn't the issue but could you put \usepackage{hyperref} as the last package in preamble.tex and try again? It is uncanny how many issues arise when hyperref isn't the last package loaded so it would at least eliminate that as a cause
    – JamesT
    Feb 12, 2023 at 10:06
  • 1
    I can confirm that putting hyperref last makes no difference. In fact, I've been able to make a much more minimal MWE.
    – tecosaur
    Feb 12, 2023 at 10:41
  • mylatexformat starts reading files from \begin{document}. so you have to move \title{…}, \author{…} etc. after \begin{document}.
    – cabohah
    Feb 12, 2023 at 11:02

1 Answer 1

1

It seems I have missed a rather crucial part of the mylatexformat docs. The \endofdump command should be in both preamble.tex and demo.tex.

If I add \endofdump to the start of demo.tex, everything works as expected.

2
  • 1
    Somehow more precisely: mylatexformat has been made to dump the whole preamble of a document. So you just don't need two files. But if you use two file, everything before \begin{document} (or \endofdump) of the document file is ignored. So you cannot set \author, \title and \date before \begin{document} but only after it (or use an addition \endofdump).
    – cabohah
    Feb 12, 2023 at 11:06
  • I'm aware I don't need two files, the idea here is that the same precompiled format file can be used with many .tex files :)
    – tecosaur
    Feb 12, 2023 at 13:04

You must log in to answer this question.

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