ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Wolfgang Schuster <schuster.wolfgang@googlemail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Listings
Date: Sun, 28 Sep 2008 23:23:52 +0200	[thread overview]
Message-ID: <B8542EB4-FAEA-4657-9D42-07D9F0B9C238@gmail.com> (raw)
In-Reply-To: <gboq7v$ikq$1@ger.gmane.org>


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).

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
___________________________________________________________________________________


  reply	other threads:[~2008-09-28 21:23 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-27 16:35 Experience on writing a thesis with MKIV Aditya Mahajan
2008-09-28 13:59 ` Hans Hagen
2008-09-28 15:45 ` Mikael Persson
2008-09-28 18:23   ` Hans Hagen
2008-09-28 19:06     ` Mikael Persson
2008-09-28 19:21       ` Aditya Mahajan
2008-09-28 19:34         ` Utopia and Fourier fonts (was: Experience on writing a thesis with MKIV) Wolfgang Schuster
2008-09-29  9:31           ` Mikael Persson
2008-09-29  9:56             ` Utopia and Fourier fonts Wolfgang Schuster
2008-09-29 13:34               ` Mikael Persson
2008-09-29 13:49                 ` Mojca Miklavec
2008-09-29 18:35               ` Mikael Persson
2008-09-29 20:22                 ` Wolfgang Schuster
2008-09-30  6:43                   ` Mikael Persson
2008-10-01 15:43                     ` Mikael Persson
2008-09-29  9:26     ` Experience on writing a thesis with MKIV Mikael Persson
2008-09-28 17:34 ` Mohamed Bana
2008-09-28 18:16   ` Listings (was: Experience on writing a thesis with MKIV) Wolfgang Schuster
2008-09-28 20:42     ` Listings Mohamed Bana
2008-09-28 21:23       ` Wolfgang Schuster [this message]
2008-09-28 22:04         ` Listings Wolfgang Schuster
2008-09-30 16:37     ` Listings (was: Experience on writing a thesis with MKIV) Chen Shen
2008-09-30 17:15       ` Wolfgang Schuster
2008-10-01  3:44         ` Chen Shen
2008-10-02 17:38           ` Chen Shen
2008-09-30 20:35       ` Listings Hans Hagen
2008-10-02 21:27     ` Listings Mohamed Bana
2008-10-03  5:49       ` Listings Peter Münster
2008-10-04  1:11         ` Listings Mojca Miklavec
2008-12-07  2:28 ` Experience on writing a thesis with MKIV Mohamed Bana
2008-12-07  2:50   ` Aditya Mahajan
2008-12-08 23:19     ` Mohamed Bana
2008-12-09  0:40       ` Aditya Mahajan
2008-12-09  1:22         ` Sorting bug in context-alpha (was: Experience on writing a thesis with MKIV) Aditya Mahajan
2008-12-09  2:59         ` Experience on writing a thesis with MKIV Mohamed Bana
2008-12-09  3:26           ` Aditya Mahajan
2008-12-09 18:17             ` Mohamed Bana
2008-12-09 19:36               ` Aditya Mahajan
2008-12-09 21:23                 ` Taco Hoekwater
2008-12-09 21:49                   ` Aditya Mahajan
2008-12-10  9:24                     ` Taco Hoekwater
2008-12-11  2:20                     ` Mohamed Bana
2008-12-11  3:17                       ` Aditya Mahajan
2008-12-15  3:52                         ` Mohamed Bana
2008-12-09 14:18           ` Mojca Miklavec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=B8542EB4-FAEA-4657-9D42-07D9F0B9C238@gmail.com \
    --to=schuster.wolfgang@googlemail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).