如何使引用计数与罗马页码一起工作?

如何使引用计数与罗马页码一起工作?

有没有办法让以下 MWE 与罗马页码一起使用?

\documentclass{article}
\usepackage{refcount}
\newcounter{mycount}
\begin{document}
%\pagenumbering{roman}
\stepcounter{mycount}
\label{test:page:\themycount}
\refused{test:page:\themycount}
\ifodd\getpagerefnumber{test:page:\themycount}
ODD
\else
EVEN
\fi
\end{document}

使用罗马页码时,出现以下错误:

! Missing number, treated as zero.
<to be read again>
                   i
l.9 \ifodd\getpagerefnumber{test:page:\themycount}

编辑:

根据 egreg 的评论,以下内容在文本上下文中有效,但在编程上下文中再次失败:

\documentclass{article}
\usepackage[user,abspage]{zref}
\newcounter{mycount}
\begin{document}
\pagenumbering{roman}
\stepcounter{mycount}
\zlabel{test:page:\themycount}
\zrefused{test:page:\themycount}
\zref[abspage]{test:page:\themycount}
% \ifodd\zref[abspage]{test:page:\themycount}
% ODD
% \else
% EVEN
% \fi
\end{document}

答案1

\ifodd期望扩展为数字的内容。 的文档用或zref标记可扩展宏:expexp2

\documentclass{article}
\usepackage[user,abspage]{zref}
\newcounter{mycount}
\begin{document}
\pagenumbering{roman}
\stepcounter{mycount}
\zlabel{test:page:\themycount}
\zrefused{test:page:\themycount}
\zref[abspage]{test:page:\themycount}

\makeatletter
\ifodd\zref@extractdefault{test:page:\themycount}{abspage}{0}\relax
  ODD
\else
  EVEN
\fi
\makeatother

\end{document}

结果

模块thepage提供属性pagevalue,即页码作为数字值。以下示例将其与一些宏定义一起使用。\thepage如果 的奇数\thepage与绝对页码的奇数不同步,它也会起作用并检测 的奇数。

\documentclass{article}
\usepackage{zref-thepage}% defines property pagevalue

\newcounter{mycount}
\renewcommand*{\themycount}{\the\value{mycount}}

\makeatletter
\newcommand*{\myzpagelabel}[1]{%
  \zref@labelbyprops{#1}{pagevalue}%
}
\newcommand*{\ifzpageodd}[1]{%
  \zref@refused{#1}%
  \ifodd\zref@extractdefault{#1}{pagevalue}{0} %
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
\makeatother

\begin{document}
\pagenumbering{roman}

\stepcounter{mycount}
\myzpagelabel{test:page:\themycount}

Page number \thepage\ is %
\ifzpageodd{test:page:\themycount}{odd}{even}.

\end{document}

结果

相关内容