我想为使用声明的某些类的定理添加 PDF 书签thmtools
,但目前我还没有找到一种完美的方法来实现这一点。
我能想到的最好主意就是在的键\pdfbookmark
中添加命令。但要使它工作,我必须为每个定理获取一个唯一的标识符,大概是使用 的内部命令,但我一直不知道该怎么做。postheadhook
\declaretheorem
thmtools
这当然是可能的,因为thmtools
使用hyperref
能够创建指向中定理的超链接\listoftheorems
,所以可能存在另一种方法来实现我想要的效果,但我找不到它。
一位 MWE 表示:
\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{hyperref}
\usepackage{thmtools}
\declaretheorem[title=Theorem,postheadhook={\pdfbookmark{a_name}{some_identifier}}]{theo}
\begin{document}
\begin{theo}
Continuous maps map quasi-compact sets to quasi-compact sets.
\end{theo}
\newpage
\begin{theo}[Tykhonov]
Cartesian products of compact spaces are compact for the product topology.
\end{theo}
\end{document}
这里,PDF书签被正确创建,但当然都有相同的名称并指向第一定理。
答案1
以下示例使用包bookmark
来更精细地控制书签。它使用hyperref
定理的锚点集(\@currentHref
)。标题存储在\@currentlabelname
包中nameref
(由加载hyperref
)。书签作为子书签添加到当前书签中,之后书签级别不会更改。
包thmtools
将定理标题名称存储在\thmt@thmname
(感谢 Evpok)中,将环境/计数器名称存储在中。这允许在的键中使用\thmt@envname
的定义。从上面的内部宏中获取其数据。\theorembookmark
postheadhook
\declaretheorem
\theorembookmark
示例文件:
\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{hyperref}
\usepackage{bookmark}
\bookmarksetup{open,numbered}
\usepackage{thmtools}
\makeatletter
\newcommand*{\theorembookmark}{%
\bookmark[
dest=\@currentHref,
rellevel=1,
keeplevel,
]{%
\thmt@thmname\space\csname the\thmt@envname\endcsname
\ifx\@currentlabelname\@empty
\else
\space(\@currentlabelname)%
\fi
}%
}
\makeatother
\declaretheorem[title=Theorem, postheadhook=\theorembookmark]{theo}
\declaretheorem[title=Lemma, postheadhook=\theorembookmark]{lemma}
\begin{document}
\section{Section with unnamed theorem}
\begin{theo}
Continuous maps map quasi-compact sets to quasi-compact sets.
\end{theo}
\begin{lemma}
Unnamed lemma.
\end{lemma}
\newpage
\subsection{Subsection with named theorem}
\begin{theo}[Tykhonov]
Cartesian products of compact spaces are compact for the product
topology.
\end{theo}
\subsection{Next subsection with named lemma}
\begin{lemma}[Emma]
Named lemma
\end{lemma}
\end{document}
使用名称作为定理列表
宏\thmt@shortoptarg
包含定理列表的名称。如果未给出可选参数,则将其设置为全名。
\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{hyperref}
\usepackage{bookmark}
\bookmarksetup{open,numbered}
\usepackage{thmtools}
\makeatletter
\newcommand*{\theorembookmark}{%
\bookmark[
dest=\@currentHref,
rellevel=1,
keeplevel,
]{%
\thmt@thmname\space\csname the\thmt@envname\endcsname
\ifx\thmt@shortoptarg\@empty
\else
\space(\thmt@shortoptarg)%
\fi
}%
}
\makeatother
\declaretheorem[title=Theorem, postheadhook=\theorembookmark]{theo}
\declaretheorem[title=Lemma, postheadhook=\theorembookmark]{lemma}
\begin{document}
\listoftheorems
\section{Section with unnamed theorem}
\begin{theo}
Continuous maps map quasi-compact sets to quasi-compact sets.
\end{theo}
\begin{lemma}
Unnamed lemma.
\end{lemma}
\newpage
\subsection{Subsection with named theorem}
\begin{theo}[Tykhonov]
Cartesian products of compact spaces are compact for the product
topology.
\end{theo}
\subsection{Next subsection with named lemma}
\begin{lemma}[Emma]
Named lemma
\end{lemma}
\begin{lemma}[{name=[LoT-Name]{Doc-Name}}]
Named lemma
\end{lemma}
\end{document}
答案2
以下是我的最终解决方案。灵感来自Heiko 的回答,但不依赖于特别指定命令,所有内容都包含在一个方便的\thbookmark
命令中
\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{hyperref}
\usepackage{thmtools}
\usepackage{bookmark}
\makeatletter
\newcommand{\thlabel}[1]{
\thmt@thmname\space\@nameuse{the#1}
\ifx\@currentlabelname\@empty
\else
\space(\@currentlabelname)%
\fi
}
\newcommand{\thbookmark}{\bookmark[dest=\@currentHref,rellevel=1,keeplevel,]{\thlabel{\thmt@envname}}}
\makeatother
\declaretheorem[title=Theorem, postheadhook={\thbookmark}]{theo}
\begin{document}
\section{Section with unnamed theorem}
\begin{theo}
Continuous maps map quasi-compact sets to quasi-compact sets.
\end{theo}
\newpage
\subsection{Subsection with named theorem}
\begin{theo}[Tykhonov]
Cartesian products of compact spaces are compact for the product
topology.
\end{theo}
\end{document}