# Cannot use a different directory for lstinputlisting

I'm having a bit of a problem. I'm trying to include source code in an appendix in latex. I use the following line in order to add the source code:

\lstinputlisting[language=C]{"C:\work\EA10080\trunk\Programming\Secondary_side\full_function\Submodules\ePWM.c"}


but I get the following error:

398 Undefined control sequence. \lst@inputpath "C:\work \EA 10080\trunk \Programming \Secondary _... l.398 ...ry_side\full_function\Submodules\ePWM.c"}

What am I doing wrong? I'm using the package listing, color and the document class is report.

Minimal working example:

\documentclass[12pt,a4paper]{report}

\usepackage{listings}
\usepackage{color}

\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}

\begin{document}

\begin{appendices}
\chapter{Source Code for PWM}
\label{sec:A}

\lstinputlisting[language=C]{"C:\work\EA10080\trunk\Programming\Secondary_side\full_function\Submodules\ePWM.c"}

\end{appendices}

\end{document}


Also, maybe I should mention that adding the source code "manually" (using \begin{listing} and then writing the code) works fine. It's much less practical though.

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Apr 22 '14 at 6:23
• The problem is probably having a lot of \  characters in your path and _ characters as well. – user31729 Apr 22 '14 at 6:25
• I just tried that but got the following error: " 398 LaTeX Error: There's no line here to end. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.398 ...side\\full_function\\Submodules\\ePWM.c"} " – Christian Apr 22 '14 at 6:31
• Unusual idea: Replace all \\  characters in your path by /, but keep \_. such as \lstinputlisting[language=C]{"C:/Work/EA10080/ etc} – user31729 Apr 22 '14 at 6:33
• Yeah. I just had that idea too. I tried it and it worked perfectly. Thanks a lot for the help. – Christian Apr 22 '14 at 6:35

Changing \ to / should work!

\documentclass[12pt,a4paper]{report}

\usepackage{listings}
\usepackage{color}

\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}

\begin{document}

\begin{appendices}
\chapter{Source Code for PWM}
\label{sec:A}

\lstinputlisting[language=C]{"C:/work/EA10080/trunk/Programming/Secondary_side/full_function/Submodules/ePWM.c"}

\end{appendices}

\end{document}

• The _ characters occuring in the pathname are probably still a source of complaints – user31729 Apr 22 '14 at 6:37
• @ChristianHupfer: I don't think so. :-) – kiss my armpit Apr 22 '14 at 6:38
• Are _ characters in pathnames converted by listings such as not being interpreted as starting an subscript? Is the activeness of _ changed? – user31729 Apr 22 '14 at 6:42
• @ChristianHupfer: I have tried my code above and there is no problem with _ (underscore). The internal details are beyond my understanding. :-) – kiss my armpit Apr 22 '14 at 6:45
• Well, anyway, if it works it is good to know (for all working on Windows ;-) – user31729 Apr 22 '14 at 6:46