# Too many bookmarks for hyperref and xpatch [duplicate]

I use a lot of "Lists of" in my document, some of them are generated by \listoftheorems. To include these lists in my PDF-bookmarks, I use this answer.

But actually this crashes, when too many bookmarks are produced.

\documentclass{article}

\usepackage{thmtools}
\usepackage{xpatch}
\xpatchcmd{\listoftheorems}{\@fileswfalse}{}{\typeout{yes}}{\typeout{no}}

\declaretheorem{theorem}

\usepackage{hyperref}

\begin{document}

\tableofcontents
\tableofcontents
\tableofcontents
\tableofcontents
\tableofcontents
\tableofcontents
\tableofcontents
\tableofcontents
\tableofcontents
\tableofcontents
\tableofcontents
%\tableofcontents %causes crash
\listoftheorems

text

\end{document}

• you get an error also without the patch. Why are you trying to create so many table of contents, is it only for the example? – Ulrike Fischer Feb 27 at 12:47
• Yes, this is only for the MWE. – Ben Feb 27 at 14:00