# Partial number parsing in siunitx

I would like the second and third examples to be printed like the first ($\times$ instead of x, spacing, repeated unit). However, in order to make siunitx accept \sqrt{2} or 2^n, I need to turn off number parsing, which turns off formatting of the number part completely.

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\SI{2 x 2}{\meter}

\SI[input-symbols=n,parse-numbers=false]{2^n x 2^n}{\meter}

\SI[parse-numbers=false]{\sqrt{2} x \sqrt{2}}{\meter}
\end{document}


Is there a way to partially parse the number part, so that spacing etc. is as intended and \sqrt{2} or 2^n still accepted?

## 1 Answer

This works:

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\SI{2 x 2}{\meter}

% in some cases, you can use the full expression as an "input symbol";
% however, this looks wrong:
\SI[input-symbols=2^n]{2^n x 2^n}{\meter}

% so to fix this, one may try:
\newcommand{\twon}{2^\mathit{n}}
\SI[input-symbols=\twon]{\noexpand\twon x \noexpand\twon}{\meter}

$2^n$ (for comparison)

% the same trick works here:
\newcommand{\sqrtwo}{\sqrt{2}}
\SI[input-symbols=\sqrtwo]{\noexpand\sqrtwo x \noexpand\sqrtwo}{\meter}

% and this is even a little simpler;
% although maybe less readable if your expression is longer:
\SI[input-symbols=\sqrt{2}]{\noexpand\sqrt{2} x \noexpand\sqrt{2}}{\meter}

$\sqrt{2}$ (for comparison)

\end{document}


Note that the simple fix (such as \SI[input-symbols=2^n]) does not even compile with \usepackage[detect-mode]{siunitx} (or \usepackage[detect-all]{siunitx}).


\documentclass{article}
\usepackage[detect-mode]{siunitx}
\newcommand{\twon}{2^n}
\begin{document}
\num[input-symbols=\twon]{\noexpand\twon}

$\num[input-symbols=\twon]{\noexpand\twon}$
\end{document}