4

I'm creating a letter using the ConTeXt letter module, and I want to process an external file within Lua and change some of the letter setup and text based on the data in the external file. I'm confused about the correct way to use context.startletter().

\usemodule[letter]

\startluacode

userdata = userdata or {}

function userdata.printLetter()
    context.startletter()
    context("Basic letter text")
    context.stopletter()
end

\stopluacode

\starttext

\ctxlua{userdata.printLetter()}

\stoptext

Compiling this trivial letter example yields an undefined control sequence for me.

EDIT: After some more tinkering, it seems that changing context.stopletter() to tex.print("\\stopletter") generates the letter that I expected. I'm still confused about the mechanism causing the problem or why that change works.

1 Answer 1

2

The letter environment uses a buffer to collect the content before it it adds the other elements (e.g. the opening). To use a buffer environment from Lua you have to use context.delayed instead of context in your code.

\usemodule[letter]

\startluacode

userdata = userdata or {}

function userdata.printLetter()
    context.delayed.startletter()
    context("Basic letter text")
    context.delayed.stopletter()
end

\stopluacode

\starttext

\ctxlua{userdata.printLetter()}

\stoptext
1
  • Adding context.delayed does produce an error-fee compilation of the file, but the resulting .pdf doesn't use any of the letter styling. Is there additional work I need to do to feed the buffer to the letter environment?
    – Ben
    Jul 17, 2015 at 18:55

You must log in to answer this question.

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