2

Have the MWE:

\documentclass{article}
\usepackage[backref=page,hypertexnames]{hyperref}
\newcommand{\RNum}[1]{\uppercase\expandafter{\romannumeral #1\relax}}

\begin{document}
    \section{Sec. \RNum{1}}
    \section{Sec. \RNum{2}}
\end{document}

The bookmark in the PDF shows that the numbers are indeed small case (while it should be upper case). How to get it fixed?

  • Is there any reason you provide the section numbers manually? Is it just for the MWE (if so, that is perfectly valid of course)? – Marijn Jul 31 '18 at 10:06
  • @Marijn Actually, in my case, section names are, Type I, Type II etc. So, I have to write Roman numerals in section name. – xxx--- Jul 31 '18 at 11:26
  • I guess you'd need an expandable \uppercase, but \uupercase is not expandable, see tex.stackexchange.com/q/387816/35864. See also tex.stackexchange.com/q/10805/35864 – moewe Jul 31 '18 at 12:05
  • 1
    \documentclass{article} \usepackage{xparse} \usepackage{hyperref} \ExplSyntaxOn \DeclareExpandableDocumentCommand{\RNum}{m}{\int_to_Roman:n{#1}} \ExplSyntaxOff \begin{document} \section{Sec.\ \RNum{1}} \section{Sec.\ \RNum{2}} \end{document} seems to work. – moewe Jul 31 '18 at 12:10
  • 1
    Or from tex.stackexchange.com/a/23492/35864 without LaTeX3 \documentclass{article} \usepackage{hyperref} \makeatletter \newcommand*{\RNum}[1]{\expandafter\@slowromancap\romannumeral #1@} \makeatother \begin{document} \section{Sec.\ \RNum{1}} \section{Sec.\ \RNum{2}} \end{document} – moewe Jul 31 '18 at 12:15
3

You need an expandable version of \RNum so that it appears correctly in the bookmarks. But \uppercase is not expandable (see \expandafter with \uppercase), so you will need the slightly different definition from the LaTeX kernel (see also How can I get Roman numerals in text?, thank you to Marcel Krüger for pointing out that the initial answer had just a verbatim copy of \RNum)

\documentclass{article}
\usepackage{hyperref}

\makeatletter
\let\RNum\@Roman
\makeatother

\begin{document}
    \section{Sec.\ \RNum{1}}
    \section{Sec.\ \RNum{2}}
\end{document}

The bookmarks sidebar shows "Sec. I" and "Sec. II"

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.