我制作了一个代码,它有一种特殊的方式来书写分值。
以下是 MWE:
\documentclass{article}
\usepackage{graphicx}
\makeatletter
\newif\if@thecomma
\def\normal@comma{,}
{
\catcode`\,=\active
\gdef,{
\if@thecomma
\expandafter\special@comma
\else
\expandafter\normal@comma
\fi}
}
\AtBeginDocument{\catcode`\,=\active}
\def\special@comma#1#2{
\ifx#1,
\else
\ifmmode
\hspace{-0.1em}\normal@comma{\raisebox{-0.10em}{\hspace{-0.28em}\scalebox{0.94}{$^{#1#2}$}}}\@thecommafalse
\else
,#1#2
\fi
\fi
}
\def\U{\ifmmode\@thecommatrue\scalebox{0.95}{\scalebox{0.98}{U\hspace{0.05em}\scalebox{0.96}{$\$$}}}\hspace{0.2em}\fi}
\makeatother
\begin{document}
I spent $\U213,22$ in last month.
\end{document}
此代码可用于多种用途,但我与 TikZ 节点有冲突 - 原因不太清楚。有没有建议获得更好的代码,没有这些极端情况?
答案1
在我看来,坚持使用标准 LaTeX 符号来表示参数更容易:
\documentclass{article}
\usepackage{xparse}
\NewDocumentCommand{\U}{>{\SplitArgument{1}{,}}m}{%
\mbox{\normalfont U\$\,\Uinner#1}%
}
\NewDocumentCommand{\Uinner}{mm}{%
#1,%
\Uraise{\IfNoValueTF{#2}{00}{#2}}%
}
\NewDocumentCommand{\Uraise}{m}{%
\begingroup\sbox{0}{0}%
\raisebox{\dimexpr\ht0-\height}{\scriptsize#1}%
\endgroup
}
\begin{document}
I spent \U{213,22} in last month and \U{10} today.
\end{document}