1

I'm sure this has something to do with expansion, and I am quite new to using the pgfkeys package so I'm possibly missing some sort of basic practice, but I cannot find anything that remotely looks like it could help me.

MWE:

\documentclass{article}
\usepackage{pgfkeys}
\begin{document}
\pgfkeys{firstkey/.initial=0}
\pgfkeys{firstkey}
%\ifnum\pgfkeys{firstkey}<1 true\else false\fi  %Does not work
\end{document}

Why is it that when the line that's commented out does not work, and I get a "Missing number, treated as zero." error? I'm sure that if I stored the values of the keys in macros I would be able to use that to compare, but I was hoping to keep my use of this as simple as possible.

For some background, I'm investigating this because I'd like to be able to specify values (text and numeric) for up to 50 parameters used by a function, but for the function to use defaults for anything which is not defined. Using key values seems like the most appropriate way to handle this, and since I'm already using tikz I figured the pgfkeys package would be fine for my purposes. It works just fine for passing text, but any time a function would require a number as an input, I experience this problem. Any assistance or guidance would be greatly appreciated.

  • If I remember correctly \pgfkeys uses some \let statement which isn't expandable. You should rather use \pgfkeysvalueof{firstkey}, with a proper value assigned to firstkey. You are trying to use \pgfkeys without setting the key value there, in this situation the .default value is applied, however, you used .initial – user31729 Aug 18 '17 at 20:31

Your Answer

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

Browse other questions tagged or ask your own question.