0

I would like to use the command \makefirstuc (from the package mfirstuc) to capitalize the first letter of what is printed by the command \ztitleref (from the package zref). It doesn't work.

Here is my code:

\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}

Here is the result:

enter image description here

Does anyone know why it's not working? Any idea of how to solve the problem?

0

1 Answer 1

3

\makefirstuc has no chance to find the first char if you hide it in a \ul, \mbox, ztitleref.

You need expandable commands, and should put the titlecasing inside. With a current LaTeX (!) you can do this:

\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}

enter image description here

1
  • Wow, thank you Ulrike for this quick response. It's really generous to share your expertise like that. I really appreciate it. It answers my question very well. Have a great day! :)
    – alpagab
    Aug 21, 2022 at 16:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .