I have been trying to get super-fast compiles with LuaLaTeX by using a pre-built preamble for my documents. However, every time I try to compile, I get this error:

No file main.aux.
[\directlua]:1: attempt to index global 'microtype' (a nil value)
stack traceback:
        [\directlua]:1: in main chunk.
MT@ifstreq ...{microtype.if_str_eq([[#1]],[[#2]])}
l.3 \begin{document}


This is with the following MWE:

% in pream.tex
\setmainfont{Arno Pro}

% in main.tex
\title{Test Document}

To generate the format I used

lualatex -ini -jobname="pream" "&lualatex" mylatexformat.ltx """pream.tex"""

and to compile main.tex I used

lualatex -fmt pream """main"""

Now, I have seen on the luatex-dev mailing list (linked to from Google) that the issue is that microtype is attempting to use some Lua code, but it can't because Lua code cannot go into a format – it must be run ‘live’ in the normal way.

Robert from the mailing list suggests putting \directlua{require("microtype")} into the document, but does not specify which one to put it in. Besides, wouldn't putting it into main.tex negate the whole (well, some of it) purpose of doing this – pre-loading all packages so compiles are faster?

Anyways, I digress.

Thanks for all the help you guys always offer here on TeX.sx!

  • 1
    You also cannot \setmainfont{Arno Pro} in a format. – Henri Menke Aug 13 '18 at 0:59
  • @HenriMenke Why not? The output says 54 preloaded fonts. – Aramis Razzaghipour Aug 13 '18 at 1:30
  • Because the font loader uses Lua as well. – Henri Menke Aug 13 '18 at 1:44
  • 2
    This question is essentially a duplicate of Guidelines for using mylatexformat with luatex but it does not have an answer, but the first comment repeats what I have stated here. You cannot dump Lua state or OpenType fonts into a format. – Henri Menke Aug 13 '18 at 4:43
  • 1
    In the luatex-dev thread you mention, @JosephWright seems to suggest that there might be something like a solution: "One can arrange (using bytecode) to save Lua fragments into a format but this is not really a general solution. Thus Lua code has to be loaded \everyjob. That's fine provided it's expected, but LaTeX packages tend to be designed on the assumption that they will be loaded 'live'." But I have no idea how this would be done practically nor why it wouldn't be a general solution. – Robert Aug 13 '18 at 13:38

Your Answer

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

Browse other questions tagged or ask your own question.