![如何在 zref 中使用大写字母?](https://linux22.com/image/453763/%E5%A6%82%E4%BD%95%E5%9C%A8%20zref%20%E4%B8%AD%E4%BD%BF%E7%94%A8%E5%A4%A7%E5%86%99%E5%AD%97%E6%AF%8D%EF%BC%9F.png)
我想使用命令\makefirstuc
(来自包)将该命令(来自包)mfirstuc
打印内容的首字母大写。但是不起作用。\ztitleref
zref
这是我的代码:
\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}