1

The main macro in tkz-elements is \tkzGetNodes. This macro retrieves the elements from the z table in order to create nodes. The elements in the table provide the node name and its coordinates. The code for this macro is as follows:

\def\tkzGetNodes{\directlua{%
     for K,V in pairs(z) do
        local n,sd,ft
        n = string.len(K)
        if n > 1 then
        _,_,ft, sd = string.find(K, "(.+)(.)" )
       if sd == "p" then   K=ft.."'" end
       _,_,xft, xsd = string.find(ft, "(.+)(.)" )
       if xsd == "p" then  K=xft.."'".."'" end
         end
    tex.sprint("\\coordinate ("..K..") at ("..V.re..","..V.im..") ; \string\r")
   end
   }}

There is no problem with the contact details, but I am having difficulty processing the names. Of course, whether it is on the lua or TeX side, certain characters are not accepted. As the use is primarily mathematical, I need certain characters. _ poses no difficulty, but in order to use prime (') and double prime (''), I had to find a workaround. This involves reserving the letter p or the pair pp, replacing them with ' and '' if they appear at the end of a name. Thus, z.Ap = point(1, 2) becomes node A' with coordinates (1, 2). z.Bpp becomes B'' and z.p becomes p.

Example:

\documentclass{standalone}
\usepackage[mini]{tkz-euclide}
\usepackage{tkz-elements}

\begin{document}

\directlua{
z.Ap = point(0, 0)
z.Bpp = point(5, 1)
z.p = point(2, 3)
% z.apo = point(1, 1)
}

\begin{tikzpicture}
\tkzGetNodes
\tkzDrawPolygon(A',B'',p)
\tkzDrawPoints(A',B'',p)
\tkzLabelPoints(A',B'')
\tkzLabelPoints[above](p)
\end{tikzpicture}
\end{document}

Question: How can I modify my macro so that point names that do not have a p at the end are accepted, but one or more letters p in their bodies? The following case appears to be the only one ...

With z.apo, I obtain

./name.tex:18: Package pgf Error: No shape named `apo' is known.

Ultimately, I am not filtering the names correctly, and with z.xpy, xpy is transformed into x''?

enter image description here

14
  • I'm not sure I understand the question. With your current code, z.apollonius = point(1, 1) results in \coordinate (apollonius) at (1,1) ;. Is that not what you want? What do you want instead? Commented 9 hours ago
  • 3
    in lua foo.x is just syntactic sugar for foo["x"] and if you use the latter form you are not limited to function names so you can use ' and other characters. Commented 9 hours ago
  • @Marijn Sorry, I was mistaken. You're right about Apollonius and Pappus; it works. It's with apo that there's a problem! Commented 8 hours ago
  • quotes, as @DavidCarlisle says, but o/w use the partial regex syntax to specify a match at the end of the string? if you put the lua in a separate file then you do not need to worry about tex special characters. Commented 8 hours ago
  • 2
    you're also recompiling the lua chunk every time \tkzGetNodes is called rather than once. if you split the lua out, you end up with a table of functions you can call and you don't have to think about tex syntax when writing them. instead you have something like tkz.GetNodes or maybe you define \tkzGetNodes on the lua side. see max's answers for ways to do that. none of this changes your package syntax. Commented 7 hours ago

1 Answer 1

4

Following cfr's comments, I tried this:

   \def\tkzGetNodes{\directlua{%
   tkz.GetNodes()
   }}


function tkz.GetNodes()
    local bs = string.char(92) 

    for K, V in pairs(z) do
        local name = K
        local n = string.len(name)

        if n > 1 then
            local ft, sd = string.match(name, "(.+)(.)")
            if sd == "p" then
                name = ft .. "'"

                local xft, xsd = string.match(ft, "(.+)(.)")
                if xsd == "p" then
                    name = xft .. "''"
                end
            end
        end

        tex.sprint(
            bs .. "coordinate (" .. name .. ") at (" ..
            V.re .. "," .. V.im .. ");"
        )
    end
end

Application:

\documentclass{standalone}
\usepackage[mini]{tkz-euclide}
\usepackage{tkz-elements}

\begin{document}

\directlua{
z.Ap = point(0, 0)
z.Bpp = point(5, 1)
z.p = point(2, 3)
z.apo = point(2, 1)
z.pappus = point(1, 1)
z.apop = point(3, 1)
}

\begin{tikzpicture}
\tkzGetNodes
\tkzDrawPolygon(A',B'',p)
\tkzDrawPoints(A',B'',p,pappus,apo,apo')
\tkzLabelPoints(A',B'')
\tkzLabelPoints[above](p,pappus,apo,apo')
\end{tikzpicture}
\end{document}

name_node

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.