0

Perhaps I am fundamentally misunderstanding what \pgfkeys does, but I would like to use it as a way to store and retrieve data in my tex document. Based on the documentation, I would expext

\pgfkeys{/a/b=my value}
Hi there \pgfkeys{/a/b}!

to insert Hi there my value! into the document. The only way I have managed to get something similar to work is with

\pgfkes{/a/b/.code=#1, /a/b/.default=my value}
Hi there \pgfkeys{/a/b}!

but this definitely seems like improper usage to me...

How can I just set values and retrieve them later?

2

What you have is essentially correct but you need to set up the key properly first. Once the keys have been defined properly you can use \pgfkeys{/a/b} and \pgfkeysvalueof{/a/b} to access the current value.

For example, the code:

\documentclass{article}
\usepackage{pgfkeys}

\pgfkeys{/a/.is family, /a,
  b/.initial=my value
}

\begin{document}

  Hi there ``\pgfkeys{/a/b}''!

  \pgfkeys{/a/b=a new value}
  You can also use ``\pgfkeysvalueof{/a/b}''.

\end{document}

produces:

enter image description here

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.