13

I'm a big fan of custom LaTeX formats built with mylatexformat. So far, pdftex has been my default engine. I'm now going to use luatex as my default engine so I'd like to adapt my format customization workflow to luatex particularities.

What kind of packages/macros can I dump in my custom format for luatex?

9
  • 4
    you can not dump lua state or opentype fonts so you need to avoid any luatex-specific setup: more trouble than it's worth, probably:-) Commented Aug 12, 2016 at 16:25
  • 2
    @DavidCarlisle Indeed. Hard to guess that e.g. pdftexcmds has a lua module without looking at the code. So no polyglossia, no fontspec, no tikz, no pgfplots, etc. That's really bad...
    – cjorssen
    Commented Aug 12, 2016 at 16:35
  • 2
    if it really mattered you could define things to catch the lua parts and load in \everyjob (as the latex format itself loads the luatexbase code in \everyjob) but really it's not a lot slower loading from a file than from a format so in most cases the benefits are probably not worth the complication Commented Aug 12, 2016 at 18:12
  • 1
    @DavidCarlisle Well, I'd be interested in a generic way to catch the lua code, say for pdftexcmds as an example without knowing the package has luacode.
    – cjorssen
    Commented Aug 12, 2016 at 18:17
  • 2
    no real generic way as if you load the tex into the format but delay the lua parts until everyjob, the relative order of execution is different and it may or may not need adjustment to the code in each case. Commented Aug 12, 2016 at 18:19

1 Answer 1

4

It's a bit hard to make a system that would work for all packages, but for any given package you can usually make something work, I preload pdftexcmds and article class here.

I did try to see if you could redefine \directlua while making the format to save its argument to run automatically in \everyjob in documents using the custom format, but even in a simple package like pdftexcmds that is tricky as some \directlua you do need to restore, but some are just transient tests while loading the file which break if you do them later. Here in fact you just need to make sure that require("pdftexcmds") is executed.

Rather than use mylatexfmt I have used a simpler custom test, but it uses the same principles.

In a normal run the test file produces terminal output of

$ lualatex cc421
This is LuaHBTeX, Version 1.15.1 (TeX Live 2023/dev) 
 restricted system commands enabled.
(./cc421.tex
LaTeX2e <2022-11-01> patch level 1
 L3 programming layer <2022-12-17>
(/usr/local/texlive/2022/texmf-dist/tex/latex/base/article.cls
Document Class: article 2022/07/02 v1.4n Standard LaTeX document class
(/usr/local/texlive/2022/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2022/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty
(/usr/local/texlive/2022/texmf-dist/tex/generic/infwarerr/infwarerr.sty)
(/usr/local/texlive/2022/texmf-dist/tex/generic/iftex/iftex.sty)
(/usr/local/texlive/2022/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty))
(/usr/local/texlive/2022/texmf-dist/tex/latex/l3backend/l3backend-luatex.def)
(./cc421.aux) (/usr/local/texlive/2022/texmf-dist/tex/latex/base/ts1cmr.fd)
 -1 | 0 | 1 
(./cc421.aux))
 413 words of node memory still in use:
   3 hlist, 1 vlist, 1 rule, 2 glue, 3 kern, 1 glyph, 5 attribute, 48 glue_spec
, 5 attribute_list, 2 write nodes
   avail lists: 2:7,3:1,4:1,5:4,7:1,9:1

warning  (pdf backend): no pages of output.
Transcript written on cc421.log.

showing article loading and the -1 | 0 | 1 test of the Lua strcmp implementation.

You can dump a format with

luahbtex -ini \&lualatex  cc421

and use it as follows showing a much reduced terminal output

$ luahbtex \&cc421 cc421
This is LuaHBTeX, Version 1.15.1 (TeX Live 2023/dev) 
 restricted system commands enabled.
(./cc421.tex
 -1 | 0 | 1 
(./cc421.aux))
 398 words of node memory still in use:
   3 hlist, 1 vlist, 1 rule, 2 glue, 3 kern, 1 glyph, 2 attribute, 48 glue_spec
, 2 attribute_list, 1 write nodes
   avail lists: 2:13,3:2,4:2,5:4,7:3,9:3

warning  (pdf backend): no pages of output.
Transcript written on cc421.log.

The test file here is

\ifx\dumped\undefined
\documentclass{article}


\usepackage{pdftexcmds}

\begin{document}
\def\dumped{}
\dump
\else
\directlua{require("pdftexcmds")}
\fi


\makeatletter

\typeout{
\pdf@strcmp{aaa}{bbb} | \pdf@strcmp{aaa}{aaa} | \pdf@strcmp{bbb}{aaa}
}

\end{document}

To make this really usable you'd want to do the same for (at least) luaotfload, but hopefully it shows that the basic aim of preloading at least the tex part of major packages into the format is not impossible.


updated to use luahbtex as required for current latex

2
  • Note: in the latest version I need to replace luatex with luahbtex.
    – user202729
    Commented Jan 18, 2023 at 15:55
  • @user202729 ah yes I'll update, lualatex has used luahbtex for a few years now Commented Jan 18, 2023 at 18:58

You must log in to answer this question.

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