[luatex] Accessing pgf nodes from inside Lua(La)Tex

Paul Isambert zappathustra at free.fr
Tue Jun 19 08:45:18 CEST 2012


"Keith J. Schultz" <schultzk at uni-trier.de> a écrit:
> 
> Hi All,
> 
> I am writing a package with pgf/TikZ from making Nassi-Schneider diagramms.
> I have the code working under XeLaTeX and wanted to refracture it to LuaTeX.
> I have to admit that I am not very TeXian. 
> 
> My question is if I have the name of a pgf node how do I get at its coordinates from
> within LuaTeX.
> 
> Or, is there a way to call pgf from directly inside LuaTeX.
> 
> What I am looking for is to have a LuaTeX call to get the coordinates.
> The following code that I have is: 
> 
> 	\pgfextracty{\YCoordinate}{\pgfpointanchor{\LastNode}{south}}
> 
> 	where \LastNode is the Name of the pgf node and \YCoordinate is a dimension.
> 
> So my do I access pgf structures from in LuaTeX?
> 
> Any help or pointers would be appreciated.

I don't think PGF has any Lua interface, but I might be wrong here.

> 
> It would help me, also, if someone could tell me how to access something I have defined
> with \edef in LuaTeX
> 
> eg. 
> 
> in the TeX file 
> \edef{\aValue}{tttt}
> 
> in a loaded .lua file
> 
> function get_my_value(NameValue)
> 	local a = <some in Lua to access the edef>(NameValue)
> 
> 	return a
> end

You can't do that, really. You may devise a complex system of
\directlua/tex.print calls, but I have some doubts it'll work.

Instead, you can use token lists:

    \edef\aValue{tttt}
    \mytok\expandafter{\aValue}

and in Lua:

    function get_my_value (name)
      local a = tex.toks.mytok
      return a
    end

Otherwise, if you really need a TeX macro (not a token list), you can
try:

    \directlua{ mymacros = {} }
    \def\gobble#1{}
    \def\Def#1#2{%
      \edef#1{#2}%
      \directlua{%
        mymacros["\expandafter\gobble\string#1"] =
          "\luaescapestring{#2}" }%
      }

then
  
    \Def\aValue{tttt}

defines \aValue as before and makes its replacement text available in
Lua as "mymacros.aValue". Admittedly suboptimal...

Best,
Paul



More information about the luatex mailing list