[Tex/LaTex] List of listings – how to add

listingstcolorbox

I have defined listings. How to create a list of listings? I mean something similar to \listoftables. Thank you

\documentclass[12pt,a4paper]{report}   
\usepackage{xcolor}
\usepackage{listings}
\usepackage{caption}

\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\tcbuselibrary{listings}
\newtcbinputlisting[auto counter]{\mylisting}[2][]{listing file={#2},title=Listing,colback=white,colframe=gray!75!black,fonttitle=\bfseries,listing only,breakable,title=Soubor \thetcbcounter: #1}

\renewcommand{\lstlistingname}{Soubor}

\newcommand{\listingsfont}{\ttfamily}   

\begin{document}
\lstinputlisting{code.txt}    
    \end{document}

Best Answer

Here is the tcolorbox - way to generate list of 'something', here list of listings with the settings list type=... and list inside.

The title=... is used by default for inserting the name of the entry.

\tbclistof[\chapter*]{lol}{\lstlistingname} is the tcolorbox - way of saying \listof....

\documentclass[12pt,a4paper]{report}   
\usepackage{xcolor}
%\usepackage{listings}
\usepackage{caption}

\usepackage[most]{tcolorbox}
\newtcbinputlisting[auto counter,list inside=lol,list type={lstlisting}]{\mylisting}[2][]{%
  listing file={#2},
  title=Listing,
  colback=white,
  colframe=gray!75!black,
  fonttitle=\bfseries,
  listing only,
  breakable,
  title=Soubor \thetcbcounter: #2,
  #1
}


\renewcommand{\lstlistingname}{Soubor}

\newcommand{\listingsfont}{\ttfamily}   


\begin{document}
\tcblistof[\chapter*]{lol}{\lstlistingname}
\clearpage
\mylisting{helloworldexample.c}
\end{document}

enter image description here enter image description here

The helloworldexample.c file follows

#include<stdio.h>

int main(int argc,char **argv)
{
  printf("Hello World!\n");
  return(0);
}

Update

\documentclass[12pt,a4paper]{report}   
\usepackage{xcolor}
%\usepackage{listings}
\usepackage{caption}

\usepackage[most]{tcolorbox}
\newtcbinputlisting[auto counter,list inside=lol,list type={lstlisting}]{\mylisting}[3][]{%
  listing file={#3},
  title=Listing,
  colback=white,
  colframe=gray!75!black,
  fonttitle=\bfseries,
  listing only,
  breakable,
  title={Soubor \thetcbcounter: #2},
  #1
}


\renewcommand{\lstlistingname}{Soubor}

\newcommand{\listingsfont}{\ttfamily}   


\begin{document}
\tcblistof[\chapter*]{lol}{\lstlistingname}
\clearpage
\mylisting{Some caption}{helloworldexample.c}
\end{document}
Related Question