Reputation: 21
In the example below the macro "\pgfkeysprintvalue" is a variant of "\pgfkeysgetvalue" that sort of sends the value of a key to Lua, and prints it from Lua:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\pgfkeyssetvalue{/p}{PP}
\pgfkeysgetvalue{/p}{\luatmp}
\luatmp % prints a "PP" in the document
\def\pgfkeysprintvalue#1{
\pgfkeysgetvalue{#1}{\luatmp}
\directlua{print("#1: "..(token.get_meaning("luatmp") or ""))}
}
\pgfkeyssetvalue {/q}{QQ}
\pgfkeysprintvalue{/q} % prints "/q: ->QQ" on stdout
\end{document}
In this other example the first three "\pgfkeys"s have interesting side-effects but expand to nothing, and the "\pgfkeys{/c,/d,/e=DD}" expands to "(c)(d:)(c)(d:DD)":
\documentclass{article}
\usepackage{tikz}
\begin{document}
\pgfkeys{/c/.code=(c)}
\pgfkeys{/d/.code=(d:#1)}
\pgfkeys{/e/.style={/c,/d=#1}}
\pgfkeys{/c,/d,/e=DD}
\end{document}
The last "\pgfkeys" above "prints" the "(c)(d:)(c)(d:DD)" into the document, and it appears in the PDF.
How do I write a variant of \pgfkeys - let me call it \pgfkeysprint - that would store the expansion of its argument in a macro called \luatmp? I guess that it would be like this:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\def\pgfkeysprint#1{
<I don't know what to put here>{#1}{\luatmp}
\directlua{print("#1: "..(token.get_meaning("luatmp") or ""))}
}
\pgfkeys{/c/.code=(c)}
\pgfkeys{/d/.code=(d:#1)}
\pgfkeys{/e/.style={/c,/d=#1}}
\pgfkeysprint{/c,/d,/e=DD} % prints "/c,/d,/e=DD: -> (c)(d:)(c)(d:DD)" on stdout
\end{document}
I'm trying to write functions for inspecting PGF keys from a Lua REPL running inside LuaLaTeX, and the part corresponing to the "<I don't know what to put here>" above is the main piece that is still missing...
Obs: I tried to write my macro \pgfkeysprint by adapting the definition of \pgfkeysgetvalue in pgf/utilities/pgfkeys.code.tex, but I couldn't find the right way to use the "\expandafter"s...
Upvotes: 1
Views: 86