| 1 |
%% |
| 2 |
%% This is file `examples.tex', |
| 3 |
%% generated with the docstrip utility. |
| 4 |
%% |
| 5 |
%% The original source files were: |
| 6 |
%% |
| 7 |
%% jvlisting.dtx (with options: `examples') |
| 8 |
%% |
| 9 |
%% Copyright (C) 2011 Jochen Voss <[email protected]> |
| 10 |
%% |
| 11 |
%% This work may be distributed and/or modified under the conditions of |
| 12 |
%% the LaTeX Project Public License, either version 1.3 of this license |
| 13 |
%% or (at your option) any later version. The latest version of this |
| 14 |
%% license is in |
| 15 |
%% |
| 16 |
%% http://www.latex-project.org/lppl.txt |
| 17 |
%% |
| 18 |
%% and version 1.3 or later is part of all distributions of LaTeX version |
| 19 |
%% 2005/12/01 or later. |
| 20 |
%% |
| 21 |
%% This work has the LPPL maintenance status `maintained' and the current |
| 22 |
%% Maintainer of this work is Jochen Voss <[email protected]>. |
| 23 |
%% |
| 24 |
%% This work consists of the files jvlisting.dtx, test.tex and the |
| 25 |
%% derived files jvlisting.sty, jvlisting.ins and examples.tex. |
| 26 |
|
| 27 |
\documentclass{article} |
| 28 |
|
| 29 |
\usepackage[text={6in,9in},centering]{geometry} |
| 30 |
\usepackage{jvlisting} |
| 31 |
\setlength{\listingskipamount}{2\baselineskip} |
| 32 |
|
| 33 |
\begin{document} |
| 34 |
|
| 35 |
\begin{listing} |
| 36 |
def cumsum(iterable): |
| 37 |
return reduce(lambda res, x: res+[res[-1]+x], iterable, [0])[1:] |
| 38 |
\end{listing} |
| 39 |
|
| 40 |
\newcounter{lineno} |
| 41 |
\newcommand{\typesetnline}[1]{\addtocounter{lineno}{1}% |
| 42 |
\noindent\hskip\listingindent\llap{{\it\scriptsize\arabic{lineno}: }}% |
| 43 |
\strut #1\par\penalty\listingpenalty} |
| 44 |
\NewListingEnvironment{nlisting}{0}{\prelistingskip}% |
| 45 |
{\setcounter{lineno}{0}\listingfont}{\typesetnline}{\postlistingskip} |
| 46 |
\begin{nlisting} |
| 47 |
for i in [1, 2, 3]: |
| 48 |
for j in ['a', 'b', 'c']: |
| 49 |
print str(i)+j |
| 50 |
\end{nlisting} |
| 51 |
|
| 52 |
\newwrite\outfile |
| 53 |
\newcommand{\copytypeset}[1]{\ListingTypesetLine{#1}% |
| 54 |
{\DisableLigatureFix\immediate\write\outfile{#1}}} |
| 55 |
\NewListingEnvironment{copylisting}{1}{\prelistingskip}% |
| 56 |
{\immediate\openout\outfile=#1\listingfont}{\copytypeset}% |
| 57 |
{\immediate\closeout\outfile\postlistingskip} |
| 58 |
|
| 59 |
\begin{copylisting}{listing1.c} |
| 60 |
#include <stdio.h> |
| 61 |
|
| 62 |
int |
| 63 |
main() |
| 64 |
{ |
| 65 |
puts("hello, world!"); |
| 66 |
return 0; |
| 67 |
} |
| 68 |
\end{copylisting} |
| 69 |
|
| 70 |
\newcommand{\pfxtypeset}[1]{\noindent\hskip\listingindent\strut |
| 71 |
\pfx#1\par\penalty\listingpenalty} |
| 72 |
\NewFileListingCommand{\prefixfilelisting}{2}{\prelistingskip}% |
| 73 |
{\listingfont\def\pfx{#2}}{\pfxtypeset}{\postlistingskip} |
| 74 |
\prefixfilelisting{listing1.c}{c> } |
| 75 |
|
| 76 |
\filelisting{listing1.c} |
| 77 |
|
| 78 |
\end{document} |
| 79 |
\endinput |
| 80 |
%% |
| 81 |
%% End of file `examples.tex'. |