50

Compiling my documents with lualatex takes quite long. I have a complex preamble, and I noticed that it takes long to process this part of the file.

Today, I came across this website, which proposes a trick I haven't seen on this site before. By pre-compiling the preamble, it claims to speed up compilation approximately three-fold: Faster LaTeX part IV: Use a precompiled preamble (Wayback Machine snapshot).

However, I have not been able to follow this tutorial with LuaLaTeX. How can I pre-compile my preamble with it?

aronadaal
  • 553
Ingo
  • 20,035

1 Answers1

12

I might be missing the point of the question, or fail to see why what my computer does is not what the OP is looking for. Further this is is certainly not the most elegant solution, since I'm at work so I only had Windows & TeXnicCenter+MikTEX2.9 at my disposal. But I think it does what it should.

Here's what I do:

  1. Compile lua_pream.tex with profile LuaTeX⇨PDF(pre) (see below)
  2. Compile lua_nopream.tex with profile LuaTeX_post⇨PDF(post)

The profiles:

LuaTeX⇨PDF(pre) is

luatex  -interaction=nonstopmode -ini -jobname="lua_pream" "&lualatex" mylatexformat.ltx "./lua_pream.tex"

or in TeXnicCenter:

enter image description here

LuaTeX_post⇨PDF(post) is

lualatex -fmt lua_pream "./lua_nopream.tex"

or in TeXnicCenter:

enter image description here

lua_nopream.tex contans not much really

\endofdump %%stuff from lua_pream.tex is dumped before here, you only need this if you have a local preamble
% part of the preamble that has to be evaluated each run
\begin{document}
The preamble used for this was compiled with vvvv set to \vvvv
\end{document}

lua_pream.tex contains the preamble

% static part of the preamble (stuff that does not change every now and then)
\documentclass{article}
\usepackage{luatexbase}
\usepackage{geometry}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subfig}
\usepackage{booktabs}
\usepackage{enumitem}
\usepackage{xspace}
\usepackage{cleveref}
\usepackage{hyperref}
\usepackage{natbib}
\def\vvvv{foobar}
% the \endofdump part 'saves' everything above into one precompiled preamble, which gets loaded every time the LaTeX document is processed. This saves a lot of time mostly. 
% NOTE: the following line ends the dumping into the preamble format file!
\endofdump
\begin{document}
        This text plays no role I guess
\end{document}
Mensch
  • 65,388
sheß
  • 3,622
  • I know so far this does not contain any actual LuaTeX specific stuff. I'm happy to work some in if requested. – sheß Sep 07 '15 at 15:09
  • 2
    You shouldn't have inputenc if you are using LuaTeX. And you probably don't want fontenc either, although it can be used if you know what you are doing. hyperref should be loaded late. It already loads url. Probably you want fontspec. I know this is only an example, but.... – cfr Sep 07 '15 at 15:14
  • You're right. That is all simply copied from the link in the OP's question. I'll update it to more sensible code as soon as I find time. Feel free to go ahead and edit my post – sheß Sep 07 '15 at 15:19
  • 2
    applied your suggested changes – sheß Sep 07 '15 at 15:56