I want to print Latex Code with a Lua Function. But there is a problem with my function if there are parenthesis in the string: in the example the second code will not be printed), who can help me?

\setdefaultlanguage[spelling=new, babelshorthands=true]{german}

function myprint(string)

\newcommand*{\myprint}[1]{\directlua{myprint([[#1]])} }

\myprint{works fine $\pi\cdot x^2$}
\myprint{doesn't work $\sqrt{2}$}

1 Answer 1


Ok, i have found a working solution with xparse package:


and then using


The v means verbatim, that makes it work!

You must log in to answer this question.

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