在memoir
类中,\part
是用罗马数字计数定义的。但是,memoir
将数字 1 更改为“第一个”或“一个”的选项\ordinaltoname{\getrefnumber{part:label}}
或\numtoname{\getrefnumber{part:label}}
仅适用于阿拉伯数字引用。是否有可能将 \ref{罗马数字} 重新定义为 \ref{阿拉伯数字}?我想在我的部分页面中使用第 I 部分(罗马引用输出)和第 1 部分(阿拉伯引用输出)。
这个答案似乎适用于章节,但是,部分更改章节似乎对我的情况不起作用:当目录使用罗马数字时,如何以计数方式获取章节 \ref?
\documentclass{memoir}% in XeLaTeX
\begin{document}
\part{Introduction}\label{part:intro}
I would like to refer to the part number by the standard Roman number input
for \ref{part:intro} giving the Roman output Part I.
And also by the arabic number input Part 1 with let's say \refarabic
for \numtoname{\refarabic{part:intro}} to obtain the output Part one.
\end{document}
答案1
以下内容不可扩展,但可以为您提供所需的内容:
\documentclass{memoir}
\usepackage{refcount,etoolbox}
\def\partnumbername#1{%
\edef\x{\getrefnumber{#1}}%
\expandafter\numtoname\expandafter{\expandafter\rmntonum\expandafter{\x}}}
\begin{document}
\part{Introduction}\label{part:intro}
Part~\ref{part:intro}.
Part~\getrefnumber{part:intro}.
Part~\partnumbername{part:intro}.
\end{document}
答案2
我一直在苦苦思索这个问题,然后@Werner 想出了一个答案。在苦苦思索的过程中,我首先尝试将引用的罗马数字转换为阿拉伯数字,然后将其排版为名称。第一部分我失败了。我尝试了 Heiko Oberdiek 的章节代码当目录使用罗马数字时,如何以计数方式获取章节 \ref?希望写一个部分版本,但他的原始代码有编译错误。我的微薄尝试毫无进展。
下面是我的代码,其中包括我失败的尝试和@Werner 代码的扩展,以便将罗马部分数字转换为阿拉伯数字,从而提供更多的通用性。
% mempartnoprob.tex SE 588204
\documentclass{memoir}
\usepackage{comment}
\begin{comment}
%%%%%% code based on Heiko Oberdiek SE 80543 which didn't work
\documentclass{report}
\makeatletter
\protected\def\ArabicRomanChapter#1#2{#2}%
\renewcommand*{\thechapter}{%
\ArabicRomanChapter{\arabic{chapter}}{\Roman{chapter}}%
}
\renewcommand*{\p@chapter}{%
\expandafter\expandafter\expandafter
\@p@chapter}
\newcommand*{\@p@chapter}[3]{#2}%
\makeatother
\begin{document}
\tableofcontents
\chapter{My chapter}
\label{chap:my}
See chapter \ref{chap:my}.
\end{document}
\end{comment}
\begin{comment}
%% my code attempts which didn't work
\newcommand*{\rtoaref}[1]{\arabic{\ref{#1}}}
\renewcommand*{\rtoaref}[1]{\arabic{{\ref{#1}}}}
\renewcommand*{\rtoaref}[1]{\expandafter\arabic{\ref{#1}}}
%\renewcommand*{\rtoaref}[1]{\ref{\arabic{#1}}}
\begin{document}
\part{First} \label{apart}
This text is in \ref{apart}.
This text is in \rtoaref{apart}.
\end{comment}
%%%% This code from Werner in answer to the question.
%%\documentclass{memoir}
\usepackage{refcount,etoolbox}
\def\partnumbername#1{%
\edef\x{\getrefnumber{#1}}%
\expandafter\numtoname\expandafter{\expandafter\rmntonum\expandafter{\x}}}
%%%% my extension to get the number ref'd as arabic instead of Roman
\def\partnumberarabic#1{%
\edef\x{\getrefnumber{#1}}%
\expandafter\rmntonum\expandafter{\x}}
\begin{document}
\part{Introduction}\label{part:intro}
Part~\ref{part:intro}.
Part~\getrefnumber{part:intro}.
Part~\partnumbername{part:intro}.
Part~\partnumberarabic{part:intro}.
\end{document}