4

I am using the package kvoptions and declaring various stringoption's. When do you need to embrace a string value when calling your package/class?

E.g. In mypackage:

\DeclareStringOption[defaultval]{abc}[defaultval]

In calling class:

\usepackage[abc=someval]{mypackage}

When are braces needed around someval, i.e. abc={someval}

percusse
  • 157,807

1 Answers1

6

The braces are needed so that the parser can treat some group as a single element and avoid parsing inside.

Consider the following:

\cmd[key=val=1,bla=0]

What should the parser understand? There are many possible meanings:

\cmd[key={val=1,bla=0}]
\cmd[key={val=1},bla=0]
\cmd[{key=val}=1,bla=0]

etc.

In some situations the particular interpretation the parser chooses can be invalid and generate an error.

Additionally, the call to \cmd itself is performing some parsing to understand for example if there is an optional argument or not; this requires escaping square brackets as well: writing \cmd[key=\bla[1]] will make \cmd think its optional argument is key=\bla[1. To fix this, use \cmd[key={\bla[1]}].

Also, as noted by @Joseph some keyval packages also strip spaces around the value so to include them you may need to put them in braces as well, or escape them in some way depending on the value:

\cmd[key={ val }] or \cmd[key=\ val\ ]

To sum up, in your examples the problematic characters are ], , and =, sometimes spaces too.

Bordaigorl
  • 15,135