I saved the following code in the file ~/Test.tex.
\documentclass{article}
\usepackage{pgfkeys}
\pgfkeys{
/handlers/first char syntax=true,
/handlers/first char syntax/the character a/.initial=\LowercaseA
}
\def\LowercaseA#1{#1}
\begin{document}
\pgfkeys{aardvark}
\end{document}
The code configures the \pgfkeys command to inspect the first character of each key, and if this character is the letter a, to call the \LowercaseA command with a single argument: the key. The \LowercaseA command simply expands to its argument. The code then calls \pgfkeys, passing it the key aardvark.
Then I executed the following commands in the Terminal.
> cd ~
> pdflatex Test
The compilation failed, and ~/Test.log contained the following error message.
! Package pgfkeys Error: I do not know the key '/aardvark' and I am going to ignore it. Perhaps you misspelled it.
See the pgfkeys package documentation for explanation.
Type H <return> for immediate help.
...
l.9 \pgfkeys{aardvark}
This came as an undesirable surprise. I expected the compilation to succeed, and for the PDF file to display the string "aardvark". My expectations were based on the following quote from section 87.3.1 First Char Syntax Detection of the PGF & TikZ manual for version 3.1.9a (the current version), on p. 977:
Usually, keys are of the form
〈key〉=〈value〉and how such keys are handled is discussed in the rest of this section. However, it is also possible to setup a different syntax for certain parts of the input to\pgfkeys. [...] this special syntax detection is the very first thing that is done when a key is processed, before any of the following operations are performed.
Questions
- Why did the compilation fail?
- How can I change my code so that the generated PDF file displays the string "aardvark"?
pgfkeysnot only alphabetical letters but also digits, and the\meaningof digits starts withthe character(as opposed tothe letter), so I assumed this applied to letters as well, and simply copied-and-pasted without verifying with the\meaningcommand. – Evan Aad Dec 14 '22 at 22:19