Assume a LaTeX 2e-macro, be it named \foo, which processes the content of one optional argument via keyval-syntax.

E.g., \foo[key1=value1, key2=value2,...,\keyN=valueN]

I would also like to have a macro
\setfoodefaults{key1=value1, key2=value2,...,\keyN=valueN}

so that after
\setfoodefaults{key1=foo, key2=bar,...,\keyN=baz}
the call
\foo %
will yield the same as the call
\foo[key1=foo, key2=bar,...,\keyN=baz]%.

In other words: Via \setfoodefaults you can set default values for each key. Such a default value shall be applied when the key in question is not specified at all in the key-value-list of \foo's optional argument.

(Be aware that not specifying a key at all within a key-value-list is different from specifying a key without a value: In the latter case the default value specified by means of the corresonding \define@key-command gets used. I am after specifying (other) default values that are to be used in the further case.)

The question is:

Which practice is better:

Should a macro \setfoodefaults change/set the default values only within the current scope/group?

Should a macro \setfoodefaults change/set the default values globally?

  • 3
    everything is local in latex unless explicitly documented as global so local is the natural choice unless you are setting things that are inherently global such as properties of the whole document – David Carlisle May 20 at 16:25
  • 1
    You could add a global-key to \setfoodefaults so the user can choose whether changes of defaults are global or restricted to the current/local scope. By the way: Probably a macro \setfoodefaults is not needed at all. You could add a key to \foo so that the values specified will henceforth also be defaults globally or within the current scope. – Ulrich Diez May 20 at 16:45
  • As a user I would probably expect the default settings to be global (otherwise what is the point of setting defaults if you have to do it again in a new scope), similar to using commands like \lstset (listings), \setminted (minted) or \setkeys{Gin} (graphicx). – Marijn May 20 at 21:30

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.