18

I know I can access raw TeX dimens with Lua using tex.dimen[key], but how do I access a LaTeX length in Lua?

MWE:

\documentclass{article}

% This is TeX
\newdimen\boxwidth
\boxwidth=3.4ex
% end of TeX

\newlength{\boxwidthlatex}
\setlength{\boxwidthlatex}{5.8ex}

\begin{document}
\directlua{tex.print(tex.dimen['boxwidth'])}  

% How to do something like this?
% \directlua{tex.print(tex.dimen['boxwidthlatex'])}  

\end{document}
21

LaTeX lengths are skips, and skips are not a simple object but a table. So you need to do something like this:

\documentclass{article}

% This is TeX
\newdimen\boxwidth
\boxwidth=3.4ex
% end of TeX

\newlength{\boxwidthlatex}
\setlength{\boxwidthlatex}{5.8ex}

\begin{document}
\directlua{tex.print(tex.dimen['boxwidth'])}

\directlua{tex.print(tex.skip['boxwidthlatex'].width)}

\directlua{tex.print(tex.skip['boxwidthlatex'].stretch)}
\end{document}

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.