I try to pass characters to lua but I don't want to typeset the "" that are not natural in latex syntax. Here is a dummy mwe.

Here is the background :



    % styles des étiquettes de graduation


        % longueur de l'axes sans le nez
        longueur/.store in=\@long,
        % minimum en x
        Xmin/.store in=\@min,
        % maximum en X
        Xmax/.store in=\@max,
        % le premier nombre est la graduation principale
        % le deuxième est la division de la graduation principale
        % le troisème est la division de la sous graduation
        % pour du papier millimétré : {1,2,5}
        % on les unités, les demis et les dixièmes.
        pas/.store in=\@pas,
        % nombre de niveau de graduation à étiqueter
        nb axes grad/.store in=\@AxeG,
        nb axes grad=1,
        % longueur du nez de la flèche en plus de la "longueur"
        nez/.store in=\@nez,
        % longueurs de marques de graduation
        mark length/.store in=\@mkl,
        mark length=.150,
        sub mark length/.store in=\@smkl,
        sub mark length=.120,
        sub sub mark length/.store in=\@ssmkl,
        sub sub mark length=.075,
        % épaisseur des marques de graduations
        submark/.style={line width=.4pt},
        % style de l'axe
            GradLength = {\@mkl, \@smkl, \@ssmkl}
            GradStyle = {"mark", "submark", "subsubmark"}
            Dte_Grad (\@long, \@min, \@max, {\@pas}, \@AxeG, \@nez)



\begin{tikzpicture}[baseline, label distance = -.1cm]

    \path[/DteG/.cd, Xmin=7.78, Xmax=7.93 ,pas={.1,10}, droite] ;
    \node[label=above:$M$] at (B3) {} ;
    \node[label=above:$N$] at (B5) {} ;
    \node[label=above:$P$] at (B11) {} ;
    \node[label=above:$R$] at (B13) {} ;



The DteGraduee.lua file :

tp = tex.print

function Dte_Grad (longueur, Xmin, Xmax, pas, AxeGrad, nez)

local step = {}

local GradTickT = {"A", "B", "C", "D"}
local GradTickB = {"a", "b", "c", "d"}

    function x (X)
        return (X - Xmin)*longueur/(Xmax - Xmin)

    -- dessin de l'axe
        tp("\\draw[/DteG/axe] (0,0)--(".. longueur + nez ..",0) ;")

    -- node phantom qui permet l'alignement à gauche
        tp("\\node[anchor=north,font=\\footnotesize,opacity=0] {\\num{0}} ;") 

    j = 1
    step[1] = 0
    step[2] = pas[1]

        if j > 1
            step[j+1] = step[j] / pas[j]

        -- calcul de l'abscisse du premier point de la graduation
        if Xmin % step[j+1] == 0
            start = Xmin
            start = Xmin + (step[j+1] - Xmin % step[j+1])

        k = 0 -- rang des ticks

        -- boucle de graduation
            -- convertit l'abscisse courante en abcisse sur le dessin
            i = x(start)

            -- on ne dessine pas la première marque sur l'axe
            -- si ce n'est pas zéro
            if start == 0 or math.abs(i)>.001
                -- dessine le trait
                tp("\\draw[/DteG/"..GradStyle[j].."] ("
                    ") coordinate ("..GradTickT[j]..k..")--("
                    ") coordinate ("..GradTickB[j]..k..")")

                -- étiquettes éventuelles sur la graduation
                if AxeGrad >= j and start % step[j] ~= 0
                    tp("node[anchor=north,font=\\footnotesize] {\\num{"..start.."}}") 

                -- on ferme le draw
                tp(";" )
            -- on incrémente
            start = start + step[j+1]
            k = k + 1

        -- abscisse suivante ou sortie
        until start > Xmax+.00001       -- arrondi supérieur

    -- sous graduation suivant ou sortie
    j = j + 1
    until pas[j] == nil


The result :

enter image description here

Here is what I am able to do for the moment. I want to pass the name of the points and their coordinate using the pgf keywords synthax. To avoid multiple "", one can do :



        points/.store in=\points,


    bob = \points
    list ()


and luatest.lua

function list ()
Point = {}

j = 1
for word in string.gmatch(bob, '([^,]+)') do
    Point[j] = word
    j = j + 1

j = 1
    while Point[j] ~= nil
    tex.print("\\node at ("..Point[j+1]..",0) {"..Point[j].."} ;")
        j = j + 2

With help of this question Lua need to split at comma

  • I don't have an environment with which to test, but my guess would be to simply remove them from your input: \begin{tikzpicture}[points={"A",1,"B",2}] to \begin{tikzpicture}[points={A,1,B,2}]. I've never worked with LuaTeX, though, so I may be way off. – Sean Allred Oct 6 '14 at 19:43
  • 1
    The title and the second paragraph of your posting seem to be at cross-purposes. Is your concern about the use of double quotes on the Lua side or on the TeX side of things? – Mico Oct 6 '14 at 19:46
  • @mico Lua need "A" otherwise it considers Point[1] as nil because A is nil. But don't want to typeset "A" in latex, so is there a way to add the "" automaticaly, or another way to pass characters ? Is it more clear ? – Tarass Oct 6 '14 at 19:53
  • Use TeX instead of Lua and it will work or do you have in real a more complex structure? – user2478 Oct 7 '14 at 9:16
  • @Herbert Yes I have a complex use for that. I can post it, not very long but not minimal ;-) – Tarass Oct 7 '14 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.