1

I am trying to use listings to point to a Java source code file. The file path is different from the Latex document. Below is an example of what I am trying to do, though it doesn't compile it says it can't find the file. How would I point to my file or do the source code files need to be in the root latex folder?

Main.tex

\usepackage{listings}
\usepackage{appendix}

\begin{document}
\input{bibliography.tex}

Appendix.tex

\appendix
\section{Appendix A: Application Code}
\lstinputlisting{/users/<user-directory>/JavaFiles/file.Java}
1
  • I think as a safety feature, you are not allowed to point to parent directories of your tex source file. you could probaly use the import package though
    – Martin H
    Apr 23, 2012 at 18:49

1 Answer 1

3

Normally latex happily reads listings from any directory. For example, this document:

\documentclass{article}
\usepackage{listings}
\usepackage{appendix}
\begin{document}
\appendix
\lstset{language=c}
\section{Appendix A: Application Code}
\lstinputlisting{/usr/include/stdlib.h}
\end{document}

happily typesets 22 pages of GNU stdlib.h on my system.

So one of several things might happen:

  1. You might have a typo in the file path.
  2. The path might have a space - TeX really does not like them.
  3. You might not have permission to read the file.

Try the example above on a Unix system (or an equivalent on a non-Unix one) to see whether listings can read the file which is definitely present and readable.

1
  • There was a typo by me which is annoying and there was a space in one of the folder names fixed and working now though. Thanks
    – sbnarra
    Apr 23, 2012 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .