¿Cómo agregar mis listados a la tabla de contenido?

¿Cómo agregar mis listados a la tabla de contenido?

estoy usando elthesulclase. Me gustaría agregar mis listados a la tabla de contenido.

Encontré una manera de hacerlo usando el \addcontentsline{toc}{spsection}{Listings}comando:

\tableofcontents
\listoffigures
\listoftables
\lstlistoflistings
\addcontentsline{toc}{spsection}{Listings}

Pero el problema es que el marcador PDF correspondiente que ya se agregó se agrega por segunda vez debido al uso de este comando.

Entonces, tal vez necesite modificar el thesul.clsarchivo.


Edición 1: Lo siento, olvidé el tulhyprefpaquete, por lo que no hay marcadores con este main.texarchivo. Aquí está el main.texarchivo correcto:

\documentclass{thesul}
\usepackage{tulhypref} % for bookmarks
\usepackage{listings} % for \lstlistoflistings
\begin{document}
    \tableofcontents
    \listoffigures
    \listoftables
    \lstlistoflistings
    \addcontentsline{toc}{spsection}{Listings}
    \chapter{My first chapter}

    Hello, this is my first chapter.

    \section{My first section}

    Hello, this is my first section.

    \begin{lstlisting}
echo "hello world";
    \end{lstlisting}
\end{document}

Edición 2: Aquí está el resultado: ingrese la descripción de la imagen aquí

Pero encontré una solución.

Cuando uso el \lstlistoflistingscomando, necesito hacer:

\hypersetup{bookmarksdepth=-1}
\lstlistoflistings
\hypersetup{bookmarksdepth}

Aquí está el código completo:

\documentclass{thesul}
\usepackage{tulhypref} % for bookmarks
\usepackage{listings} % for \lstlistoflistings
\begin{document}
    \tableofcontents
    \listoffigures
    \listoftables
    \hypersetup{bookmarksdepth=-1} % add this line (to disable bookmarks)
    \lstlistoflistings
    \hypersetup{bookmarksdepth} % add this line (to enable bookmarks)
    \addcontentsline{toc}{spsection}{Listings}
    \chapter{My first chapter}

    Hello, this is my first chapter.

    \section{My first section}

    Hello, this is my first section.

    \begin{lstlisting}
echo "hello world";
    \end{lstlisting}
\end{document}

Aquí está el resultado: ingrese la descripción de la imagen aquí

Respuesta1

En lugar de usar listingsun mecanismo incorporado, prefiero definir un nuevo entorno flotante y usarlo junto con lstlisting(tal como se usa un tableflotante junto con un tabularentorno):

Lo siguiente funciona sin problemas y da los resultados esperados:

\documentclass{thesul}
\usepackage{tulhypref} % for bookmarks
\usepackage{listings} % for \lstlistoflistings

\usepackage{newfloat}
\DeclareFloatingEnvironment[
  fileext = lol ,
  listname = {List Of Listings} ,
  name = Listing
]{listing}

\begin{document}

\tableofcontents
\listoffigures
\listoftables
\listoflistings

\chapter{My first chapter}
Hello, this is my first chapter.

\section{My first section}
Hello, this is my first section.

\begin{listing}
  \begin{lstlisting}
echo "hello world";
  \end{lstlisting}
  \caption{My listing's caption.}
\end{listing}

\end{document}

información relacionada