Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with siunitx commands in math mode in some cases #315

Open
schtandard opened this issue Jan 24, 2025 · 0 comments
Open

Error with siunitx commands in math mode in some cases #315

schtandard opened this issue Jan 24, 2025 · 0 comments

Comments

@schtandard
Copy link

My understanding is that the siunitx typesetting commands need to be protected by an \mbox in order not to run into issues with ulem and this is what happens as long as they appear outside of math mode. Inside math mode, this does not seem to be done and does not usually cause any trouble (though I don't understand why). However, I have found that it can still be problematic in some situations. Here's an MWE:

document_old.tex

\documentclass{article}
\usepackage{siunitx}
\begin{document}

Hello World!
Bye World!

\end{document}

document_new.tex

\documentclass{article}
\usepackage{siunitx}
\begin{document}

Hello World!
We have $x = \qtylist[list-units=bracket, list-final-separator={, }]{1; 2; 3}{\meter}$, you see.
Bye World!

\end{document}

After running latexdiff document_old.tex document_new.tex > document_diff.tex, I get the following document_diff.tex.

\documentclass{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL document_old.tex   Fri Jan 24 13:42:49 2025
%DIF ADD document_new.tex   Fri Jan 24 13:42:53 2025
\usepackage{siunitx}
%DIF PREAMBLE EXTENSION ADDED BY LATEXDIFF
%DIF UNDERLINE PREAMBLE %DIF PREAMBLE
\RequirePackage[normalem]{ulem} %DIF PREAMBLE
\RequirePackage{color}\definecolor{RED}{rgb}{1,0,0}\definecolor{BLUE}{rgb}{0,0,1} %DIF PREAMBLE
\providecommand{\DIFadd}[1]{{\protect\color{blue}\uwave{#1}}} %DIF PREAMBLE
\providecommand{\DIFdel}[1]{{\protect\color{red}\sout{#1}}} %DIF PREAMBLE
%DIF SAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddbegin}{} %DIF PREAMBLE
\providecommand{\DIFaddend}{} %DIF PREAMBLE
\providecommand{\DIFdelbegin}{} %DIF PREAMBLE
\providecommand{\DIFdelend}{} %DIF PREAMBLE
\providecommand{\DIFmodbegin}{} %DIF PREAMBLE
\providecommand{\DIFmodend}{} %DIF PREAMBLE
%DIF FLOATSAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddFL}[1]{\DIFadd{#1}} %DIF PREAMBLE
\providecommand{\DIFdelFL}[1]{\DIFdel{#1}} %DIF PREAMBLE
\providecommand{\DIFaddbeginFL}{} %DIF PREAMBLE
\providecommand{\DIFaddendFL}{} %DIF PREAMBLE
\providecommand{\DIFdelbeginFL}{} %DIF PREAMBLE
\providecommand{\DIFdelendFL}{} %DIF PREAMBLE
%DIF COLORLISTINGS PREAMBLE %DIF PREAMBLE
\RequirePackage{listings} %DIF PREAMBLE
\RequirePackage{color} %DIF PREAMBLE
\lstdefinelanguage{DIFcode}{ %DIF PREAMBLE
%DIF DIFCODE_UNDERLINE %DIF PREAMBLE
  moredelim=[il][\color{red}\sout]{\%DIF\ <\ }, %DIF PREAMBLE
  moredelim=[il][\color{blue}\uwave]{\%DIF\ >\ } %DIF PREAMBLE
} %DIF PREAMBLE
\lstdefinestyle{DIFverbatimstyle}{ %DIF PREAMBLE
	language=DIFcode, %DIF PREAMBLE
	basicstyle=\ttfamily, %DIF PREAMBLE
	columns=fullflexible, %DIF PREAMBLE
	keepspaces=true %DIF PREAMBLE
} %DIF PREAMBLE
\lstnewenvironment{DIFverbatim}{\lstset{style=DIFverbatimstyle}}{} %DIF PREAMBLE
\lstnewenvironment{DIFverbatim*}{\lstset{style=DIFverbatimstyle,showspaces=true}}{} %DIF PREAMBLE
\lstset{extendedchars=\true,inputencoding=utf8}

%DIF END PREAMBLE EXTENSION ADDED BY LATEXDIFF

\begin{document}

Hello World!
\DIFaddbegin \DIFadd{We have $x = \qtylist[list-units=bracket, list-final-separator={, }]{1; 2; 3}{\meter}$, you see.
}\DIFaddend Bye World!

\end{document}

Trying to compile the diff, I get the error message

! Argument of \qtylist  has an extra }.
<inserted text> 
                \par 
l.51 }
      \DIFaddend Bye World!
I've run across a `}' that doesn't seem to match anything.
For example, `\def\a#1{...}' and `\a}' would produce
this error. If you simply proceed now, the `\par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your `}' was spurious, just type `2' and it will go away.

If I omit any of the options passed to \qtylist, the error goes away, so it seems to be some kind of special case. Encasing the \qtylist in a brace group also works.

I hope this is the right place to report this, as I don't really understand what's going on. Maybe the siunitx commands should be protected also in math mode?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant