Using the listings package, I am trying to input a Java source file into my document using a specified, user-defined style.
This works just fine if I have the specified style definition in the same document. However, I wish to save the style so that I can use it without having the definition directly in my document.
Section 2.4.1 of the listings manual sounded promising, so I attempted to save my style in a file called listings-java.prf in the same directory as the listings.cfg file itself. I then added \input{listings-java.prf} at the bottom of listings.cfg. However, when I try to use the style, I get an error saying that it cannot load the requested style for whatever reason. It's the same error I get if I try to specify a style that doesn't exist, so I assume that it is not even trying to read my file or else my file incorrectly written/specified/otherwise linked to.
The guide says to ensure the file is located within TeX's search path, and I assume that the directory containing listings.cfg is in that path, which is why I placed it there.
What am I doing wrong, and how can I fix it?
EDIT: Following the suggestion in comments, I have shifted my \input command up a line, directly before the \endinput command in listings.cfg. Now, I get the following error (despite listings-java.prf being in the same directory):
(E:\non-modeling\LaTeX\tex\latex\listings\listings.sty
(E:\non-modeling\LaTeX\tex\latex\listings\lstmisc.sty)
(E:\non-modeling\LaTeX\tex\latex\listings\listings.cfg
! LaTeX Error: File `listings-java.prf' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: prf)
So it would appear that the same directory does not count as being in TeX's search path. How can I add it?
When I manually input the absolute path to the file, it proceeds to read it, but then tells me that \definecolor is an undefined control sequence. I tried adding \usepackage{xcolor} to the top of the file, but then I get errors about that package already being in use (because I also have it at the top of my document file). Can this be fixed, or do I need to inline all references to the defined colors?
Here's listings-java.prf:
\definecolor{bg}{RGB}{25,25,25} % code background color
\definecolor{fg}{RGB}{166,166,166} % code foreground color
\definecolor{kw}{RGB}{194,77,67} % keyword color
\definecolor{ct}{RGB}{80,84,79} % comment color
\definecolor{st}{RGB}{185,185,114} % string color
\definecolor{cs}{RGB}{248,248,242} % classname color
\definecolor{hl}{RGB}{71,148,99} % highlighting color
\definecolor{at}{RGB}{253,151,31} % annotation color
\lstdefinestyle{Java}{
language=Java, % choose the language of the code
basicstyle=\footnotesize % the style of the fonts that are used for the code
\ttfamily
\color{fg},
numbers=left, % where to put the line-numbers
numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers
stepnumber=1, % the step between two line-numbers. If it is 1 each line will be numbered
numbersep=5pt, % how far the line-numbers are from the code
backgroundcolor=\color{bg}, % choose the background color
showspaces=false, % don't show spaces by adding particular underscores
showstringspaces=false, % don't underline spaces within strings
showtabs=false, % don't show tabs within strings by adding particular underscores
frame=single, % adds a frame around the code
rulecolor=\color{BrickRed},
tabsize=2, % sets default tabsize to 2 spaces
captionpos=b, % sets the caption-position to bottom
keywordstyle=\color{kw}\bf, % the style of the font used for keywords
commentstyle=\color{ct}, % the style of the font used for comments
stringstyle=\color{st}, % the style of the font used for strings
breaklines=true, % sets automatic line breaking
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
escapeinside=\`\`, % if you want to jump out to LaTeX within the code
moredelim=**[is][\color{hl}\bf]{@@}{@@} % delimeters for highlighting pieces of code
}
I get the same error even if I remove all information concerning color and have only the style definition in the file.
Here's listings.cfg:
%%
%% This is file `listings.cfg',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% lstdrvrs.dtx (with options: `config')
%%
%% The listings package is copyright 1996--2004 Carsten Heinz, and
%% continued maintenance on the package is copyright 2006--2007 Brooks
%% Moses. From 2013 on the maintenance is done by Jobst Hoffmann.
%% The drivers are copyright 1997/1998/1999/2000/2001/2002/2003/2004/2006/
%% 2007/2013 any individual author listed in this file.
%%
%% This file is distributed under the terms of the LaTeX Project Public
%% License from CTAN archives in directory macros/latex/base/lppl.txt.
%% Either version 1.3 or, at your option, any later version.
%%
%% This file is completely free and comes without any warranty.
%%
%% Send comments and ideas on the package, error reports and additional
%% programming languages to Jobst Hoffmann at <j.hoffmann@fh-aachen.de>.
%%
\ProvidesFile{listings.cfg}[2014/03/04 1.5c listings configuration]
\def\lstlanguagefiles
{lstlang0.sty,lstlang1.sty,lstlang2.sty,lstlang3.sty}
\lstset{defaultdialect=[R/3 6.10]ABAP,
defaultdialect=[2005]Ada,
defaultdialect=[68]Algol,
defaultdialect=[gnu]Awk,
defaultdialect=[ANSI]C,
defaultdialect=[light]Caml,
defaultdialect=[1985]Cobol,
defaultdialect=[WinXP]command.com,
defaultdialect=[ISO]C++,
defaultdialect=[95]Fortran,
defaultdialect=[5.2]Mathematica,
defaultdialect=[OMG]OCL,
defaultdialect=[Standard]Pascal,
defaultdialect=[67]Simula,
defaultdialect=[plain]TeX,
defaultdialect=[97]VRML}
\lstalias[]{TclTk}[tk]{tcl}
\lstalias[6.1]{ABAP}[R/3 6.10]{ABAP}
\lstalias[3.1]{ABAP}[R/3 3.1C]{ABAP}
\lstalias[4.6]{ABAP}[R/3 4.6C]{ABAP}
\input{listings-java.prf}
\endinput
%%
%% End of file `listings.cfg'.