1

I am trying to use mylatexformat to precompile my lengthy preamble, which is basically all in my custom .cls, with the remaining bit of non-static preamble at the top of my main.tex, before which I put \csname endofdump\endcsname (I have also tried just \endofdump). I use VSCode (LaTeX Workshop) and my distribution is MiKTeX. I have successfully generated the main.fmt file by using the command lualatex -ini -jobname="main" --shell-escape "&lualatex" mylatexformat.ltx "main.tex". Once I have the .fmt, I put %&main on the very first line of my main.tex and run the command lualatex --shell-escape "&main" main.tex, however, I keep on getting this error:

    (./main.tex[\directlua]:1: attempt to index a nil value (global 'shellesc')
    stack traceback:
            [\directlua]:1: in main chunk.
    \write ->\directlua {shellesc.write_or_execute()}  

I thought this might be due to me not having the shellesc.sty tool in MiKTeX, but I do, and --shell-escape is working and produces minted output, when I'm not using mylatexformat ofcourse. A very similar error shows up here, but their issue was fixed by just installing a missing package it seems.

Here is my main.log directly after generating the .fmt, and here is a log file after issuing the second command.

I can't think of any other details to include to help the debug process, but can definitely add more if needed. Although I am running it using lualatex, I ultimately want to be able to use latexmk -lualatex ... for automation, but I don't know if that's possible with mylatexformat...

  • 2
    you can not save Lua state or Opentype fonts in the format so precompiling the format with lualatex is tricky. – David Carlisle Apr 20 '21 at 10:57
  • luatex does not have the same \write18 mechanism to access the shell so minted (via shellesc package) uses Lua to access the shell if used by luatex, but if you load shellesc.sty into the format the tex interface is saved but all the underlying Lua definitions are dropped so, as you show you get undefiend names in Lua – David Carlisle Apr 20 '21 at 11:04
  • Might be a stupid question... but... what if I precompiled my .cls (excluding the lualatex dependent fonts, etc.) in pdflatex for example, and then added the font in the dynamic part of the preamble and compiled with lualatex? – Daniel Jakob Apr 20 '21 at 12:14
  • no the format is engine specific , tex isn't a compiler there isn't really any compiled form of a class or package file, the fmt is just a dump of the state of the engine at that time (it used to be literally a core dump of the machine memory not so in recent decades but still engine specific). Just don't load packages using lua in your preloaded preamble, and load them in the document using the format. – David Carlisle Apr 20 '21 at 13:13
  • Just curious, are you using mylatexformat to speed up compiling or to just reduced pre-amble? For the latter, you can just make a standalone file for your pre-amble as a .sty and use RequirePackage. I used mylatexformat a fair bit in the past, but didn't really notice compile speed improvement. Not that important to me anyways. – likethevegetable Apr 20 '21 at 21:58
  • @likethevegetable, I already have most of my \RequirePackages and settings in my custom labreport.cls class file. Is this different from using a .sty? – Daniel Jakob Apr 21 '21 at 16:15
  • For most intents, they're the same. Have you seen noticeable speed gains with mylatexformat? – likethevegetable Apr 21 '21 at 16:35
  • I only got mylatexformat to work once with pdflatex, not at all with lualatex, and by moving a good few of my packages to the dynamic section of the preamble, but then, yes I did see a big improvement. During a regular compile, VSCode tells me that about 40 seconds is being spent doing the preamble, of 52 seconds total in a 4-run latexmk compile, but with mylatexformat it was about 14 seconds total. – Daniel Jakob Apr 21 '21 at 16:59

0 Answers0