[NTG-context] Experience on writing a thesis with MKIV

Mohamed Bana m.bana.lists at gmail.com
Sun Sep 28 19:34:25 CEST 2008


Aditya Mahajan wrote:
> 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 
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}


Thanks guys



More information about the ntg-context mailing list