11

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:

surprisingly correct output of above code

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.

4 Answers 4

13

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}
3
  • 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]?
    – Chris H
    Sep 2, 2014 at 9:35
  • 1
    @ChrisH Yes, I would. The penalty is there to prevent or at least discourage a line break between the number and the unit.
    – Joseph Wright
    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.
    – Chris H
    Sep 2, 2014 at 11:23
2

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.

See example in https://gitlab.com/ekleinod/changes/tree/master/testfiles/t61-siunitx

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.

2
  • 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
    – Chris H
    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
1

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}
-1

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

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

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.