0

I'm working with a document for which I need to generate some data from a Lua script each time the PDF is produced. However, the generation of this data might be a slow, so I would like the script only to generate it from scratch when lualatex doesn't run in draft mode.

I wonder if there's something like this:

if tex.isRunningDraftMode() then
    print("USING OLD DATA")
else
    generateDataFromScratch()
end

Note that during the generation of the data, nothing is written to the document.

1 Answer 1

3

You can test for draft mode with tex.draftmode:

if tex.draftmode == 1 then
  print'draftmode'
else
  generateDataFromScratch()
end

Attention: this tests for the engine level draft mode (Triggered by running lualatex with the --draftmode option or the \draftmode primitive. In this mode LuaTeX does not generate a PDF at all).

If you are thinking about a different draft mode you will need another answer.

1
  • This is exactly what I needed, thanks!
    – Miguel
    Apr 4, 2022 at 14:42

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.