6

Context:

I am still working on a solution for Thin space between minus sign and number. After digging through the source code of siunitx I think I have to redefine \c__siunitx_minus_tl, but unfortunately my knowledge about latex3 is close to non existent.

Question

How to redefine a command in latex3? I thought as the command was already present in the package, I could just set a new value

\tl_set:Nn \c__siunitx_minus_tl { + }

but this does not seem to have any influence. How to do this correctly?

M(N)WE

\documentclass{article}
\usepackage{siunitx}

\usepackage{expl3}

\ExplSyntaxOn
\AtBeginDocument{
   \tl_set:Nn \c__siunitx_minus_tl { + }
}
\ExplSyntaxOff

\begin{document}

    math mode $\num{-42}$

    text mode \num{-42}

\end{document}

[The exact replacement symbol does not matter at this stage, my first goal to get the replacement to work]

1
  • I am not sure where the boundaries between expl3 and latex3 are, please suggest re-tagging if you think something else would be more appropriate. Aug 23, 2016 at 12:01

1 Answer 1

7
+50

There are two separate issues here: how to redefine variable content any how to alter what you see with siunitx.

In terms of setting expl3 variables, the normal approach is to use \<thing>_set:Nn. Here we have a token list, and if you put

\ExplSyntaxOn
\tl_show:N \c__siunitx_minus_tl
\ExplSyntaxOff

after \begin{document} you will find it has been altered. I'll come back below to why that's not working in the output.

What you will notice here is that the variable is formally a constant (\c_...), so we should not attempt to set it. One can argue about whether this should be a constant, but as it is the conceptually more 'correct' way to deal with this situation is arguably to delete and recreate

\cs_undefine:N \c__siunitx_minus_tl
\tl_const:N \c__siunitx_minus_tl { + }

(The outcome is much the same, of course: ultimately we are dealing with a TeX macro.)

So why do you see no change? With the standard settings, siunitx uses math mode for printing numbers, and that means that - is passed through directly: \c__siunitx_minus_tl is not used. You will need to force text mode

\documentclass{article}

\usepackage{siunitx}

\sisetup{mode = text}
\ExplSyntaxOn
\cs_undefine:N \c__siunitx_minus_tl
\tl_const:Nn \c__siunitx_minus_tl { + }
\ExplSyntaxOff

\begin{document}
math mode $\num{-42}$

text mode \num{-42}
\end{document}

Of course, with expl3 we don't generally encourage altering internal values from other code. Here, siunitx has been something of a 'test case' for expl3 and when the current code was written the exact approach required in terms of interfaces was still being refined. I'd expect a v3 release of the package to have clearer interface set up, probably including a public name for \c__siunitx_minus_tl. (Work is ongoing on v3: tricky but I hope doable.)

1
  • 1
    Thank you so much - you're a Godsent! What a helpful, clear and informative answer! Seems like learning a bit expl3 will open interesting possibilities. Aug 23, 2016 at 13:41

You must log in to answer this question.

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