# Hyperref bookmarks for unnumbered sections

I'm using titlesec to format subsections so that they are not numbered (as opposed to using the usual starred variant \subsection*) and using hyperref to get bookmarks with section numbers in the resulting PDF file. The bookmarksnumbered option to hyperref does not know the titlesec formatting, so the bookmarks for subsections are coming out numbered, though…

Question: is there a way to get titlesec and hyperref to play nice to each other so that these numbers are omitted from the PDF bookmarks?

This little example

\documentclass{article}
\usepackage[
bookmarksnumbered,
bookmarksdepth=2
]{hyperref}
\usepackage{titlesec}

\titleformat{\subsection}
{\Large}
{}
{0pt}
{}
{}

\begin{document}
\section{First Section}
\subsection{First subsection}
\subsection{Second subsection}
\section{Second Section}
\subsection{First subsection}
\subsection{Second subsection}
\end{document}


gets you this:

• My approach has generally been to use the starred form and then use hyperref's pdfbookmark. Is there a particular reason you don't want the starred form? Aug 10 '20 at 0:57
• @Teepeemm, mostly because I really prefer to be able to change the output without having to change the markup. Aug 10 '20 at 14:32

\documentclass{article}
\usepackage[
bookmarksnumbered,
bookmarksdepth=2
]{hyperref}
\usepackage{titlesec}

\titleformat{\subsection}
{\Large}
{}
{0pt}
{}
{}

\begin{document}
\tableofcontents
\section{First Section}
\subsection{First subsection}
\subsection{Second subsection}
\section{Second Section}
\subsection{First subsection}
\subsection{Second subsection}
\end{document}


So why don't you simply change secnumdepth? Then everything will be numbered in the same way:

\documentclass{article}
\usepackage[
bookmarksnumbered,
bookmarksdepth=2
]{hyperref}
\setcounter{secnumdepth}{1}
\begin{document}
\tableofcontents
\section{First Section}
\subsection{First subsection}
\subsection{Second subsection}
\section{Second Section}
\subsection{First subsection}
\subsection{Second subsection}
\end{document}


• Well, my tocdepth is such that subsections do not show up in the toc ;-) Aug 10 '20 at 14:25
• your bookmark-tocdepth is not -- that's why you are asking the question don't you? Aug 10 '20 at 14:27