如何在 zref 中使用大写字母?

如何在 zref 中使用大写字母?

我想使用命令\makefirstuc(来自包)将该命令(来自包)mfirstuc打印内容的首字母大写。但是不起作用。\ztitlerefzref

这是我的代码:

\documentclass{article}

\usepackage[user,titleref]{zref}
\usepackage{soul}
\usepackage{mfirstuc}

\newcommand{\saveRef}[2]{%
    \ztitlerefsetup{title={#2}}\zlabel{#1}
}

\newcommand{\printRef}[1]{%
    The \ul{\mbox{\ztitleref{#1}}} is on page \zpageref{#1}.
}

\newcommand{\printRefUpper}[1]{%
    The \makefirstuc{{\ul{\mbox{\ztitleref{#1}}}}} is on page \zpageref{#1}.
}

\begin{document}

\saveRef{first}{first title saved}
\saveRef{second}{second title saved}

Print \textbackslash ztitleref normally (it works) :

\printRef{first}

\printRef{second}

\bigskip Print \textbackslash ztitleref with uppercase on first letter (it does not work) :

\printRefUpper{first}

\printRefUpper{second}

\end{document}

结果如下:

在此处输入图片描述

有人知道为什么它不起作用吗?有办法解决这个问题吗?

答案1

\makefirstuc如果将第一个字符隐藏在\ul,,中\mbox,则没有机会找到它ztitleref

您需要可扩展的命令,并且应该将标题放在里面。使用当前的 LaTeX (!),您可以执行以下操作:

\documentclass{article}

\usepackage[user,titleref]{zref}
\usepackage{soul}

\newcommand{\saveRef}[2]{%
    \ztitlerefsetup{title={#2}}\zlabel{#1}}

\makeatletter
\newcommand\mytitleref[1]{\zref@extractdefault{#1}{title}{??}}
\makeatother
\AddToNoCaseChangeList{\mytitleref}

\soulregister\MakeTitlecase{1}

\newcommand{\printRef}[1]{%
    The \ul{\mbox{\ztitleref{#1}}} is on page \zpageref{#1}.}

\newcommand{\printRefUpper}[1]{%
    The \ul{\MakeTitlecase{\mytitleref{#1}} is on page \mbox{\zpageref{#1}}.}}


\begin{document}

\saveRef{first}{first title saved}
\saveRef{second}{second title saved}

Print \textbackslash ztitleref normally (it works) :

\printRef{first}

\printRef{second}

\bigskip Print \textbackslash ztitleref with uppercase on first letter:

\printRefUpper{first}

\printRefUpper{second}

\end{document}

在此处输入图片描述

相关内容