LaTeX forum ⇒ Document ClassesCreating dynamic keys with pgfkeys

Information and discussion about specific document classes and how to create your own document classes.
uebeue8ebd
Posts: 1
Joined: Sun Nov 10, 2024 5:49 pm

Creating dynamic keys with pgfkeys

Postby uebeue8ebd » Sun Nov 10, 2024 5:56 pm

Good day to everyone, I hope you can help me with this question.
I need to store some parameters in a document and later be able to retrieve them. I’m sharing the code with you:
\documentclass{article}
\usepackage{tikz}

\pgfkeys{
	/myKeys/.is family, 
}

\newcommand{\readDynamicKey}[1]{
	\pgfkeysifdefined{/myKeys/#1}%
		{Value of Key #1 = \pgfkeysvalueof{/myKeys/#1}}%
		{Key #1 not found}
}

\begin{document}
	Reading all keys immediately after being created\\
	\def\n{1}	
	\pgfkeyssetvalue{/myKeys/A\n}{A\n}
	\readDynamicKey{A\n}\\
	\foreach \n in {2,...,3}{
		\pgfkeyssetvalue{/myKeys/A\n}{A\n}
		\readDynamicKey{A\n}\\
	}
	\par\medskip
	
	Reading all keys later\\
	\foreach \n in {1,...,3}{
		\readDynamicKey{A\n}\\
	}
\end{document}


However, the compiler's response is:
Reading all keys immediately after being created
Value of Key A1 = A1
Value of Key A2 = A2
Value of Key A3 = A3

Reading all keys later
Value of Key A1 = A1
Key A2 not found
Key A3 not found


It seems that the keys are being saved, but later I can't retrieve them. Could you help me resolve this?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics

Return to “Document Classes”

Who is online

Users browsing this forum: Google [Bot] and 5 guests