Can't use numexpr in horizontal mode

\numexpr is an additional item that can be used in contexts where TeX is looking for a <number>.

It basically is an “unnamed counter register” as far as its syntax is concerned and is not allowed “bare”.

It essentially works like \countX (where \countX stands for an “unreachable” count register number) after this unnamed register is loaded with the value of the expression.

So just like you can't say Hi \count232 to print the value stored in \count232, you cannot say

Hi \numexpr 6+1\relax

Just consider \count232 and \numexpr 6+1\relax as referring to an abstract number, which exists independently of its representation. You need to access a representation of this abstract number:

Hi \number\count232

Hi \romannumeral\count232

Hi \number\numexpr 6+1\relax

Hi \romannumeral\numexpr 6+1\relax

Bare bones TeX only provides \number (for the decimal representation) and \romannumeral (for lowercase Roman numeral representation). Add-on packages may provide other representations.


You need \number or \the in front of the expression: \numexpr works like a TeX \count. Alternatively, you could use the xfp package to provide a thin wrapper

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

\number\numexpr 1 + 2 * 3 \relax

\the\numexpr 1 + 2 * 3 \relax

\inteval{1 + 2 * 3}

\end{document}