# How can I use \SI from siunitx inside \replaced from changes?

I'm trying to record some changes using the changes package - I've already done a lot of the text, and had to work around display maths but I've got a simple value typeset using siunitx, and changing that value doesn't appear to work:

\documentclass{article}
\usepackage{siunitx}
\usepackage{changes}
\begin{document}
\replaced{\SI{1}{\volt}}{\SI{2}{\volt}}
\end{document}


gives:

! Extra }, or forgotten \endgroup.
\UL@stop ...z@ \else \UL@putbox \fi \else \egroup
\egroup \UL@putbox \fi \if...
l.5 ...\SI{1}{\volt}}{\SI{2}{\volt}}


If I continue to compile (getting the same error again and 2 missing } inserteds, the output is actually exactly as expected:

adding \protect before the \SI gives exactly the same error, and of course trying \SI{\replaced{1}{2}}{\volt} was never going to work:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! siunitx error: "invalid-token-in-number"
!
! Invalid token '\let ' in numerical input.
!
! See the siunitx documentation for further information.
!
! For immediate help type H <return>.
!...............................................


Is there some workaround that will get this to run without errors? I don't really want to run in nonstopmode in case of "real" errors, and besides, I used a build script that's designed to stop on errors.

The problem here is actually an interaction with the \sout command from the ulem package. Essentially, there is a clash over the insertion of a \penalty between the number and the unit: ulem alters how this expects to work and that doesn't agree with the box/grouping in siunitx. I've not traced it all back to a minimal example of the low-level code, but that probably wouldn't help in any case (at least without quite a bit of effort). What you can do is simply disable the insertion of a penalty. There isn't an interface for this (one of the few things not in the options for siunitx!) so at the moment a low-level redefinition is required

\documentclass{article}
\usepackage{siunitx}
\usepackage{changes}
\ExplSyntaxOn
\cs_set_eq:NN \__siunitx_unit_output_number_sep:
\__siunitx_unit_output_number_sep_aux:
\ExplSyntaxOff
\begin{document}
\replaced{\SI{1}{\volt}}{\SI{2}{\volt}}
\end{document}

• That's great, thank you. But is there a downside - i.e. should I be undoing this fix when I switch from [draft] to [final]? Sep 2, 2014 at 9:35
• @ChrisH Yes, I would. The penalty is there to prevent or at least discourage a line break between the number and the unit. Sep 2, 2014 at 9:47
• Now I think about it, I'm using a non-breaking space as my separator, so on the face of it I shouldn't need a penalty anyway. But of course I've no way of knowing whether it could break despite this. Sep 2, 2014 at 11:23

You could define your own deletion markup no depending on the ulem package, e.g.:

\usepackage{changes}
\setdeletedmarkup{---#1---}


Downside of this approach is that the deleted markup does not match expectations of being striked out.

As I cannot answer the duplicate question Undocumented incompatibility between changes and siunitx? here is the link for the corresponding issue tracker Incompatibility with siunitx and maybe other packages

Disclaimer: I am the author of the package.

• This is an interesting alternative, however when the document also contains multi-line changes to body text (as mine did) I don't think it would be very clear Jul 22, 2019 at 6:12
• Yes, I wanted to point out a solution to prevent using the ulem package. Maybe you could format your deletions bold and red (regardless of the author) or such. Markup of headings, figures, citations etc. is difficult too. Sorry.
– etg
Jul 23, 2019 at 7:43

An easy workaround for this is to replace \SI{x}{y} for \num{x}\,\si{y}, which should produce an equivalent result in most cases and doesn't produce the error:

\documentclass{article}
\usepackage{siunitx}
\usepackage{changes}
\begin{document}
\replaced{\SI{1}{\volt}}{\num{2}\,\si{\volt}}
\end{document}


Wrap \SI inside a \mbox:
\mbox{\SI{}}.
Take into account that the word will continue along the line (no breakup).

• Welcome to TeX.SE! Please explain better how that can solve the given issue ... Mar 23, 2018 at 13:14