45

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?

  • 7
    Lot of the time LuaTeX (luaotfload) spends on loading fonts. I am not sure if this can be put in the format. – topskip May 17 '13 at 8:48
  • 2
    I too think OpenType fonts can't be set up in a format. – egreg May 17 '13 at 9:02
  • 1
    You need the version of LuaTeX in TeXLive 2013; the one in TL2012 has a bug with mylatexformat. – Reinstate Monica - M. Schröder May 17 '13 at 9:08
  • 1
    @MartinSchröder That bug is fixed; but nothing there seems to say that OpenType fonts can be made part of the format. See this ticket – egreg May 17 '13 at 9:58
  • 3
    @Ingo Not an answer to your question, but might be helpful in this context: You can use LuaJitTeX instead of LuaTeX. For many documents it can be used as a drop-in replacement. Depending on your use of Lua, this might yield a speed gain between 5% and 30%. – Marco Sep 25 '13 at 23:03
7

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

% 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}
  • I know so far this does not contain any actual LuaTeX specific stuff. I'm happy to work some in if requested. – sheß Sep 7 '15 at 15:09
  • 1
    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 7 '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 7 '15 at 15:19
  • 1
    applied your suggested changes – sheß Sep 7 '15 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.