是否有可能排版存储在宏中的 \numexpr 计算的数字,而无需使用 \the?

是否有可能排版存储在宏中的 \numexpr 计算的数字,而无需使用 \the?

对于下面的 MWE,使用\thewith\NextShiftIndex可以使文档正确运行,但是,我想知道是否可以让存储在 中的计算数字\NextShiftIndex不需要\the像存储在 中那样进行排版\CurrentShift

\documentclass{article}
\parindent=0pt

\begin{document}

    \edef\CurrentShift{2}
    \edef\NextShift{\numexpr\CurrentShift + 1\relax}
    
    \ifnum \CurrentShift = 2
        \def\CurrentShiftIndex{2\textsuperscript{nd}}
        \def\NextShiftIndex{\NextShift\textsuperscript{rd}}
    \else
            \ifnum \CurrentShift = 3
                \def\CurrentShiftIndex{3\textsuperscript{rd}}
                \def\NextShiftIndex{\NextShift\textsuperscript{th}}
            \else
                \def\CurrentShiftIndex{\CurrentShift\textsuperscript{th}}
                \def\NextShiftIndex{\NextShift\textsuperscript{th}}
        \fi
    \fi
    
    \CurrentShiftIndex\\
    \NextShiftIndex

\end{document}

答案1

您在追寻类似这样的东西吗?:

\documentclass[a4paper]{article}

% ---- Layout ----------------------------------------------------------------------
\pagestyle{plain}
\csname @ifundefined\endcsname{pagewidth}{}{\pagewidth=\paperwidth}%
\csname @ifundefined\endcsname{pdfpagewidth}{}{\pdfpagewidth=\paperwidth}%
\csname @ifundefined\endcsname{pageheight}{}{\pageheight=\paperheight}%
\csname @ifundefined\endcsname{pdfpageheight}{}{\pdfpageheight=\paperheight}%
\textwidth=\paperwidth
\advance\textwidth-3cm
\evensidemargin=\dimexpr-1in+2cm\relax
\oddsidemargin=\dimexpr-1in+1cm\relax
\marginparsep=2mm
\marginparwidth=\dimexpr2cm-2\marginparsep\relax
\textheight=\paperheight
\advance\textheight-3cm
\topmargin=\dimexpr-1in+1cm\relax
\headheight=0pt
\headsep=0pt
{\normalfont
 \setbox\csname @tempboxa\endcsname\hbox{0123456789}%
 \global\footskip=\dimexpr 1cm -.5\dp\csname @tempboxa\endcsname
                               +.5\ht\csname @tempboxa\endcsname\relax
}%
\parindent=0pt
\flushbottom
% ----------------------------------------------------------------------------------

\newcommand*\OrdinalNumber[1]{%
  \the\numexpr(#1)\relax
  \textsuperscript{\ifcase\the\numexpr(#1)\relax th\or st\or nd\or rd \else th\fi}%
}%
\newcommand*\advanceMacro[2][1]{%
  \edef#2{\the\numexpr(#2)+(#1)\relax}%
}%
% \advanceMacro can be prefixed with \global.

\begin{document}

\twocolumn

Initialize \verb|\CurrentShift|:\smallskip

\verb|\def\CurrentShift{0}|\def\CurrentShift{0}\\%
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\OrdinalNumber{\CurrentShift}| yields: \OrdinalNumber{\CurrentShift}\\
\verb|\OrdinalNumber{\CurrentShift+1}| yields: \OrdinalNumber{\CurrentShift+1}\\
\verb|\OrdinalNumber{\CurrentShift+2}| yields: \OrdinalNumber{\CurrentShift+2}\\
\verb|\OrdinalNumber{\CurrentShift+3}| yields: \OrdinalNumber{\CurrentShift+3}

\medskip\hrule\medskip

\verb|\advanceMacro{\CurrentShift}|\advanceMacro{\CurrentShift}\\
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\OrdinalNumber{\CurrentShift}| yields: \OrdinalNumber{\CurrentShift}\\
\verb|\OrdinalNumber{\CurrentShift+1}| yields: \OrdinalNumber{\CurrentShift+1}\\
\verb|\OrdinalNumber{\CurrentShift+2}| yields: \OrdinalNumber{\CurrentShift+2}\\
\verb|\OrdinalNumber{\CurrentShift+3}| yields: \OrdinalNumber{\CurrentShift+3}

\medskip\hrule\medskip

\verb|\advanceMacro{\CurrentShift}|\advanceMacro{\CurrentShift}\\
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\OrdinalNumber{\CurrentShift}| yields: \OrdinalNumber{\CurrentShift}\\
\verb|\OrdinalNumber{\CurrentShift+1}| yields: \OrdinalNumber{\CurrentShift+1}\\
\verb|\OrdinalNumber{\CurrentShift+2}| yields: \OrdinalNumber{\CurrentShift+2}\\
\verb|\OrdinalNumber{\CurrentShift+3}| yields: \OrdinalNumber{\CurrentShift+3}

\medskip\hrule\medskip

\verb|\advanceMacro{\CurrentShift}|\advanceMacro{\CurrentShift}\\
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\OrdinalNumber{\CurrentShift}| yields: \OrdinalNumber{\CurrentShift}\\
\verb|\OrdinalNumber{\CurrentShift+1}| yields: \OrdinalNumber{\CurrentShift+1}\\
\verb|\OrdinalNumber{\CurrentShift+2}| yields: \OrdinalNumber{\CurrentShift+2}\\
\verb|\OrdinalNumber{\CurrentShift+3}| yields: \OrdinalNumber{\CurrentShift+3}

\medskip\hrule\medskip

\verb|\advanceMacro{\CurrentShift}|\advanceMacro{\CurrentShift}\\
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\OrdinalNumber{\CurrentShift}| yields: \OrdinalNumber{\CurrentShift}\\
\verb|\OrdinalNumber{\CurrentShift+1}| yields: \OrdinalNumber{\CurrentShift+1}\\
\verb|\OrdinalNumber{\CurrentShift+2}| yields: \OrdinalNumber{\CurrentShift+2}\\
\verb|\OrdinalNumber{\CurrentShift+3}| yields: \OrdinalNumber{\CurrentShift+3}

\medskip\hrule\medskip

\verb|\advanceMacro[2+3]{\CurrentShift}|\advanceMacro[2+3]{\CurrentShift}\\
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\OrdinalNumber{\CurrentShift}| yields: \OrdinalNumber{\CurrentShift}\\
\verb|\OrdinalNumber{\CurrentShift-4}| yields: \OrdinalNumber{\CurrentShift-4}\\
\verb|\OrdinalNumber{\CurrentShift+1}| yields: \OrdinalNumber{\CurrentShift+1}\\
\verb|\OrdinalNumber{\CurrentShift+2}| yields: \OrdinalNumber{\CurrentShift+2}\\
\verb|\OrdinalNumber{\CurrentShift+3}| yields: \OrdinalNumber{\CurrentShift+3}\\
\verb|\OrdinalNumber{\CurrentShift*2}| yields: \OrdinalNumber{\CurrentShift*2}

\medskip\hrule\medskip

\verb|\advanceMacro[\numexpr5-10\relax]{\CurrentShift}|%
\advanceMacro[\numexpr5-10\relax]{\CurrentShift}\\
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\OrdinalNumber{\CurrentShift}| yields: \OrdinalNumber{\CurrentShift}\\
\verb|\OrdinalNumber{\CurrentShift-4}| yields: \OrdinalNumber{\CurrentShift-4}\\
\verb|\OrdinalNumber{\CurrentShift+1}| yields: \OrdinalNumber{\CurrentShift+1}\\
\verb|\OrdinalNumber{\CurrentShift+2}| yields: \OrdinalNumber{\CurrentShift+2}\\
\verb|\OrdinalNumber{\CurrentShift+3}| yields: \OrdinalNumber{\CurrentShift+3}\\
\verb|\OrdinalNumber{\CurrentShift*2}| yields: \OrdinalNumber{\CurrentShift*2}

\newpage

Initialize \verb|\CurrentShift|:\smallskip

\verb|\def\CurrentShift{3}|\def\CurrentShift{3}\\%
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\OrdinalNumber{\CurrentShift}| yields: \OrdinalNumber{\CurrentShift}\\
\verb|\OrdinalNumber{\CurrentShift+1}| yields: \OrdinalNumber{\CurrentShift+1}\\
\verb|\OrdinalNumber{\CurrentShift+2}| yields: \OrdinalNumber{\CurrentShift+2}\\
\verb|\OrdinalNumber{\CurrentShift+3}| yields: \OrdinalNumber{\CurrentShift+3}

\medskip\hrule\medskip

Initialize \verb|NextShift|:\smallskip

\verb|\def\NextShift{27}|\def\NextShift{27}\\%
\verb|\NextShift| is defined as \texttt{\meaning\NextShift}.\smallskip

Define \verb|\NextShift| to yield the result of (\verb|\CurrentShift|+1):\smallskip

\verb|\advanceMacro[-\NextShift+\CurrentShift+1]{\NextShift}|%
\advanceMacro[-\NextShift+\CurrentShift+1]{\NextShift}\\
\verb|\NextShift| is defined as \texttt{\meaning\NextShift}.\\
\verb|\OrdinalNumber{\NextShift}| yields: \OrdinalNumber{\NextShift}\\
\verb|\OrdinalNumber{\NextShift+1}| yields: \OrdinalNumber{\NextShift+1}\\
\verb|\OrdinalNumber{\NextShift+2}| yields: \OrdinalNumber{\NextShift+2}\\
\verb|\OrdinalNumber{\NextShift+3}| yields: \OrdinalNumber{\NextShift+3}

\medskip\hrule\medskip

Initialize \verb|\CurrentShift|:\smallskip

\verb|\def\CurrentShift{3}|\def\CurrentShift{3}\\%
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\OrdinalNumber{\CurrentShift}| yields: \OrdinalNumber{\CurrentShift}\\
\verb|\OrdinalNumber{\CurrentShift+1}| yields: \OrdinalNumber{\CurrentShift+1}\\
\verb|\OrdinalNumber{\CurrentShift+2}| yields: \OrdinalNumber{\CurrentShift+2}\\
\verb|\OrdinalNumber{\CurrentShift+3}| yields: \OrdinalNumber{\CurrentShift+3}

\medskip\hrule\medskip

Initialize \verb|NextShift|:\smallskip

\verb|\def\NextShift{\CurrentShift}|\def\NextShift{\CurrentShift}\\%
\verb|\NextShift| is defined as \texttt{\meaning\NextShift}.\smallskip

Define \verb|\NextShift| to yield the result of (\verb|\CurrentShift|+1):\smallskip

\verb|\advanceMacro{\NextShift}|\advanceMacro{\NextShift}\\
\verb|\NextShift| is defined as \texttt{\meaning\NextShift}.\\
\verb|\OrdinalNumber{\NextShift}| yields: \OrdinalNumber{\NextShift}\\
\verb|\OrdinalNumber{\NextShift+1}| yields: \OrdinalNumber{\NextShift+1}\\
\verb|\OrdinalNumber{\NextShift+2}| yields: \OrdinalNumber{\NextShift+2}\\
\verb|\OrdinalNumber{\NextShift+3}| yields: \OrdinalNumber{\NextShift+3}

\end{document}

在此处输入图片描述



\documentclass{article}

\newcommand*\CurrentShift{0}%
\newcommand*\ShiftIndex[1]{%
  \the\numexpr(#1)\relax
  \textsuperscript{\ifcase\the\numexpr(#1)\relax th\or st\or nd\or rd \else th\fi}%
}%
\newcommand*\advanceCurrentShift[1][1]{%
  \edef\CurrentShift{\the\numexpr(\CurrentShift)+(#1)\relax}%
}%
% \advanceCurrentShift can be prefixed with \global.

\parindent=0pt

\begin{document}

\hrule height 0pt\kern-1in

\verb|\def\CurrentShift{0}|\def\CurrentShift{0}\\%
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\ShiftIndex{\CurrentShift}| yields: \ShiftIndex{\CurrentShift}\\
\verb|\ShiftIndex{\CurrentShift+1}| yields: \ShiftIndex{\CurrentShift+1}\\
\verb|\ShiftIndex{\CurrentShift+2}| yields: \ShiftIndex{\CurrentShift+2}\\
\verb|\ShiftIndex{\CurrentShift+3}| yields: \ShiftIndex{\CurrentShift+3}

\medskip\hrule\medskip

\verb|\advanceCurrentShift|\advanceCurrentShift\\
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\ShiftIndex{\CurrentShift}| yields: \ShiftIndex{\CurrentShift}\\
\verb|\ShiftIndex{\CurrentShift+1}| yields: \ShiftIndex{\CurrentShift+1}\\
\verb|\ShiftIndex{\CurrentShift+2}| yields: \ShiftIndex{\CurrentShift+2}\\
\verb|\ShiftIndex{\CurrentShift+3}| yields: \ShiftIndex{\CurrentShift+3}

\medskip\hrule\medskip

\verb|\advanceCurrentShift|\advanceCurrentShift\\
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\ShiftIndex{\CurrentShift}| yields: \ShiftIndex{\CurrentShift}\\
\verb|\ShiftIndex{\CurrentShift+1}| yields: \ShiftIndex{\CurrentShift+1}\\
\verb|\ShiftIndex{\CurrentShift+2}| yields: \ShiftIndex{\CurrentShift+2}\\
\verb|\ShiftIndex{\CurrentShift+3}| yields: \ShiftIndex{\CurrentShift+3}

\medskip\hrule\medskip

\verb|\advanceCurrentShift|\advanceCurrentShift\\
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\ShiftIndex{\CurrentShift}| yields: \ShiftIndex{\CurrentShift}\\
\verb|\ShiftIndex{\CurrentShift+1}| yields: \ShiftIndex{\CurrentShift+1}\\
\verb|\ShiftIndex{\CurrentShift+2}| yields: \ShiftIndex{\CurrentShift+2}\\
\verb|\ShiftIndex{\CurrentShift+3}| yields: \ShiftIndex{\CurrentShift+3}

\medskip\hrule\medskip

\verb|\advanceCurrentShift|\advanceCurrentShift\\
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\ShiftIndex{\CurrentShift}| yields: \ShiftIndex{\CurrentShift}\\
\verb|\ShiftIndex{\CurrentShift+1}| yields: \ShiftIndex{\CurrentShift+1}\\
\verb|\ShiftIndex{\CurrentShift+2}| yields: \ShiftIndex{\CurrentShift+2}\\
\verb|\ShiftIndex{\CurrentShift+3}| yields: \ShiftIndex{\CurrentShift+3}

\medskip\hrule\medskip

\verb|\advanceCurrentShift[5]|\advanceCurrentShift[5]\\
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\ShiftIndex{\CurrentShift}| yields: \ShiftIndex{\CurrentShift}\\
\verb|\ShiftIndex{\CurrentShift-4}| yields: \ShiftIndex{\CurrentShift-4}\\
\verb|\ShiftIndex{\CurrentShift+1}| yields: \ShiftIndex{\CurrentShift+1}\\
\verb|\ShiftIndex{\CurrentShift+2}| yields: \ShiftIndex{\CurrentShift+2}\\
\verb|\ShiftIndex{\CurrentShift+3}| yields: \ShiftIndex{\CurrentShift+3}\\
\verb|\ShiftIndex{\CurrentShift*2}| yields: \ShiftIndex{\CurrentShift*2}

\medskip\hrule\medskip

\verb|\advanceCurrentShift[\numexpr5-10\relax]|\advanceCurrentShift[\numexpr5-10\relax]\\
\verb|\CurrentShift| is defined as \texttt{\meaning\CurrentShift}.\\
\verb|\ShiftIndex{\CurrentShift}| yields: \ShiftIndex{\CurrentShift}\\
\verb|\ShiftIndex{\CurrentShift-4}| yields: \ShiftIndex{\CurrentShift-4}\\
\verb|\ShiftIndex{\CurrentShift+1}| yields: \ShiftIndex{\CurrentShift+1}\\
\verb|\ShiftIndex{\CurrentShift+2}| yields: \ShiftIndex{\CurrentShift+2}\\
\verb|\ShiftIndex{\CurrentShift+3}| yields: \ShiftIndex{\CurrentShift+3}\\
\verb|\ShiftIndex{\CurrentShift*2}| yields: \ShiftIndex{\CurrentShift*2}

\end{document}

在此处输入图片描述

相关内容