I have some Lua code which searches for "①" and "②" within some text and prints only the text displayed between:

    userdata = userdata or {}

    function userdata.printbetween(str, m1, m2)
        m1 = m1 or "①"
        m2 = m2 or "②"
        mat_pat = string.format('%s(.*)%s', m1, m2)
        str = string.match(str, mat_pat) or str

\define\sentence{This is ① a final ② test sentence.}


        \item \textbetween{This is ① a test ② sentence.}
        \item \textbetween{This is ① another test ② sentence.}
        \item \textbetween{\sentence}

This should print:

1. a test
2. another test
3. a final

Instead, this is printing:

1. a test
2. another test
3. This is ① a final ② test sentence.

When I give Lua a variable, such as \sentence, it appears to process "\sentence" and not the data contained inside \sentence.

How can I let Lua examine the contents inside the variable rather than just examining the variable's name?

  • 3
    \define makes the definition unexpandable. Try \def\sentence{....} instead
    – Aditya
    Jul 21 '13 at 0:21

\define makes the definition unexpandable. Instead use


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.