Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pgfkeys: define keys with optional arguments #1308

Open
stettberger opened this issue Feb 28, 2024 · 0 comments
Open

pgfkeys: define keys with optional arguments #1308

stettberger opened this issue Feb 28, 2024 · 0 comments

Comments

@stettberger
Copy link

Brief outline of the proposed feature

Dear PGF/TikZ developers,
thank you for your tremendous work. In my daily work, pgfkeys have proven to be the sanest way to write TeX code. However, when creating my notebook templates, I felt the need for a way to define pgfkeys with an optional argument. I was inspired by /tikz/label and /tikz/pin, but discovered that there is no cannonical way to define such keys on your own.

Therefore, I built one. If you think this is worth the effort, I can create a pull request for this.

Usage example

\def\pgfkeysdefargopt#1#2#3{%
  \long\def\pgfkeys@temp{%
    \@ifnextchar[%
    {\pgfkeysvalueof{#1/.@body}}%
    {\pgfkeysvalueof{#1/.@body}[#2]}%
  }%
  \pgfkeyslet{#1/.@cmd}{\pgfkeys@temp}%
  \def\pgfkeys@temp[##1]##2\pgfeov{#3}%
  \pgfkeyslet{#1/.@body}{\pgfkeys@temp}%
}

\pgfkeysdefnargs{/handlers/.code 2 opt}{2}{%
  \edef\pgfkeys@temp{\pgfkeyscurrentpath}%
  \expandafter\pgfkeysdefargopt\expandafter{\pgfkeys@temp}{#1}{#2}}

\pgfkeys{/handlers/.style 2 opt/.code 2 args=\pgfkeys{\pgfkeyscurrentpath/.code 2 opt={#1}{\pgfkeysalso{#2}}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant