I have a macro for writing SI units that take numbers as optional arguments, but when these macros are used for ToC entries, the .toc file does not write closing brackets for optional arguments, messing up said .toc file during re-compile. Is this a fixable problem?



\ExplSyntaxOn % Used for many other macros, so keeping this would be very nice
\NewDocumentCommand \meter {o o} {
    \IfValueTF{#1} {
        \IfValueTF{#2} { \ensuremath{\SI{#2}{#1\meter}} }
        { \IfDecimal{#1} { \ensuremath{\SI{#1}{\meter}} } { \si{#1\meter} } }
    } { \si{\meter} }


.toc Entries :

\contentsline {section}{\numberline {1}\meter [0.7}{1}{section.1}% 

1 Answer 1


Just change




i.e., enclose the expression \meter[0.7] located in the optional argument of \section in a pair of curly braces. That way, LaTeX gets the help it needs to parse the arguments of \section correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.