Thomas Schuler wrote:

> I've got really big problems in using the listings package in Lyx 1.1.6.fix 3 
> with tetex on my Redhat 7.2 Linuxbox...I would be very grateful if anybody is 
> out there who can give me the final tip...:-)
> 
> I installed the listings package as described but if I want to create an 
> export from the example file (Welcome1.java with listings.lyx, taken from 
> www.lyx.org/help/listings/listings.php3) to PDF or PS, Latex tells me that it 
> has a problem:

This example-file is for the old listings.sty-version.

try the attached one.

Herbert



-- 
http://www.lyx.org/help/
#LyX 1.2 created this file. For more info see http://www.lyx.org/
\lyxformat 220
\textclass article
\begin_preamble
\usepackage{listings}

\newcommand{\lst}[2]{%
    \noindent\rule[-1ex]{\textwidth}{0.3mm}\vspace{-1ex}
    
\lstinputlisting[caption={#2},label={#1},showstringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,%
    
basicstyle=\footnotesize\tt,numbers=left,stepnumber=1,numberstyle=\tiny,xleftmargin=2em,%
    breaklines=true,language=Java]{#1}
    \vspace{1ex}%
}
\end_preamble
\language german
\inputencoding latin1
\fontscheme default
\graphics default
\paperfontsize default
\spacing single 
\papersize Default
\paperpackage a4
\use_geometry 0
\use_amsmath 0
\use_natbib 0
\use_numerical_citations 0
\paperorientation portrait
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\defskip medskip
\quotes_language english
\quotes_times 2
\papercolumns 1
\papersides 1
\paperpagestyle default

\layout Title

Demo for package listings 
\layout Author

Herbert Vo�
\layout Standard

At first we want to see the first Java code for a little program, called
 Welcome (see Listing 
\begin_inset ERT
status Collapsed

\layout Standard

\backslash 
ref{prog1}
\end_inset 

).
\layout Standard


\begin_inset ERT
status Open

\layout Standard

\backslash 
lstinputlisting[caption={My first Java 
Program},label={prog1},showstringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,
    basicstyle=
\backslash 
footnotesize
\backslash 
tt,numbers=left,stepnumber=1,numberstyle=
\backslash 
tiny,xleftmargin=2em,    breaklines=true,language=Java]{Welcome1.java}
\end_inset 


\layout Standard

Another way is to write an own command for the inputlisting, which has a
 better layout.
 This one is called 
\family typewriter 
lst
\family default 
 with 2 parameters:
\layout Enumerate

The filename of the Sourcefile
\layout Enumerate

The caption
\layout Standard


\family typewriter 
\size small 

\backslash 
newcommand{
\backslash 
lst}[2]{% 
\layout Standard


\family typewriter 
\size small 

\backslash 
noindent
\backslash 
rule[-1ex]{
\backslash 
textwidth}{0.3mm}
\backslash 
vspace{-1ex}%
\layout Standard


\family typewriter 
\size small 

\backslash 
lstinputlisting[caption={#2},label={#1},stringspaces=false,frame={tb},%
\layout Standard


\family typewriter 
\size small 
lineskip=-1pt,extendedchars=true,%
\layout Standard


\family typewriter 
\size small 
basicstyle=
\backslash 
footnotesize
\backslash 
tt,labelstep=1,labelstyle=
\backslash 
tiny,indent=2em,%
\layout Standard


\family typewriter 
\size small 
language=Java,breaklines]{#1}
\backslash 
vspace{1ex} }%
\layout Standard


\begin_inset ERT
status Collapsed

\layout Standard

\backslash 
hspace{-1em}
\end_inset 


\family typewriter 
\size small 
} 
\layout Standard
\added_space_top medskip 
Now the listing is called by 
\layout Standard


\family typewriter 

\backslash 
lst{Welcome1.java}{My first Java Program}
\layout Standard

The lst-command creates by default a label which is the filename, here 
\family typewriter 
Welcome1.java
\begin_inset ERT
status Collapsed

\layout Standard
.
\end_inset 


\family default 
 
\layout Standard


\begin_inset ERT
status Collapsed

\layout Standard

\backslash 
lst{Welcome1.java}{My first Java Program}
\end_inset 


\layout Standard

A reference to this listings is therefore no problem, look at listing 
\begin_inset ERT
status Collapsed

\layout Standard

\backslash 
ref{Welcome1.java}
\end_inset 

.
 This reference is set by 
\family typewriter 

\backslash 
ref{Welcome1.java}
\family default 
.
 
\layout Standard

Changing the fontstyle to courier is possible with:
\layout Standard


\family typewriter 
basicstyle=
\backslash 
fontfamily{pcr}
\backslash 
fontseries{m}
\backslash 
selectfont
\backslash 
footnotesize
\layout Standard


\begin_inset ERT
status Open

\layout Standard

\backslash 
lstinputlisting[caption={My first Java 
Program},label={prog1},showstringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,
  basicstyle=
\backslash 
footnotesize
\backslash 
tt,numbers=left,stepnumber=1,numberstyle=
\backslash 
tiny,xleftmargin=2em,    breaklines=true,language=Java]{Welcome1.java}
\end_inset 


\layout Standard

The baselineskip (vertical space) can also be changed.
 As an additional command to the options of 
\family typewriter 
basicstyle
\family default 
 write:
\layout Standard


\family typewriter 

\backslash 
renewcommand
\backslash 
baselinestretch{0.8}
\layout Standard

and the listings becomes:
\layout Standard


\begin_inset ERT
status Open

\layout Standard

\backslash 
lstinputlisting[caption={My first Java 
Program},label={prog1},showstringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,
  basicstyle=
\backslash 
renewcommand
\backslash 
baselinestretch{0.8}
\backslash 
footnotesize
\backslash 
tt,numbers=left,stepnumber=1,numberstyle=
\backslash 
tiny,xleftmargin=2em,    breaklines=true,language=Java]{Welcome1.java}
\end_inset 


\layout Standard

A list of listings is possible with 
\family typewriter 

\backslash 
lstlistoflistings
\family default 
:
\layout Standard


\begin_inset ERT
status Collapsed

\layout Standard

\backslash 
lstlistoflistings
\end_inset 


\the_end

Reply via email to