I apologize if this a rookie question, but I find it extremely hard to find a solution to my Lua problem using online searches and browsing reference manuals.
I would like to calculate a length: Divide \linewidth
by \baselineskip
, take the floor
, and finally multiply with \baselineskip
. The result should be returned in pt
.
I already fail with getting \baselineskip
into Lua such that I can do a calculation with it:
\documentclass{article}
\begin{document}
\begin{enumerate}
\item Linewidth works this way: \directlua{tex.sprint(tex.dimen['linewidth'] / 65536)tex.sprint('pt')}
\item and this way: \directlua{tex.sprint(tex.dimen.linewidth / 65536)tex.sprint('pt')}
\item \directlua{tex.sprint(tex.dimen['baselineskip'])}
\item \directlua{tex.print(tex.skip['baselineskip'].width)}
\item \directlua{tex.print(tex.skip['baselineskip'].stretch)}
\item \directlua{tex.sprint(tex.baselineskip)}
\end{enumerate}
\end{document}
So the questions are: How do I get \baselineskip
into Lua, and how can I calculate and output the length I described above.
If someone happens to know a "real" beginner's guide to LuaLaTeX that also discusses such problems, I would appreciate a hint. Thanks!
Solution
With the help of the answers below, the length above can be calculated as:
\directlua{tex.sprint(math.floor(tex.dimen.linewidth / tex.baselineskip.width)
* tex.baselineskip.width / tex.sp('1pt') ..'pt')}
[\directlua]:1: incorrect dimen name stack traceback: [C]: in function 'getdimen' [\directlua]:1: in main chunk. l.9 ...lua{tex.sprint(tex.getdimen("baselineskip"))}
. – FlorianL Apr 27 '17 at 19:37