I am trying to create my own template package.
In this package, there are several custom environments defined. One of those environments starts and ends a table, i.e:
\newenvironment{customenvtab}{\begin{tabular{c|c}}{\end{tabular}}
In this environment, I have defined a function to fill the table. This function uses macros defined with the help of the pgfkeys package to use key-value arguments. The problem is, only the first key value argument is mapped correctly when used. When I remove the tabular environment, both arguments are mapped correctly when used.
What am I doing wrong?
FYI: I am not very proficient in LaTeX.
Thank you very much in advance for your replys (and your patience, if there is something missing).
Here is my minimal example:
\documentclass{article}
\usepackage{pgfkeys}
\def\customvarset{\pgfqkeys{/rpath}}
\newenvironment{customenvnotab}{%
\newcommand*{\resetvarset}{%
\customvarset{%
spath/.cd,%
var1/.initial=var1 tbd,%
var2/.initial=var2 tbd
}
}
\resetvarset
\def\notabval##1{\pgfkeysvalueof{/rpath/spath/##1}}
\newcommand{\cmdnotab}[1]{%
\customvarset{spath/.cd, ##1}
\notabval{var1}, \notabval{var2}
\resetvarset
}
}{}
\newenvironment{customenvtab}{%
\newcommand*{\resetvarsettab}{%
\customvarset{%
tpath/.cd,%
var3/.initial=var3 tbd,%
var4/.initial=var4 tbd
}
}
\resetvarsettab
\def\tabval##1{\pgfkeysvalueof{/rpath/tpath/##1}}
\newcommand{\cmdtab}[1]{%
\customvarset{tpath/.cd, ##1}
\tabval{var3} & \tabval{var4}
\resetvarsettab
}
\begin{tabular}{c|c}
}{%
\end{tabular}
}
\begin{document}
\section{Working}
\begin{customenvnotab}
\cmdnotab{}\
\cmdnotab{var1=test var1}\
\cmdnotab{var2=test var2}\
\cmdnotab{var1=bla, var2=blu}
\end{customenvnotab}
\section{Not Working}
\begin{customenvtab}
\cmdtab{}\
\cmdtab{var3=test var3}\
\cmdtab{var4=test var4}\
\cmdtab{var3=blo, var4=bli}
\end{customenvtab}
\end{document}


\pgfqkeyscommand performs local assignments, and each tabular cell implicitly forms a group. So, the assignment works in the first column (where it is done), then is forgotten when the next cell starts. – frougon Jun 28 '22 at 10:03\customvarset{tpath/.cd, ##1}before each column actually works. What would be a clean way to implement input of multiple key value arguments with pgfkeys in such a setting (if there even is any)? (e.g. usage of another table package, or other types of solutions?) – frankieee Jun 28 '22 at 13:27\resetvarsettabis useless. In the spirit of your first idea, I've written a solution that automatically makes global assignments from/path/to/var3=...and/path/to/var4=.... Since these become macro assignments, I modified the definition of\tabvallike so:\newcommand*{\tabval}[1]{\pgfkeys{/rpath/tpath/#1/.my getvalue}}. There is automation to allow nice setup with\customvarset{tpath/.my setup keys={var3, var4}}, so it's nice to use but there is some machinery code. Can post if you want. – frougon Jun 28 '22 at 13:39