In a document embedding java code (actually processing) I can successfully embed listings using:


In an attempt to increase convenience, I wrote a new command that abbreviates this to:



This works fine. However, in many instances it would be better to keep the listing external. This should be:


which I abbreviate:



Both formulations result in the following error:

! Undefined control sequence.
l.160 \incjava

While on the subject, is there any way to define a standard directory to avoid having to repeatedly refer to code/openglprocessing, in a similar manner to the graphics path for \includegraphics?

\graphicspath{ {img/} }
  • Advice: Define a macro for the editor instead of LaTeX, the source code will be much more readable that way. – Johannes_B Jun 7 '15 at 12:50

Instead of \java, I would define an environment java. Then the \begin and \end macros are properly matched in the source code, also making some TeX editors happy. Such an environment is defined by \lstnewenvironment of package listings. Also an optional argument is added. Then the user can set some options in \begin{java}[...] for a particular listings.

The \incjava command should work as is does in the following example. Also this macro is given an optional argument for options to the particular listings.




public class Example implements StringHandler {

     * Prints the given string.
     * @param s  the given string
    public void handle(String s) {




There is no \listingspath for listing files, but \input@path for TeX files can be defined, e.g.:


Each entry should be surrounded by curly braces and end with the directory separator.

Another variant is setting the environment variable TEXINPUTS to include the directory, example for TeX Live/Linux:


The colon (Unix) or semicolon (Windows) at the beginning is important, because then the previous search path (from texmf.cnf) is added at this place.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.