Am 28.09.2008 um 22:42 schrieb Mohamed Bana:
Wolfgang Schuster wrote:
Am 28.09.2008 um 19:34 schrieb Mohamed Bana:
Hi everyone,
I finished my thesis, writing both my thesis and my presentation using ConTeXt.
Aditya :). But there's a still something missing that I need before I even
Aditya Mahajan wrote: thinking of typesetting an msc thesis in ConTeXt. I'd like to have something equivelant to the *listings.sty* package; http://thread.gmane.org/gmane.comp.tex.context/15591/focus=15592 or http://vega.soi.city.ac.uk/~abbg770/listing-sample.pdf.
I setup listing first;
\lstset{breaklines=true, showlines=true, % showing line numbers numbers=left, % where to show line numbers numberstyle=\tiny\color{gray}, numbersep=10pt, % stepnumber=1, % how often to show the line number on the left language=Java, % specifiy the language basicstyle=\ttfamily\small, % print whole listing small keywordstyle=\color{eclipsekeyword}\ttfamily\underbar, % underlined bold black keywords identifierstyle=, % nothing happens commentstyle=\color{eclipsecomment}, % white comments, if you use commentstyle=\color{white}, stringstyle=\ttfamily, % typewriter type for strings showstringspaces=false, % no special string spaces frame=single, backgroundcolor=\color{white}, tabsize=4, showspaces=false, showstringspaces=false}
\lstset{morecomment=[s][\color{eclipsejavadoc}]{/**}{*/}}
Includes a file, look at Listing B.2 on the pdf I posted. This should be self explanatory;
\lstinputlisting[ caption={SpreadsheetParser.java}, label=lst:SpreadsheetParser.java] {source/SpreadsheetParser.java}
I can also list inline using the same settings defined in \lstset - but it doesn't break across lines. The choice of charater is arbitrary i.e., I could have chosen to use | instead of !;
\lstinline!matcher(CharSequence input)!
Similar to preceeding, with line breaking. Also I can refer to it using; \ref{lst:freeformlogfile}
\begin{lstlisting}[frame=,label={lst:freeformlogfile},caption={Log File}] import java.util.Arrays;
public class ArrayReallocationDemo {
public static void main(String[] args) { int[] data1 = new int[] { 1, 3, 5, 7, 9 };
printArray(data1); int[] data2 = Arrays.copyOf(data1, 6); data2[5] = 11; printArray(data2);
int[] data3 = Arrays.copyOfRange(data1, 2, 10); printArray(data3); }
// print array elements private static void printArray(int[] data) { StringBuilder stringBuilder = new StringBuilder("["); for (int i = 0; i < data.length; i++) { stringBuilder.append(data[i]); if (i < data.length - 1) stringBuilder.append(", "); } stringBuilder.append("]"); System.out.println(stringBuilder); } } \end{lstlisting}
\setupcolors[state=start]
\definetyping[JAVA][option=JV]
\setuptyping [JAVA] [numbering=line]
\starttext
\startJAVA ... \stopJAVA
\stoptext
or
same preamble as above plus
\definefloat[listing][listings]
\starttext
\placelisting [split] [lst:freeformlogfile] {Log File} {\startJAVA ... \stopJAVA}
\stoptext
Wolfgang
Thanks Wolfgang.
Source; http://pastebin.com/m40986857 Pdf; http://filebin.ca/kceezh/listing.pdf or http://filebin.ca/kceezh
I've still got some issues with it :(. I think I'll just wait till verbatim supports improves.
1. Lines protude into the margin and sometime even go past the end of the page.
\setuptyping [JAVA] [numbering=line, lines=yes] \setuplinenumbering[location=text]
2. Why doesn't it show the line numbers for the empty lines?
Could be a MkII bug because it works with MkIV but here appears a new problem, "location=text" for line numbering is not working. Test file for Hans: % engine=luatex \setuplinenumbering[location=text] \showframe \starttext \startlinenumbering A line of text with the line number. \stoplinenumbering \stoptext
3. Is there a way to supress the 'there is nothing to split' warning?
It's a bug, I will look for a solution (the caption has to be fixed too). Wolfgang