我希望第二个和第三个示例能够像第一个一样打印($\times$
而不是x
、间距、重复单位)。但是,为了siunitx
接受\sqrt{2}
或2^n
,我需要关闭数字解析,这会完全关闭数字部分的格式。
\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}
有没有办法部分解析数字部分,以便间距等符合预期或\sqrt{2}
仍然2^n
被接受?
答案1
这有效:
\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}
请注意,简单的修复(例如\SI[input-symbols=2^n]
)甚至不能与\usepackage[detect-mode]{siunitx}
(或\usepackage[detect-all]{siunitx}
)一起编译。
还要注意detect-mode
,可以使用\newcommand{\twon}{2^n}
而不是\newcommand{\twon}{2^\mathit{n}}
数学模式之外的 ;但这可能会导致数学模式下打印错误:
\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}