5

I am toying with luadraw and would like to have my graphic depending on \thepage for the number of iterations. I tried \\thepage, "\\thepage" or to use g:Writeln or tex.sprint but none of them worked.

Minimal non-working example (inspired by the luadraw manual):

%!TEX TS-program = lualatex
\documentclass{article}
\usepackage{luadraw}

\begin{document}
bla blo bli
\begin{luadraw}{name=Sierpinski}
local iteration = g:Writeln("\\thepage") %num? tex.sprint?
local g = graph:new{window={-5,5,-5,5},margin={0,0,0,0},size={1,1}}
local i = cpx.I
local rand = math.random
local A, B, C = 5*i, -5-5*i, 5-5*i -- triangle initial
local T, niv = {{A,B,C}}, iteration
for k = 1, niv do
    T = concat( hom(T,0.5,A), hom(T,0.5,B), hom(T,0.5,C) )
end
for _,cp in ipairs(T) do
    g:Filloptions("full", rgb(rand(),rand(),rand()))
    g:Dpolyline(cp,true, "line width=0pt")
end
g:Show()
\end{luadraw}
\end{document}
1
  • 1
    I don't have a better answer than the one offered by @Jasper Habicht, but I have two remarks: your code doesn't work because you're using a method of the g graphic object (g:Writeln()) before you've created that object. Furthermore, the g:Writeln() method writes a string to the tikzpicture environment, but doesn't return a value (so it returns nil). Commented Mar 10 at 12:40

1 Answer 1

3

You can access the value of the counter page (which is called \c@page internally) using tex.count['c@page']:

%!TEX TS-program = lualatex
\documentclass{article}

\begin{document}
This is page \thepage.

This is page \directlua{tex.sprint(tex.count['c@page'])}.
\end{document}

output of above code

So, in your Lua code, you could just say

local iteration = tex.count['c@page']
2
  • Any idea how to also access the last page counter? Commented Mar 10 at 12:51
  • 2
    But as always the page counter is not reliable because of the asynchronous page breaking. Commented Mar 10 at 13:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.