From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- macros/latex/contrib/jvlisting/README | 51 +++ macros/latex/contrib/jvlisting/jvlisting.dtx | 642 +++++++++++++++++++++++++++ macros/latex/contrib/jvlisting/jvlisting.ins | 62 +++ macros/latex/contrib/jvlisting/jvlisting.pdf | Bin 0 -> 193906 bytes macros/latex/contrib/jvlisting/test.tex | 358 +++++++++++++++ 5 files changed, 1113 insertions(+) create mode 100644 macros/latex/contrib/jvlisting/README create mode 100644 macros/latex/contrib/jvlisting/jvlisting.dtx create mode 100644 macros/latex/contrib/jvlisting/jvlisting.ins create mode 100644 macros/latex/contrib/jvlisting/jvlisting.pdf create mode 100644 macros/latex/contrib/jvlisting/test.tex (limited to 'macros/latex/contrib/jvlisting') diff --git a/macros/latex/contrib/jvlisting/README b/macros/latex/contrib/jvlisting/README new file mode 100644 index 0000000000..eb0640b6c0 --- /dev/null +++ b/macros/latex/contrib/jvlisting/README @@ -0,0 +1,51 @@ +jvlisting --- a customizable replacement for LaTeX's verbatim class +Copyright (C) 2011 Jochen Voss + +Please send any problem reports and/or suggestions to the the program's +author Jochen Voss + + +INSTALLATION +------------ + +- To generate "jvlisting.sty" and to create an additional file + "examples.tex" containing a few examples, you can run the following + command: + + tex jvlisting.ins + + After this step, you can try the examples by running the newly + created file "examples.tex" through LaTeX: + + latex examples.tex + +- For simple installation, just move "jvlisting.sty" in a directory + where LaTeX can find it. The jvlisting manual is in the file + "jvlisting.pdf". + +- The regenerate the manual: + + latex jvlisting.dtx + +- A list of test cases which I use for debugging can be found in the + file "test.tex". + + +COPYING +------- + +This work may be distributed and/or modified under the conditions of +the LaTeX Project Public License, either version 1.3 of this license +or (at your option) any later version. The latest version of this +license is in + + http://www.latex-project.org/lppl.txt + +and version 1.3 or later is part of all distributions of LaTeX version +2005/12/01 or later. + +This work has the LPPL maintenance status `maintained' and the current +Maintainer of this work is Jochen Voss . + +This work consists of the files jvlisting.dtx, test.tex and the +derived files jvlisting.sty, jvlisting.ins and examples.tex. diff --git a/macros/latex/contrib/jvlisting/jvlisting.dtx b/macros/latex/contrib/jvlisting/jvlisting.dtx new file mode 100644 index 0000000000..c1f038906a --- /dev/null +++ b/macros/latex/contrib/jvlisting/jvlisting.dtx @@ -0,0 +1,642 @@ +% \iffalse +% jvlisting.dtx - docstrip archive for the jvlisting macro package +%<*gobble> +\iffalse +% +%<*install> +\input docstrip.tex + +\preamble + +Copyright (C) 2011 Jochen Voss + +This work may be distributed and/or modified under the conditions of +the LaTeX Project Public License, either version 1.3 of this license +or (at your option) any later version. The latest version of this +license is in + + http://www.latex-project.org/lppl.txt + +and version 1.3 or later is part of all distributions of LaTeX version +2005/12/01 or later. + +This work has the LPPL maintenance status `maintained' and the current +Maintainer of this work is Jochen Voss . + +This work consists of the files jvlisting.dtx, test.tex and the +derived files jvlisting.sty, jvlisting.ins and examples.tex. +\endpreamble +% +%<*gobble> +\fi +% +%<*driver> +\documentclass{ltxdoc} +\usepackage[text={6in,9in},centering]{geometry} +\usepackage{hyperref} +\usepackage{jvlisting} +\setlength{\parskip}{0pt plus.5ex} +\setlength{\listingskipamount}{.6ex plus.5ex minus.1ex} +\PageIndex +\NewListingEnvironment{xlist}{0}{\prelistingskip}% + {\listingfont\small\renewcommand{\baselinestretch}{0.95}}% + {\ListingTypesetLine}{\postlistingskip} +\begin{document} +\DocInput{jvlisting.dtx} +\end{document} +% +%<*examples> + +\documentclass{article} + +\usepackage[text={6in,9in},centering]{geometry} +\usepackage{jvlisting} +\setlength{\listingskipamount}{2\baselineskip} + +\begin{document} +% +%<*usage> +% \fi +\GetFileInfo{jvlisting.sty} +\title{The \textsf{jvlisting} package} +\date{\filedate\ \fileversion} +\author{Jochen Voss\\ \texttt{voss@seehuhn.de}\\ \texttt{http://seehuhn.de/}} +\maketitle + +\begin{abstract} + This package provides the \LaTeX\ environment \verb|listing|, an + alternative to the built-in \verb|verbatim| environment. The + \verb|listing| environment is specially tailored for including + listings of computer program source code into documents. The main + advantages over the original \verb|verbatim| environment are that + \verb|listing| environments automatically fix leading white-space + so that the environment and program listing can be indented with + the rest of the document source and that \verb|listing| + environments can easily be customised and extended. +\end{abstract} + +\tableofcontents + +\section{Basic Usage} + +The \verb|listing| environment allows to include source code of +computer programs in \LaTeX\ documents by including the code between +\verb|\begin{listing}| and \verb|\end{listing}|. + +\medskip + +\textbf{Example.} In order to typeset the listing of a simple Python +function (computing the cumulative sum of a list) you can use the +following code in your \LaTeX\ document. +\begin{xlist} + \begin{listing} + def cumsum(iterable): + return reduce(lambda res, x: res+[res[-1]+x], iterable, [0])[1:] + \end{listing} +\end{xlist} +\noindent +These commands result in the following output: +% \iffalse +% +%<*examples|usage> +% \fi + +\begin{listing} + def cumsum(iterable): + return reduce(lambda res, x: res+[res[-1]+x], iterable, [0])[1:] +\end{listing} +% \iffalse +% +%<*usage> +% \fi + +\medbreak + +Differently from the \LaTeX\ \verb|verbatim| environment, the +\verb|listing| environment can be indented to match the surrounding +document source. The following will work as expected: +\begin{xlist} + \begin{figure}[h] + \begin{listing} + def cumsum(iterable): + return reduce(lambda res, x: res+[res[-1]+x], iterable, [0])[1:] + \end{listing} + \end{figure} +\end{xlist} +\noindent +The Python code will be typeset using the same indentation as in the +previous example, despite the fact that the code in the two +\verb|listing| environments has different indentation in the +\LaTeX\ source code. + +To make it easier to copy real program source code directly into your +\LaTeX\ file, the code in listings can be indented by TAB characters +instead of spaces. The TAB spacing is assumed to be 8 character +columns. + +In addition to the \LaTeX\ environment described above, there is also +a command \verb|\filelisting| to typeset source code contained in a +file. The command takes one argument, the name of the file to +include, and behaves very similar to the the \verb|listing| +environment. + +\medskip + +\textbf{Example.} In order to typeset the contents of a file +\verb|cumsum.py|, we could use the following command. +\begin{xlist} + \filelisting{cumsum.py} +\end{xlist} + +\bigbreak + +There are various parameters to customise how listings are typeset. +These parameters apply both to the \verb|listing| environment and +to the \verb|\filelisting| command. +\begin{itemize} +\item The amount of space inserted before and after a listing is + given by \verb|\listingskipamount|. The default value is + \verb|1ex|. Commands like the following can be used to adjust the + amount of space. + \begin{xlist} + \setlength{\listingskipamount}{1\baselineskip} + \end{xlist} +\item The indentation of the left margin of the typeset code is + determined by \verb|\listingindent|. The default value is + \verb|2em|. Commands like the following can be used to adjust + indentation. + \begin{xlist} + \setlength{\listingindent}{2cm} + \end{xlist} +\item The font used in the listing is controlled by the macro + \verb|\listingfont|. The default value is \verb|\normallistingfont| + which sets up a typewriter-like font. Example: The following + command can be used to obtain more compact listings by slightly + reducing the font size and the line spacing. + \begin{xlist} + \renewcommand{\listingfont}% + {\normallistingfont\small\renewcommand{\baselinestretch}{0.95}} + \end{xlist} +\item The penalty for page breaks inside a listing is given by + \verb|\listingpenalty|. The higher this value, the less attractive + page breaks inside the listing are to \LaTeX's page breaking + algorithm. The default value is 500. The following command can be + used to completely disable page breaks inside listings. + \begin{xlist} + \listingpenalty=10000 + \end{xlist} +\item The penalty for page breaks just before or after a listing is + given by \verb|\prelistingpenalty| (default value 100) and + \verb|\postlistingpenalty| (default value -50), respectively. +\end{itemize} + +\section{Extending the \textsf{listing} Environment} + +New \verb|listing|-like environments can be defined using the +\verb|\NewListingEnvironment| macro. This macro takes six arguments +and uses them to define a new \LaTeX\ environment. The arguments, in +order, are +\begin{enumerate} +\item The name of the new environment. +\item The number of extra arguments for the new environment + (normally~0). These extra arguments of the environment, if any, are + substituted into the initialisation commands (\textit{i.e.}\ into + the fourth argument of \verb|\NewListingEnvironment|); see the + \verb|copylisting| environment, below, for an example. +\item Commands to execute before the environment is entered + (\textit{e.g.}\ to add vertical white space). +\item Initialisation commands, executed inside the environment + (\textit{e.g.}\ font/margin setup). +\item The name of a macro (receiving one argument) which will be used + to typeset each line of input. +\item Commands to execute after the environment is completed. +\end{enumerate} + +\medskip + +\textbf{Example.} The \verb|listing| environment provided by the +\verb|jvlisting| package is defined using the following commands: +% \iffalse +% +%<*listingdef|usage> +% \fi + +% \begin{macrocode} +\let\listingfont=\normallistingfont +\newcommand{\ListingTypesetLine}[1]{\ifvmode\penalty\listingpenalty\noindent\fi + \hskip\listingindent\strut#1\par} +\newcommand{\prelistingskip}{\endgraf\ifdim\lastskip>\listingskipamount\else + \removelastskip\penalty\prelistingpenalty\vskip\listingskipamount\fi} +\newcommand{\postlistingskip}{\endgraf\penalty\postlistingpenalty + \vskip-\parskip\nobreak\vskip\listingskipamount\noindent} +\NewListingEnvironment{listing}{0}{\prelistingskip}% + {\listingfont\let\ListingStartHook\listingstarthook}{\ListingTypesetLine}% + {\postlistingskip\ignorespacesafterend} +% \end{macrocode} +% \iffalse +% +%<*usage> +% \fi + +\medbreak + +\textbf{Example.} An \verb|nlisting| environment which generates +listings with additional line numbers can be defined as follows: +% \iffalse +% +%<*examples|usage> +% \fi + +% \begin{macrocode} +\newcounter{lineno} +\newcommand{\typesetnline}[1]{\addtocounter{lineno}{1}% + \noindent\hskip\listingindent\llap{{\it\scriptsize\arabic{lineno}: }}% + \strut #1\par\penalty\listingpenalty} +\NewListingEnvironment{nlisting}{0}{\prelistingskip}% + {\setcounter{lineno}{0}\listingfont}{\typesetnline}{\postlistingskip} +% \end{macrocode} +% \iffalse +%> +%<*examples> +\begin{nlisting} + for i in [1, 2, 3]: + for j in ['a', 'b', 'c']: + print str(i)+j +\end{nlisting} +% +%<*usage> +% \fi + +\medbreak + +\textbf{Example.} The following code defines a new \verb|copylisting| +environment which does not only typeset the source code, but also +saves a copy in an external file. Here we need to be careful in case +the quote character \verb|`| can be present in the listing: by +default, \verb|\listingfont| makes \verb|`| an active character in +order to prevent problems with ligatures, but this fix causes damage +to the output of the \verb|\write| command. To work around this +problem, we can use \verb|\DisableLigatureFix| (defined by the +\verb|jvlisting| package for just this purpose) to temporarily disable +the ligature fix. +% \iffalse +% +%<*examples|usage> +% \fi + +% \begin{macrocode} +\newwrite\outfile +\newcommand{\copytypeset}[1]{\ListingTypesetLine{#1}% + {\DisableLigatureFix\immediate\write\outfile{#1}}} +\NewListingEnvironment{copylisting}{1}{\prelistingskip}% + {\immediate\openout\outfile=#1\listingfont}{\copytypeset}% + {\immediate\closeout\outfile\postlistingskip} +% \end{macrocode} +% \iffalse +%> +%<*usage> +% \fi +Here we used the second argument to \verb|\NewListingEnvironment| to +indicate that the \verb|copylisting| environment should take an +additional parameter (the output file name). The new environment is +used as follows: +% \iffalse +% +%<*examples|usage> +% \fi + +% \begin{macrocode} +\begin{copylisting}{listing1.c} + #include + + int + main() + { + puts("hello, world!"); + return 0; + } +\end{copylisting} +% \end{macrocode} +% \iffalse +%> +%<*usage> +% \fi + +\section{Extending the \textsf{filelisting} Command} + +New \verb|filelisting|-like commands can be defined using the +\verb|\NewFileListingCommand| macro. This macro takes six arguments +and uses them to define a new macro. The arguments, in order, are +\begin{enumerate} +\item The name of the new command including the leading backslash. +\item The number of arguments for the new command (normally~1). These + arguments, including the first one which gives the file name, are + substituted into the third, fourth and sixth argument of + \verb|\NewFileListingCommand|); see the \verb|\prefixfilelisting| + command, below, for an example. +\item Commands to execute before the listing is started + (\textit{e.g.}\ to add vertical white space). +\item Initialisation commands, executed inside the scope of the + listing (\textit{e.g.}\ font/margin setup). +\item The name of a macro (receiving one argument) which will be used + to typeset each line of input. +\item Commands to execute after the listing is completed. +\end{enumerate} +The first argument of the newly defined macro always denotes the name +of the file to include. + +\medskip + +\textbf{Example.} Using the auxiliary functions for the +\verb|listing| environment, the built-in \verb|filelisting| command +can be defined as follows: +% \iffalse +% +%<*listingdef|usage> +% \fi + +% \begin{macrocode} +\NewFileListingCommand{\filelisting}{1}{\prelistingskip}% + {\listingfont}{\ListingTypesetLine}{\postlistingskip} +% \end{macrocode} +% \iffalse +% +%<*usage> +% \fi + +\medbreak + +\textbf{Example.} The following command defines a macro to read a +file and to prefix every line of the resulting listing with a given +string. +% \iffalse +% +%<*examples|usage> +% \fi + +% \begin{macrocode} +\newcommand{\pfxtypeset}[1]{\noindent\hskip\listingindent\strut + \pfx#1\par\penalty\listingpenalty} +\NewFileListingCommand{\prefixfilelisting}{2}{\prelistingskip}% + {\listingfont\def\pfx{#2}}{\pfxtypeset}{\postlistingskip} +% \end{macrocode} +% \iffalse +%> +%<*examples> +\prefixfilelisting{listing1.c}{c> } +% +%<*package> +% \fi + +% \StopEventually{} +% \section{Implementation} +% +% This section describes the internal implementation of the +% \verb|jvlisting| package. In order to avoid name clashes with other +% packages, the names of all internal macros defined in this package +% start with the prefix \verb|jvl@|. The following is the preamble +% for the package file. +% \begin{macrocode} +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{jvlisting}[2011/11/17 v0.7 Formatted Program Listings] +% \end{macrocode} + +% \subsection{Processing the Lines of Input} +% +% We start by provinding a macro \verb|\jvl@iterlines| which can be +% used to iterate over all lines of input until a line containing some +% marker is found. The marker is given as argument \verb|#1| to the +% \verb|\jvl@iterlines| macro. Each line is processed by prepending +% \verb|\jvl@dropempty| (for the first and last line) or +% \verb|\jvl@tryhook| (for all other lines). +% \begin{macrocode} +\def\jvl@iterlines#1{\expandafter\jvl@iterla\expandafter{#1}{\jvl@dropempty}} +{\obeylines\gdef\jvl@iterla#1#2#3 + {\def\jvl@testmarker##1#1{}% + \expandafter\def\expandafter\w\expandafter{\jvl@testmarker#3#1}% + \ifx\w\empty% + \def\next{#2{\jvl@iterla{#1}{\jvl@tryhook}}#3 + }% + \else% + % special treatment for the last line + \def\y##1#1##2#1{\jvl@dropempty{\jvl@end##2}##1 + }% + \def\next{\y#3#1}% + \fi\next}} +% \end{macrocode} + +% The next step in processing is to drop the first line (whatever +% comes directly after the opening \verb|begin| statement) and the +% last line (whatever comes directly before the closing \verb|end| +% statement), if these lines consist only of white space. +% \begin{macrocode} +\def\jvl@dropempty#1{\jvl@dropa{#1}{}} +{\obeylines\gdef\jvl@dropa#1#2#3{\ifx + #3\def\next{#1}% + \else% + \if#3 \def\next{\jvl@dropa{#1}{#2#3}}\else% + \def\next{\jvl@tryhook{#1}#2#3}\fi% + \fi\next}} +% \end{macrocode} + +% Next we try to apply the \verb|\ListingStartHook|. +% \begin{macrocode} +\def\jvl@tryhook#1{\ifx\ListingStartHook\undefined + \def\next{\jvl@countspaces{#1}}% + \else + \def\jvl@trya{\let\ListingStartHook\undefined\jvl@countspaces{#1}}% + \def\next{\ListingStartHook{\jvl@trya}}% + \fi + \next} +% \end{macrocode} + +% Next we determine the indentation level of the current line by +% expanding TAB characters and then counting spaces. The result is +% stored in the scratch counter \verb|@tempcnta|. +% \begin{macrocode} +\def\jvl@countspaces#1{\@tempcnta=0\jvl@counta{#1}} +{\catcode`\^^I=12 +\gdef\jvl@counta#1#2{\if^^I#2% + \advance\@tempcnta by8\divide\@tempcnta by8\multiply\@tempcnta by8 + \def\next{\jvl@counta{#1}}% + \else + \expandafter\if\noexpand#2 % + \advance\@tempcnta by1 + \def\next{\jvl@counta{#1}}% + \else + \def\next{\jvl@fixspaces{#1}#2}% + \fi + \fi\next}} +% \end{macrocode} + +% Using the value in \verb|@tempcnta|, we fix the indentation by first +% subtracting the common indentation level (stored in \verb|\jvl@idt|) +% and then inserting the required number of spaces (using +% \verb|\space|). +% \begin{macrocode} +\newcount\jvl@idt \jvl@idt=\m@ne +{\obeylines\gdef\jvl@fixspaces#1#2{\ifx + #2\else% + \ifnum\jvl@idt<0% + \jvl@idt=\@tempcnta% + \else% + \ifnum\@tempcnta<\jvl@idt\jvl@idt=\@tempcnta\fi% + \fi\fi\jvl@fixa{#1}#2}} +\def\jvl@fixa#1{\ifnum\@tempcnta>\jvl@idt + \advance\@tempcnta by\m@ne + \def\next{\jvl@fixa{#1}\space}% + \else + \def\next{\jvl@output{#1}}% + \fi\next} +% \end{macrocode} + +% Finally, we apply the output function \verb|\jvl@typeset| to the +% processed line and starting processing of the next line. +% \begin{macrocode} +{\obeylines\gdef\jvl@output#1#2 + {\jvl@typeset{#2}#1}} +% \end{macrocode} +% The symbol \verb|\jvl@typeset| will be defined inside the +% \verb|\begin{listing}| command; since neested listings are not +% possible, using a global name for the output function is no +% problem. + +% \subsection{Defining Listing Environments} +% +% In order to allow for verbatim printing, the macro +% \verb|jvl@fixparsing| switches off the special meaning of most +% characters. Some care is needed to avoid problems with spaces and +% hyphenation. +% \begin{macrocode} +{\catcode`\ =\active% +\gdef\jvl@obeyspaces{\frenchspacing\catcode`\ =\active\let \space}} +\def\jvl@fixparsing{\let\do\@makeother\dospecials\catcode`\^^I=12 + \jvl@obeyspaces\hyphenchar\font\m@ne} +% \end{macrocode} + +% Since the \verb|\hyphenchar| setting is global, we save save the +% value of \verb|hyphenchar| before entering the listing environment +% end restore the original setting at the end. +% \begin{macrocode} +\newcount\jvl@tmphyphenchar +\def\jvl@begingroup{\jvl@tmphyphenchar=\hyphenchar\font + \begingroup \parskip0pt \advance\leftskip by\@totalleftmargin} +\def\jvl@endgroup{\endgroup \hyphenchar\font=\jvl@tmphyphenchar} +% \end{macrocode} + +% Given the code above, we can now define the +% \verb|\NewListingEnvironment| macro. Some care is needed when +% constructing the marker for use in the \verb|\jvl@iterlines| macro, +% because the text we need to match uses category code 12 (``other'') +% for the characters \verb|\|, \verb|{| and~\verb|}|. +% \begin{macrocode} +\begingroup + \catcode`|=0 \catcode`[=1 \catcode`]=2 + \catcode`\{=12 \catcode`\}=12 \catcode`\\=12 + |gdef|jvl@makemarker#1[% + |expandafter|gdef|csname jvl@@#1marker|endcsname[\end{#1}]] +|endgroup +\def\NewListingEnvironment#1#2#3#4#5#6{\jvl@makemarker{#1}% + \expandafter\newcommand\csname #1\endcsname[#2]{#3\jvl@begingroup + #4\def\jvl@end{\end{#1}}\let\jvl@typeset=#5% + \jvl@fixparsing\obeylines + \expandafter\def\expandafter\jvl@start\expandafter{% + \expandafter\jvl@iterlines\csname jvl@@#1marker\endcsname}% + \let\next\jvl@start + \next}% + \expandafter\gdef\csname end#1\endcsname{\jvl@endgroup #6}} +% \end{macrocode} + +% \subsection{Reading Listings from File} +% +% When reading listings from a file, we get the lines terminated by +% \verb|^^M| characters. The following function is a replacement for +% \verb|\jvl@iterlines|, used to read lines from a file and to strip +% the trailing \verb|^^M| characters: +% \begin{macrocode} +\newread\jvl@fileinput +\def\jvl@iterfile{\read\jvl@fileinput to\l + \ifeof\jvl@fileinput + \let\next\relax + \else + \expandafter\jvl@iterfa\l + \let\next\jvl@iterfile + \fi\next} +{\catcode`\^^M=12 +\gdef\jvl@iterfa#1^^M{\jvl@iterfb{#1}}} +{\obeylines\gdef\jvl@iterfb#1{\jvl@tryhook{\relax}#1 + }} +% \end{macrocode} +% +% In analogy to \verb|\NewListingEnvironment|, the following macro is +% used to define new functions for listing file contents. +% \begin{macrocode} +\def\NewFileListingCommand#1#2#3#4#5#6{% + \ifnum#2<1 + \PackageError{jvlisting}{% + Invalid number of arguments: `#2' + }{% + The second argument to \protect\NewFileListingCommand\space must be at + least 1. + }% + \fi + \newcommand{#1}[#2]{#3\jvl@begingroup + #4\let\jvl@typeset=#5% + \jvl@fixparsing\catcode`\^^M=12 + \openin\jvl@fileinput=##1\jvl@iterfile\closein\jvl@fileinput + \jvl@endgroup#6% + \ignorespaces + }% +} +% \end{macrocode} + +% \subsection{Finishing Touches} +% +% The following definitions provide default values for the +% customisable parameters of the \verb|listing| environment. +% \begin{macrocode} +\newskip\listingskipamount \listingskipamount=1ex +\newdimen\listingindent \listingindent=2em +\newcount\prelistingpenalty \prelistingpenalty=100 +\newcount\listingpenalty \listingpenalty=500 +\newcount\postlistingpenalty \postlistingpenalty=-50 +% \end{macrocode} +% Finally, we define the default font for use in listings. Some care +% is needed to avoid problems with ligatures like \verb|?`|. We break +% such ligatures by making \verb|`| and active character. For use in +% file listings we also provide \verb|\DisableLigatureFix| to +% (temporarily) disable this fix. +% \begin{macrocode} +{\catcode`\`=\active\gdef`{\relax\lq}% +\gdef\DisableLigatureFix{\def`{\lq}}} +\def\normallistingfont{\normalfont\ttfamily\catcode`\`=\active} +% \end{macrocode} +% \iffalse +% +%<*examples> + +\filelisting{listing1.c} + +\end{document} +% +%<*install> + +\keepsilent +\askforoverwritefalse + +\generate{% + \file{jvlisting.ins}{\from{jvlisting.dtx}{install}}% + \usedir{tex/latex/jvlisting}% + \file{jvlisting.sty}{\from{jvlisting.dtx}{package}% + \from{jvlisting.dtx}{listingdef}}% + \file{examples.tex}{\from{jvlisting.dtx}{examples}}% +} +\endbatchfile +% +% \fi +% \endinput +% +% Local Variables: +% whitespace-style: (face trailing tabs lines-tail empty space-before-tab) +% whitespace-line-column: 78 +% End: diff --git a/macros/latex/contrib/jvlisting/jvlisting.ins b/macros/latex/contrib/jvlisting/jvlisting.ins new file mode 100644 index 0000000000..e7b4cb36f3 --- /dev/null +++ b/macros/latex/contrib/jvlisting/jvlisting.ins @@ -0,0 +1,62 @@ +%% +%% This is file `jvlisting.ins', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% jvlisting.dtx (with options: `install') +%% +%% Copyright (C) 2011 Jochen Voss +%% +%% This work may be distributed and/or modified under the conditions of +%% the LaTeX Project Public License, either version 1.3 of this license +%% or (at your option) any later version. The latest version of this +%% license is in +%% +%% http://www.latex-project.org/lppl.txt +%% +%% and version 1.3 or later is part of all distributions of LaTeX version +%% 2005/12/01 or later. +%% +%% This work has the LPPL maintenance status `maintained' and the current +%% Maintainer of this work is Jochen Voss . +%% +%% This work consists of the files jvlisting.dtx, test.tex and the +%% derived files jvlisting.sty, jvlisting.ins and examples.tex. +\input docstrip.tex + +\preamble + +Copyright (C) 2011 Jochen Voss + +This work may be distributed and/or modified under the conditions of +the LaTeX Project Public License, either version 1.3 of this license +or (at your option) any later version. The latest version of this +license is in + + http://www.latex-project.org/lppl.txt + +and version 1.3 or later is part of all distributions of LaTeX version +2005/12/01 or later. + +This work has the LPPL maintenance status `maintained' and the current +Maintainer of this work is Jochen Voss . + +This work consists of the files jvlisting.dtx, test.tex and the +derived files jvlisting.sty, jvlisting.ins and examples.tex. +\endpreamble + +\keepsilent +\askforoverwritefalse + +\generate{% + \file{jvlisting.ins}{\from{jvlisting.dtx}{install}}% + \usedir{tex/latex/jvlisting}% + \file{jvlisting.sty}{\from{jvlisting.dtx}{package}% + \from{jvlisting.dtx}{listingdef}}% + \file{examples.tex}{\from{jvlisting.dtx}{examples}}% +} +\endbatchfile +\endinput +%% +%% End of file `jvlisting.ins'. diff --git a/macros/latex/contrib/jvlisting/jvlisting.pdf b/macros/latex/contrib/jvlisting/jvlisting.pdf new file mode 100644 index 0000000000..4a160aaa04 Binary files /dev/null and b/macros/latex/contrib/jvlisting/jvlisting.pdf differ diff --git a/macros/latex/contrib/jvlisting/test.tex b/macros/latex/contrib/jvlisting/test.tex new file mode 100644 index 0000000000..ffa59a95f5 --- /dev/null +++ b/macros/latex/contrib/jvlisting/test.tex @@ -0,0 +1,358 @@ +\documentclass{article} + +\usepackage[a4paper,margin=1in]{geometry} +\usepackage{jvlisting} +\usepackage{multicol} + +\newcommand{\testbreak}{\vskip0pt plus 10cm\penalty-100\vskip0pt plus-10cm + \bigskip} +\newenvironment{test}[1]{\testbreak\begingroup\textbf{Test~#1}}% + {\par\endgroup} +\newenvironment{testpages}[1]{\parskip0pt + \vskip2pt\hrule\begin{minipage}[c][#1\baselineskip]{1\linewidth}% + \begin{multicols}{2}\parskip1ex}% + {\end{multicols}\end{minipage}\vskip3pt\hrule} +\parindent0pt +\parskip1ex + +\newwrite\outfile + +\begin{document} + +\begin{center} + \bf Test Cases for the jvlisting Package +\end{center} + + +This document contains test cases to exercise different features of +the \verb|jvlisting| \LaTeX\ package. + + +\begin{test}{1.1} (printing of special characters). + The following two lines should be the same + \setlength{\listingindent}{0pt} + \setlength{\listingskipamount}{0pt} + \begin{listing} + start %\{}~``''$ end + \end{listing} + \verb|start %\{}~``''$ end| +\end{test} + + +\begin{test}{1.2} (ligatures). + The following two lines should be the same + \setlength{\listingindent}{0pt} + \setlength{\listingskipamount}{0pt} + \begin{listing} + start ?` !` end + \end{listing} + \verb|start ?` !` end| +\end{test} + + +\begin{test}{2.1} (indentation). + The following five lines should align horizontally. + \setlength{\listingskipamount}{0pt} + \begin{listing} + |line1| + \end{listing} + \begin{listing} +|line2| + \end{listing} + \begin{listing} |line3| + |line4| + |line5|\end{listing} +\end{test} + + +\begin{test}{2.2} (decreasing indentation level). + The left end of the following lines should align horizontally. + \begin{listing} |line0 + |line1 + |line2 + |line3 + \end{listing} +\end{test} + + +\begin{test}{2.3} (increasing indentation level). + The right end of the following lines should align horizontally. + \begin{listing} + xxline1| + xline2| + line3| + \end{listing} +\end{test} + + +\begin{test}{2.4} (\verb|\listingindent|). + The following two lines should align horizontally. + \setlength{\listingskipamount}{0pt} + +\hskip3cm\texttt{|line1|} + +\setlength{\listingindent}{3cm} +\begin{listing} + |line2| +\end{listing} +\end{test} + + +\begin{test}{3.1} (\verb|\listingskipamount|, part~1). +The lines of the listing should vertically align with the lines to the +right. + +\setlength{\listingskipamount}{0pt} +\begin{minipage}{.4\linewidth} + line1 line1 line1 line1 line1 + \begin{listing} + line2 line2 line2 line2 line2 + line3 line3 line3 line3 line3 + \end{listing} + line4 line4 line4 line4 line4 +\end{minipage}% +\begin{minipage}{.6\linewidth} + line1 \\ + line2 \\ + line3 \\ + line4 +\end{minipage} +\end{test} + + +\begin{test}{3.2} (\verb|\listingskipamount|, part~2). +The lines of the listing should vertically align with the lines to the +right. + +\begin{minipage}{.4\linewidth} + line1 line1 line1 line1 line1 + \setlength{\listingskipamount}{1\baselineskip} + \begin{listing} + line3 line3 line3 line3 line3 + \end{listing} + line5 line5 line5 line5 line5 +\end{minipage}% +\begin{minipage}{.6\linewidth} + line1 \\ + line2 \\ + line3 \\ + line4 \\ + line5 +\end{minipage} +\end{test} + + +\begin{test}{3.3} (no extra parskip before/after listings). +The lines of the listing should vertically align with the lines to the +right. + +\begin{minipage}{.4\linewidth}\parskip12pt +\setlength{\listingskipamount}{0pt} + line1 line1 line1 line1 line1 + \begin{listing} + line2 line2 line2 line2 line2 + line3 line3 line3 line3 line3 + line4 line4 line4 line4 line4 + \end{listing} + line5 line5 line5 line5 line5 + + line7 +\end{minipage}% +\begin{minipage}{.6\linewidth}\parskip1\baselineskip + line1 + + line3 + + line5 + + line7 +\end{minipage} +\end{test} + + +\begin{test}{4.1} (page breaks). +The columns should be of equal height (four rows each). +\setlength{\listingskipamount}{0pt}% +\begin{testpages}{6} + Some text \dots \\ + \dots\ before the listing. + \begin{listing} + line1 + line2 + line3 + line4 + line5 + line6 + \end{listing} +\end{testpages} +\end{test} + + +\begin{test}{4.2} (page breaks, \verb|\listingpenalty|). +The column break should be immediately before \verb|line1|. +\setlength{\listingskipamount}{0pt}% +\listingpenalty=10000 +\begin{testpages}{6} + Some text \dots \\ + \dots\ before the listing. + \begin{listing} + line1 + line2 + line3 + line4 + line5 + line6 + \end{listing} +\end{testpages} +\end{test} + + +\begin{test}{4.3} (page breaks, \verb|\prelistingpenalty|). +The column break should {\em not} be immediately before \verb|line1|. +\setlength{\listingskipamount}{0pt}% +\prelistingpenalty=10000 +\begin{testpages}{3} + Some text \dots \\ + \dots\ before \dots \\ + \dots the listing. + \begin{listing} + line1 + line2 + \end{listing} +\end{testpages} +\end{test} + + +\begin{test}{4.4} (page breaks, \verb|\postlistingpenalty|). +The column break should {\em not} be immediately after \verb|line3|. +\setlength{\listingskipamount}{0pt}% +\postlistingpenalty=10000 +\begin{testpages}{3} + \begin{listing} + line1 + line2 + line3 + \end{listing} + Some text \dots \\ + \dots\ after the listing. +\end{testpages} +\end{test} + + +\begin{test}{5} (\verb|\filelisting|) +The following two listings should look the same. +\immediate\openout\outfile=tmp.txt +\immediate\write\outfile{line1} +\immediate\write\outfile{line2} +\immediate\write\outfile{line3} +\immediate\closeout\outfile + +\begin{minipage}{.5\linewidth} +\begin{listing} +line1 +line2 +line3 +\end{listing} +\end{minipage}% +\begin{minipage}{.5\linewidth} +\filelisting{tmp.txt} +\end{minipage} +\end{test} + + +\begin{test}{6.1} (\verb|\listingstarthook|, prepending a character) + The following two lines should be the same. + \setlength{\listingskipamount}{0pt}% + \begin{listing} + xtest + \end{listing} + \def\listingstarthook#1{#1x\ignorespaces}% + \begin{listing} + test + \end{listing} +\end{test} + +\begin{test}{6.2} (\verb|\listingstarthook|, prepending a line) + The following listing should have two lines. + \setlength{\listingskipamount}{0pt}% + {\obeylines + \gdef\listingstarthook#1{#1{ }{ }{ }{ }line1 + }}% + \begin{listing} + line2 + \end{listing} + \global\let\listingstarthook=\undefined +\end{test} + +\begin{test}{6.3} (\verb|\listingstarthook|, removing the first line) + The following listing should have two lines. + \setlength{\listingskipamount}{0pt}% + {\obeylines + \gdef\listingstarthook#1#2 + {#1}}% + \begin{listing} + this should not be shown + line1 + line2 + \end{listing} + \global\let\listingstarthook=\undefined +\end{test} + +\begin{test}{6.4} (\verb|\listingstarthook|, conditionally removing the first line) + The following listing should have two lines. + \setlength{\listingskipamount}{0pt}% + {\catcode`\#=12\gdef\hash{#}} + {\obeylines + \gdef\skiptoeol#1#2 + {\noindent\hbox to0pt{\hss (a line was removed)\hskip-\textwidth}#1}} + \def\x#1#2#3{\if#3 \def\next{\x{#1}{#2#3}}\else + \expandafter\ifx\hash#3\def\next{\skiptoeol{#1}}\else + \def\next{#1#2#3}\fi\fi\next} + \def\listingstarthook#1{\x{#1}{}} + \begin{listing} + #line0 + line1 + line2 + \end{listing} + The following listing should have three lines. + \begin{listing} + line0 + line1 + line2 + \end{listing} +\end{test} + +\newcommand{\writetofile}[1]{\immediate\write\outfile{#1}} +\NewListingEnvironment{filetestlisting}{0}{}% + {\immediate\openout\outfile=tmp.txt}{\writetofile}% + {\immediate\closeout\outfile} + +\begin{test}{7.1} (writing listings to file) + The following two lines should be the same. + \setlength{\listingskipamount}{0pt}% + \begin{listing} + a line with ``quotes'', \slashes and potential ligatures: ` ?` !` ' + \end{listing} + \begin{filetestlisting} + a line with ``quotes'', \slashes and potential ligatures: ` ?` !` ' + \end{filetestlisting} + \filelisting{tmp.txt} +\end{test} + +\newcommand{\copytypeset}[1]{\ListingTypesetLine{#1}% + {\DisableLigatureFix\immediate\write\outfile{#1}}} +\NewListingEnvironment{copylisting}{0}{\prelistingskip}% + {\immediate\openout\outfile=tmp.txt\listingfont}{\copytypeset}% + {\immediate\closeout\outfile\postlistingskip} + +\begin{test}{7.2} (simultaneously typesetting and writing to a file) + The following four lines should be the same. + \setlength{\listingskipamount}{0pt}% + \begin{copylisting} + a line with ``quotes'', \slashes and potential ligatures: ` ?` !` ' + a line with ``quotes'', \slashes and potential ligatures: ` ?` !` ' + \end{copylisting} + \filelisting{tmp.txt} +\end{test} + +\end{document} -- cgit v1.2.3