How do you apply \Roman to a math expression in a counter

counters

Let's say I want to produce the same effect as in How do you switch numbers in a chapter?

but with Roman numerals. So I would have

  • Chapter I
  • Chapter II
  • Chapter III+IV
  • Chapter VI

instead of the arabic version in that post.

In that post, Chapter 3+4 is produced by the following code:

\def\thechapter{\arabic{chapter}+\the\numexpr\value{chapter}+1\relax}

I wonder if there is a similar way to produce Chapter III+IV. If I just do

\def\thechapter{\Roman{chapter}+\Roman{\the\numexpr\value{chapter}+1\relax}}

it will return an error. (The same if I remove \the.)

Best Answer

This answer really answers the specific question of why the error occurs and how to fix it. It doesn't address the issues answered in the linked question. See egreg's answer for that kind of solution or use the solution here as part of the solution given in the linked question.

The \Roman command (and similar commands) expect a counter as an argument, not a number, but your \numexpr yields a number, hence the error you receive:

Missing number, treated as zero.
<to be read again> 
\c@4

So if you want to do this simply by using the same method, you need to use the internal command \@Roman which expects a number.

\documentclass{book}

\makeatletter
\def\thechapter{\Roman{chapter}+\@Roman{\numexpr\value{chapter}+1\relax}}
\makeatother
\begin{document}
\setcounter{chapter}{2}
\chapter{A chapter}
\end{document}

If you don't want to use the low level command \@Roman you can load the calc package, and use a temporary counter to achieve the same effect:

\documentclass{book}
\newcounter{tmpchap}
\usepackage{calc}
\renewcommand\thechapter{\protect\setcounter{tmpchap}{\value{chapter}+1}\Roman{chapter}+\Roman{tmpchap}}
\begin{document}
\setcounter{chapter}{2}
\chapter{A chapter}
\end{document}

output of code

Related Question