PDF ブックマーク内の \ref の自動 \texorpdfstring (セクション タイトル)

PDF ブックマーク内の \ref の自動 \texorpdfstring (セクション タイトル)
\section{Proof of Theorem~\ref{thm:main}}

正しい PDF ブックマークが生成されません (hyperrefパッケージを使用)。

\section{Proof of \texorpdfstring{Theorem~\ref{thm:main}}{Theorem 3.1.7}}

望ましい結果が得られる(\texorpdfstring とヘッダーの設定) ですが、「3.1.7」はハードコードされているため、テキストを再配置するたびにこのコード行を変更する必要があります。

多くの数学式はUnicode表現がないため、PDF文字列(PDFブックマーク)として使用できないことを理解しています(セクションタイトルに数式モードの \texorpdfstring を自動的に追加する)。

しかし、「定理 3.1.7」にはプレーン ASCII シンボルのみが含まれています。したがって、少なくとも理論的には、これに対する自動ソリューションを実装できるはずです。

理想的には、次のように記述できるコードが欲しいです:

\section{Proof of \Cref{thm:main}}

(cleverefパッケージを使用することで、すでに解決策\refも非常に役立ちます)

例:

\documentclass{article}
\usepackage{hyperref}
\usepackage{cleveref}
\newtheorem{theorem}{Theorem}[section]


\begin{document}

    \begin{theorem}\label{thm:main}
        text
    \end{theorem}

many pages

\section{Proof of \Cref{thm:main}}  
\end{document}

(このコードでは正しい PDF ブックマークは生成されません)

(追記: このようなコードをhypperrefまたはcleverefパッケージに含めると本当に素晴らしいと思います)

答え1

\ref の星印付きバージョンを使用できます:

\documentclass{article}
\newtheorem{theorem}{theorem}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\section{Proof of Theorem~\texorpdfstring{\ref{thm:main}}{\ref*{thm:main}}}
\begin{theorem}
  \label{thm:main} some theorem
\end{theorem}
\end{document}

答え2

@Phelype Oleinikは非常に良い解決策にリンクしましたhttps://tex.stackexchange.com/a/485979/128042

\documentclass{article}
\usepackage{hyperref}
\usepackage{cleveref}
\newtheorem{theorem}{Theorem}[section]
\usepackage{crossreftools}

\pdfstringdefDisableCommands{%
    \let\Cref\crtCref
    \let\cref\crtcref
}
\begin{document}

    \begin{theorem}\label{thm:main}
        text
    \end{theorem}

many pages

\section{Proof of \Cref{thm:main}}  
\end{document}

この別の質問に対する解決策セクションタイトルのcleverefリンクを非表示にするこの質問にも完璧に答えます。

ウルリケ・フィッシャーの解https://tex.stackexchange.com/a/504969/128042パッケージを使用できない場合は、優れた代替手段となりますcrossreftools

関連情報