# luatex tex.print does not trigger process_input_buffer callback?

I've defined a new LaTeX command to randomize itemize-like lists using LuaLaTeX like this:

\newcommand*\Randomize{%
\directlua{%
questions.itemstbl = {""}
}%
}


The Lua code simply collects all lines (items) between \Randomize and \EndRandomize, which prints the shuffled table of collected items:

\newcommand*\EndRandomize{%
\directlua{tex.print(questions.shuffleTable(questions.itemstbl))}%
}


The callback is finally removed by collect_lines when it finds the \EndRandomize line.

This works like a charm with the following direct input:

\begin{itemize}
\Randomize
\item some text
\item more text
\item another text
\EndRandomize
\end{itemize}


Problem arises when I try to read (using Lua) such environments from a .tex file and print (show) them using tex.print. It seems that LuaTeX does not trigger this data processing callback while doing tex.print, so \Randomize command does not work (without \Randomize it works).

Is there a simple solution for this problem? I'm thinking of generating a temp .tex file with all read itemize-like environments and then \input this file, such that the callback is triggered. But I'm trying to avoid the disk rw latency.

• Hm, can you show the mwe that doesn't work ? – Luigi Scarso Jul 12 '16 at 19:19
• Here follows a link to a Overleaf project showing a MWE link. What didn't work is if, instead of typing the environment "question" directly, I use several tex.print commands to produce the same env content. – bgeneto Jul 29 '16 at 13:44