1

In my project, at some point I need to use a \numlist from siunitx in an \uppercase environment. However, additional options to the numlist command are not detected properly, as can be seen in the following MWE.

\documentclass[draft]{article}
\usepackage{siunitx}

\begin{document}

This does work: \numlist[parse-numbers=false]{2;3;4;5X}.

\uppercase{This does not work: \numlist[parse-numbers=false]{2;3;4;5X}.}

\end{document}

This produces the following error

The option file 'PARSE-NUMBERS' is not known by siunitx:perhaps it is spelled incorrectly.

and the resulting output is not correct.

Mensch
  • 65,388
mhehv
  • 11
  • 1
    This feels like an 'X-Y' question: could you give a bit more context? – Joseph Wright Aug 23 '21 at 09:44
  • I'm using the \numlist in a section title, which is capitalized when being used in the page heading. At that point, any option passed to \numlist is not working any longer (including the detect-all option to detect the font style) – mhehv Aug 23 '21 at 09:54
  • Since the \numlist is not expandable, you will have to come up with a different approach, which will depend on the intended usage. For example, \sbox0{\numlist[parse-numbers=false]{2;3;4;5X}} \uppercase{This does not work: \box0.} compiles, but "and" is not capitalized and the box will not respond to fontsize changes, etc. Further, \box0 is temporary and thus ephemeral. – Steven B. Segletes Aug 23 '21 at 10:01
  • 2
    It works if you use the textcase package and \MakeTextUppercase{This does not work: \NoCaseChange{\numlist[parse-numbers=false]{2;3;4;5X}}.} – daleif Aug 23 '21 at 11:50
  • @daleif Sounds like an answer to me – Joseph Wright Aug 23 '21 at 17:54
  • Somewhat related: https://tex.stackexchange.com/questions/384911/how-to-capture-a-macros-ultimate-expansion-as-a-string – John Kormylo Aug 24 '21 at 15:09

2 Answers2

1

The problem is obviously that \uppercase acts on the key=val pair.

One way around this is to use the textcase package and its \MakeTextUppercase and encase the stuff you do not want affected in \NoCaseChange{...}

This way this works

\documentclass[draft]{article}
\usepackage{siunitx}
\usepackage[overload]{textcase}
\begin{document}

This does work: \numlist[parse-numbers=false]{2;3;4;5X}.

\MakeTextUppercase{This does not : \NoCaseChange{\numlist[parse-numbers=false]{2;3;4;5X}}.}

\end{document}

daleif
  • 54,450
0

This will achieve your goal, but it means redefining \sectionmark each time you use \numlist.

\documentclass{book}
\usepackage{siunitx}
\usepackage{lipsum}

\begin{document} \csname protected@edef\endcsname\numlistA{\numlist[parse-numbers=false]{2;3;4;5X}}% \numlistA passed to TOC unexpanded \tableofcontents

\csname protected@edef\endcsname\numlistB{\numlist[parse-numbers=false, list-final-separator={~AND~}]{2;3;4;5X}}% \def\sectionmark#1{\let\numlistA\relax \markright {\MakeUppercase{#1}\numlistB}}

\section{This does not work \numlistA}

\lipsum[1-12]

\end{document}

What is really freaky is that if you change the definition of \numlistA, both the \tableofcontents and \markright will use the wrong definition with "AND" in the TOC and "and" in the header.

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • Is there a reason you didn't just use \sisetup{list-final-separator = { AND }}? – Joseph Wright Aug 23 '21 at 16:30
  • @JosephWright - It didn't occur to me. I was digging through the source code looking for something to patch. I will use it now. Thanks! – John Kormylo Aug 23 '21 at 17:48
  • Thanks for this suggestion, however this does not work if the \numlist is used inside a \section{}, as in that case and needs to be formatted depending on whether it is for example in the table of contents or in a page heading. – mhehv Aug 24 '21 at 08:15