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}

1 Answer 1

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}

You must log in to answer this question.

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