我想使用memoir
's\ordinaltoname
来引用枚举块中的特定项。该项用标签命令标记。简单的代码无法编译,显然是因为标签在第一次传递时未定义并且\ordinaltoname
不知道该做什么。考虑以下 MWE:
\documentclass{memoir}
\title{Title}
\author{Author}
\date{\today}
\begin{document}
\frontmatter
\mainmatter
\begin{enumerate}
\item{}\label{por:existence}First point;
\item{}\label{por:defn}Second point;
\item{}\label{por:associativity}Third point.
\end{enumerate}
\ordinaltoname{\ref{por:existence}}
\backmatter
\end{document}
编译后,
[78] Yeah? pdflatex mwe
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
(./mwe.tex
LaTeX2e <2018-04-01> patch level 5
(/usr/local/texlive/2018/texmf-dist/tex/latex/memoir/memoir.cls
Document Class: memoir 2018/04/04 v3.7g configurable book, report, article docu
ment class
(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(/usr/local/texlive/2018/texmf-dist/tex/latex/ifetex/ifetex.sty
(/usr/local/texlive/2018/texmf-dist/tex/plain/ifetex/ifetex.tex))
(/usr/local/texlive/2018/texmf-dist/tex/generic/ifxetex/ifxetex.sty)
(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(/usr/local/texlive/2018/texmf-dist/tex/latex/memoir/mem10.clo))
No file mwe.aux.
! Missing number, treated as zero.
<to be read again>
\protect
l.23 \ordinaltoname{\ref{por:existence}}
?
将标签引用转换为可在序数等命令中使用的数字的正确方法是什么?
答案1
这在本质上类似于用于从数字生成序数词的宏?. 你可以通过使用refcount
的\getrefnumber
,它是可扩展的:
\documentclass{memoir}
\usepackage{refcount}
\begin{document}
\begin{enumerate}
\item \label{por:existence}
First point;
\item \label{por:defn}
Second point;
\item \label{por:associativity}
Third point.
\end{enumerate}
This reference points to the \ordinaltoname{\getrefnumber{por:existence}} element.
\end{document}