Como adicionar minhas listagens ao índice?

Como adicionar minhas listagens ao índice?

estou usando othesulaula. Gostaria de adicionar minhas listagens ao índice.

Encontrei uma maneira de fazer isso usando o \addcontentsline{toc}{spsection}{Listings}comando:

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

Mas o problema é que o marcador de PDF correspondente que já foi adicionado é adicionado uma segunda vez devido ao uso deste comando.

Então, talvez eu precise modificar o thesul.clsarquivo.


Editar 1: Desculpe, esqueci o tulhyprefpacote, então não há marcadores com este main.texarquivo. Aqui está o main.texarquivo correto:

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

Edição 2: Aqui está o resultado: insira a descrição da imagem aqui

Mas encontrei uma solução alternativa.

Quando uso o \lstlistoflistingscomando, preciso fazer:

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

Aqui está o 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}

Aqui está o resultado: insira a descrição da imagem aqui

Responder1

Em vez de usar listingsum mecanismo integrado, prefiro definir um novo ambiente flutuante e usá-lo junto com lstlisting(assim como você usa um tablefloat junto com um tabularambiente):

O seguinte funciona sem problemas e fornece os 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}

informação relacionada