From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/44395 Path: news.gmane.org!not-for-mail From: Wolfgang Schuster Newsgroups: gmane.comp.tex.context Subject: Re: Listings Date: Mon, 29 Sep 2008 00:04:16 +0200 Message-ID: <036FC29C-0092-431E-8269-46FEA8FD544B@gmail.com> References: <55EB992D-5348-422A-8105-11A2B2726AF7@gmail.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v926) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1222641270 3024 80.91.229.12 (28 Sep 2008 22:34:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 28 Sep 2008 22:34:30 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Mon Sep 29 00:35:27 2008 connect(): Connection refused Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from ronja.vet.uu.nl ([131.211.172.88] helo=ronja.ntg.nl) by lo.gmane.org with esmtp (Exim 4.50) id 1Kk4rP-0005BU-Go for gctc-ntg-context-518@m.gmane.org; Mon, 29 Sep 2008 00:35:27 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 22E681FE4F; Mon, 29 Sep 2008 00:34:23 +0200 (CEST) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 30679-03; Mon, 29 Sep 2008 00:33:24 +0200 (CEST) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 0E8E41FBF9; Mon, 29 Sep 2008 00:33:23 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 9C84D1FBEF for ; Mon, 29 Sep 2008 00:33:21 +0200 (CEST) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 31131-02 for ; Mon, 29 Sep 2008 00:32:42 +0200 (CEST) Original-Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.153]) by ronja.ntg.nl (Postfix) with ESMTP id D33541FE64 for ; Mon, 29 Sep 2008 00:04:19 +0200 (CEST) Original-Received: by fg-out-1718.google.com with SMTP id l26so2346695fgb.8 for ; Sun, 28 Sep 2008 15:04:19 -0700 (PDT) Original-Received: by 10.86.65.9 with SMTP id n9mr3575140fga.55.1222639458951; Sun, 28 Sep 2008 15:04:18 -0700 (PDT) Original-Received: from ?192.168.2.23? (p5B29525B.dip.t-dialin.net [91.41.82.91]) by mx.google.com with ESMTPS id 4sm2678429fge.8.2008.09.28.15.04.17 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 28 Sep 2008 15:04:18 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.926) X-Virus-Scanned: amavisd-new at ntg.nl X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.9 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl X-Virus-Scanned: amavisd-new at ntg.nl Xref: news.gmane.org gmane.comp.tex.context:44395 Archived-At: Am 28.09.2008 um 23:23 schrieb Wolfgang Schuster: > > Am 28.09.2008 um 22:42 schrieb Mohamed Bana: > >> Wolfgang Schuster wrote: >>> Am 28.09.2008 um 19:34 schrieb Mohamed Bana: >>> >>>> 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} >>> >>> \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). Here is a quick and dirty solution, alisghtly modified version of something I wrote two years ago [1]. The code is not ready for documents because the spacing between the lines is wrong. \unprotect \def\dododostarttyping[#1]% {\typingparameter\c!before \ifinsidesplitfloat \setbox\tablecontentbox\vbox\bgroup % added \fi \startpacked % includes \bgroup \dosetuptypelinenumbering{#1}% \initializetyping \startverbatimcolor \expanded{\mktypeblockverbatim{\s!start\currenttyping}{\s!stop \currenttyping}}} \def\dostoptyping#1% hm, currenttyping {\stopverbatimcolor \stoppacked % includes \egroup \ifinsidesplitfloat \egroup % added \dosplitverbatimbox\tablecontentbox \fi \typingparameter\c!after \egroup \dochecknextindentation{\??tp#1}% \dorechecknextindentation} \def\dosplitverbatimbox#1% {\resettsplit \setbox\tsplitcontent\box#1% \handletsplit} \protect [1] http://archive.contextgarden.net/message/20061004.105840.df79ec7f.en.html Regards, Wolfgang ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________