I need to make some macros in ConTeXt. I have tried to use Lua code, but I do not understand how to mix ConTeXt source and Lua source together. Here is an example:
\define[3]\textmacro{
\startlua
if #1=1 then
tex.print('#2')
else
tex.print('\math{#3}')
end
\stoplua
}
\starttext
\textmacro{1}{This is some text.}{1+2}
\stoptext
If #1
is equal to "1", this should print the contents of #2
, otherwise it should print the contents of #3
in math mode. In LaTeX, this can be written in this way:
\documentclass{article}
\usepackage{etoolbox}
\newcommand{\textmacro}[3]{
\ifnumequal{#1}{1}{#2}{$#3$}
}
\begin{document}
\textmacro{1}{This is some text.}{1+2}
\end{document}
How can I do this correctly with Lua and ConTeXt?