LaTexのセクション見出しでローマ数字を使用するとエラーが発生する

Aug 24 2020

ローマ数字を使用して、ラテックスドキュメントの一部のセクションを列挙したいと思います。

私はこれを使用します:\MakeUppercase{\romannumeral 2}数字を作成します。これは通常のテキストでは正常に機能しますが、セクションまたはサブセクションコマンドで使用しようとすると、セクション見出しに数字が正しく表示されているように見えても、「未定義の制御シーケンス」エラーが発生します。

\MakeUppercaseコマンドだけでは\romannumeral 2エラーが発生しないため、明らかに問題はコマンドにあります。

私も\newcommand同じ効果でを定義しようとしました。

なぜそうなるのか誰かが知っていますか?

編集:最小限の再現可能な例を作成した後、問題はhyperrefパッケージに関係していることがわかりました。

\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}

\usepackage{hyperref}

\newcommand{\RomanNumeralCaps}[1]{\MakeUppercase{\romannumeral #1}}

\begin{document}

\chapter{Some chapter}
\section{Some section}
\subsection{Experiment \MakeUppercase{\romannumeral 1}}
\MakeUppercase{\romannumeral 1}
\RomanNumeralCaps{2}

\end{document}

回答

2 samcarter_is_at_topanswers.xyz Aug 25 2020 at 16:02

PDFブックマークの代替文字列を指定できます。

\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}

\usepackage{romannum}% for approach #1 and #2
\usepackage{biblatex}% for approach #3
\usepackage{hyperref}


\begin{document}

\chapter{Some chapter}
\section{Some section}
\subsection{Experiment \texorpdfstring{\Romannum{1}}{I}}

or

\subsection[Experiment II]{Experiment \Romannum{2}}

or

\subsection{Experiment \RN{3}}

However with this approach the III will be replaced by 3 in the pdf bookmarks

\end{document}