1

I'm using pgfkeys to define some key-value options. I need some default value to initialize a key and I also want to use this default value as a fallback indepentent from the passed key value pair.

What I've tried is to create somekind of a child key. But I don't know how to use this to initialize the actual key with it.

In the MWE at the workaround I would like to use the original initialized value for titlepage. What is the best way to achieve this?

\begin{filecontents}{\jobname.def}
    Test file content
\end{filecontents}

\documentclass{article}
\usepackage{pgfkeys}

\pgfkeys{
    test/.cd,
    titlepage/.store in = \@file@titlepage,
    titlepage/.default = \jobname.def,%<-- Set default value
    titlepage = \jobname.def, % <-- initial titlepage
}
\newcommand{\testtitlepage}{%
    \InputIfFileExists{\@file@titlepage}
    {Found titlepage: \@file@titlepage\par} % <-- only for testing}
    {Workaround: \pgfkeysvalueof{test/titlepage}}%<-- Try to use default value of titlepage
}
\begin{document}
    \pgfkeys{test/titlepage = test.def}% <-- Set non-existing file to activate workaround
    \testtitlepage
\end{document}

Edit: I updated my MWE to use .default. But I'm still unable to use this default key inside \testtitlepage, when the passed file don't exist.

2
  • 3
    Isn't this what the pgfkeys modifiers .default or .initial are meant for?
    – user31729
    Commented Sep 18, 2017 at 12:45
  • Thanks for the advice. I updated my question using the .default modifier. But I still don't know how to get this default value inside my macro testtitlepage, when the passed file don't exist.
    – faltfe
    Commented Sep 18, 2017 at 14:21

1 Answer 1

2

I guess you are looking for this here:

\begin{filecontents}{\jobname.def}
    Test file content
\end{filecontents}

\documentclass{article}
\usepackage{pgfkeys}

\makeatletter
\pgfkeys{
    test/.cd,
    titlepage/.store in = \@file@titlepage,
    titlepage/.default = \jobname.def,%<-- Set default value
    titlepage = \jobname.def, % <-- initial titlepage
}

\newcommand{\testtitlepage}{%
    \InputIfFileExists{\@file@titlepage}
    {Found titlepage: \@file@titlepage\par} % <-- only for testing}
    {Workaround: \pgfkeysvalueof{/test/titlepage/.@def}}%<-- Try to use default value of titlepage
}
\begin{document}
    \testtitlepage

    \pgfkeys{/test/titlepage = notexisting.def}% <-- Set non-existing file to activate workaround
    \testtitlepage
\end{document}

enter image description here

1
  • Thanks, this is working nicely. Do the subkey .@def hold the value of the .default modifier? I couldn't find something within the pgf manual.
    – faltfe
    Commented Sep 19, 2017 at 11:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .