4

I would like to add PDF bookmarks for some classes of theorems declared using thmtools and I couldn't find a beautiful way to do it so far.

The best idea I have been able to come up with was to add \pdfbookmark commands to the postheadhook key of \declaretheorem. But for this to work I have to get a unique identifier for each theorem, presumbably using an internal command from thmtools and I have not been able to figure out how.

This is most certainly possible, since thmtools used with hyperref is able to create hyperlinks to the theorems in \listoftheorems, so there could lie another way to do what I want, but I can't find it.

A 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}

Here, PDF bookmarks are correctly created, but of course have all the same name and point to the first theorem.

2
  • How about you post a minimal working example (MWE) containing your current usage so the community has something to play with?
    – Werner
    Jul 10 '13 at 15:57
  • If you want to apply it to specific classes of theorems, say definition, you could use something like uidDefinition\theHdefinition as your unique identifier. \theHdefinition is the expandable representation of the theorem number as used by hyperref. It's not guaranteed to be unique, but pretty much the best shot you get. Jul 10 '13 at 16:13
5

The following example uses package bookmark for finer control of the bookmark. It uses the anchor hyperref sets for the theorem (\@currentHref). And the title is stored in \@currentlabelname by package nameref (loaded by hyperref). The bookmark is added as child to the current bookmark and the bookmark level is not changed afterwards.

Package thmtools stores the theorem title name in \thmt@thmname (thanks Evpok) and the environment/counter name in \thmt@envname. That allows the definition of \theorembookmark for use in key postheadhook of \declaretheorem. \theorembookmark gets its data from the internal macros above.

Example file:

\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}

Result

Using the name for the list of theorems

Macro \thmt@shortoptarg contains the name for the list of theorems. It is set to the full name if the optional argument is not given.

\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}

Result

9
  • There seem to be no need to define \theoremname, you can use \thmt@thmname for that.
    – Evpok
    Jul 10 '13 at 18:44
  • @Evpok: Thanks, that allows me together with \thmt@envname to put the bookmark code in macro \theorembookmark, see the edited question. Jul 10 '13 at 22:56
  • So our answers are essentially the same :) let's keep it that way.
    – Evpok
    Jul 10 '13 at 23:13
  • Is it possible to modify this solution, so the bookmarks contain the same strings as in \listoftheorems, i.e. the optional name of the theorem – if present – is used? That would be the ideal solution for me :-)
    – JBantje
    May 24 '15 at 13:43
  • 1
    @JBantje See updated answer. May 24 '15 at 14:29
1

Here is my final solution. Drawing inspiration from Heiko's answer, but not relying on ad hoc commands, everything wrapped in a convenient \thbookmark command

\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}

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.