4

I used to set section headings in uppercase with the sectsty package \MakeUppercase. But this gives problems when using references in section headings. So how does one do it properly?

Here is a minimal example:

\documentclass{article}

\usepackage{nameref}
\usepackage{sectsty}
\sectionfont{\MakeUppercase}

\begin{document}

\begin{description}
  \item [Keyword\label{key}] This is the description text.
\end{description}

\section{Here it does not work: \nameref{key}}

Here it works: \nameref{key}.

\end{document}
0
3

You need an expandable version of \nameref.

\documentclass{article}

\usepackage{nameref}
\usepackage{sectsty}
\sectionfont{\MakeUppercase}

\makeatletter
\newcommand\enameref[1]{%
  \expandafter\ifx\csname r@#1\endcsname\relax
  ??\typeout{^^JLaTeX Warning: Reference #1 undefined on input line \the\inputlineno}%
  \else
    \expandafter\expandafter\expandafter\@thirdoffive\csname r@#1\endcsname
  \fi
}
\makeatother

\begin{document}

\begin{description}
  \item [Keyword\label{key}] This is the description text.
\end{description}

\section{Here it does not work: \enameref{key}}

Here it works: \nameref{key}.

\end{document}

enter image description here

1
  • Sorry, I must somehow have overlooked your reply. Yes, that works. Now I wonder: why is this not the default definition of nameref? Also, how would I overwrite the default nameref command to use the expandable version instead. I tried to just remove the "e" in your newcommand but that didn't work. – Daniel Oct 7 '17 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.