# How to hide path in lstlistoflistings?

When I am making a list of listings in my latex report, using:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstset{language = Matlab,
inputpath=./Code/}

\begin{document}

\lstlistoflistings
\lstinputlisting{test1.m}
\lstinputlisting{test2.m}
\lstinputlisting{test3.m}

\end{document}


the paths of my files are displayed:

How can I hide the path? I would like to obtain:

without moving my files into the current directory.

## 1 Answer

Option caption enhances the listing with a caption, whose title is also used for the entry in the list of listings:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstset{language = Matlab, inputpath=./Code/}

\begin{document}

\lstlistoflistings
\lstinputlisting[caption=test1.m]{test1.m}
\lstinputlisting[caption=test2.m]{test2.m}
\lstinputlisting[caption=test3.m]{test3.m}

\end{document}


The caption can be suppressed for the document by an empty mandatory argument for key caption. The optional argument in square brackets denotes the title for the entry in the list of listings:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstset{language = Matlab, inputpath=./Code/}

\begin{document}

\lstlistoflistings
\lstinputlisting[caption={[test1.m]{}}]{test1.m}
\lstinputlisting[caption={[test2.m]{}}]{test2.m}
\lstinputlisting[caption={[test3.m]{}}]{test3.m}

\end{document}


• Thank you very much, it works well. I still have another problem with the caption though: for a file called "test_name.m", the command \lstinputlisting{test_name.m} works but neither \lstinputlisting[caption={[test_name.m]{}}]{test_name.m} nor \lstinputlisting[caption={[test\_name.m]{}}]{test_name.m} work. How can I add the underscore character? – fidekild Jul 5 '16 at 19:22
• @fidekild put the filename in " " – naphaneal Jul 5 '16 at 19:40
• @fidekild \_ (or \textunderscore) in the value of caption works. – Heiko Oberdiek Jul 5 '16 at 19:55
• @HeikoOberdiek Thank you, it now works perfectly. – fidekild Jul 5 '16 at 23:33