diff options
author | Karl Berry <karl@freefriends.org> | 2011-10-18 22:26:36 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2011-10-18 22:26:36 +0000 |
commit | 9570de045eef234423490cbec0cf6b72cf808d4e (patch) | |
tree | afce9ffbd434cf42158257b8b068c8db226b89b6 /Master/texmf-dist/tex/latex/jvlisting | |
parent | 60d7a3cc1d113df4777e1fb10b0a68bab06ece5f (diff) |
jvlisting 0.5 (17oct11)
git-svn-id: svn://tug.org/texlive/trunk@24315 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/jvlisting')
-rw-r--r-- | Master/texmf-dist/tex/latex/jvlisting/jvlisting.sty | 127 |
1 files changed, 75 insertions, 52 deletions
diff --git a/Master/texmf-dist/tex/latex/jvlisting/jvlisting.sty b/Master/texmf-dist/tex/latex/jvlisting/jvlisting.sty index 7794887939a..dffc5378215 100644 --- a/Master/texmf-dist/tex/latex/jvlisting/jvlisting.sty +++ b/Master/texmf-dist/tex/latex/jvlisting/jvlisting.sty @@ -26,58 +26,81 @@ %% jvlisting.sty, jvlisting.ins and examples.tex. \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{jvlisting}[2011/06/27 v0.1 Formatted Program Listings] +\ProvidesPackage{jvlisting}[2011/10/17 v0.5 Formatted Program Listings] -\def\jvl@iterlines#1{\obeylines - \expandafter\jvl@iterla\expandafter{#1}{\jvl@dropempty}} -{\obeylines -\gdef\jvl@iterla#1#2#3 +\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#3\jvl@eol\jvl@iterla{#1}{\jvl@countspaces}}% + \def\next{#2{\jvl@iterla{#1}{\jvl@tryhook}}#3 + }% \else% - \def\y##1#1##2#1{\jvl@dropempty ##1\jvl@eol\jvl@end##2}% + % 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}} -\def\jvl@dropempty{\jvl@dropa{}} -\def\jvl@dropa#1#2{\ifx\jvl@eol#2% - \let\next=\relax +\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}} + +\def\jvl@tryhook#1{\ifx\ListingStartHook\undefined + \def\next{\jvl@countspaces{#1}}% \else - \if#2 \def\next{\jvl@dropa{#1#2}}\else - \def\next{\jvl@countspaces #1#2}\fi - \fi\next} + \def\jvl@trya{\let\ListingStartHook\undefined\jvl@countspaces{#1}}% + \def\next{\ListingStartHook{\jvl@trya}}% + \fi + \next} -\def\jvl@countspaces{\@tempcnta=0\jvl@counta} +\def\jvl@countspaces#1{\@tempcnta=0\jvl@counta{#1}} {\catcode`\^^I=12 -\gdef\jvl@counta#1{\expandafter\if\noexpand#1^^I% +\gdef\jvl@counta#1#2{\if^^I#2% \advance\@tempcnta by8\divide\@tempcnta by8\multiply\@tempcnta by8 - \let\next=\jvl@counta + \def\next{\jvl@counta{#1}}% \else - \expandafter\if\noexpand#1 % + \expandafter\if\noexpand#2 % \advance\@tempcnta by1 - \let\next=\jvl@counta + \def\next{\jvl@counta{#1}}% \else - \def\next{\jvl@fixspaces #1} + \def\next{\jvl@fixspaces{#1}#2}% \fi \fi\next}} -\newcount\jvl@idt \jvl@idt=-1 -\def\jvl@fixspaces#1{\ifx\jvl@eol#1\else - \ifnum\jvl@idt<0 - \jvl@idt=\@tempcnta - \else - \ifnum\@tempcnta<\jvl@idt\jvl@idt=\@tempcnta\fi - \fi\fi\jvl@fixa#1} -\def\jvl@fixa{\ifnum\@tempcnta>\jvl@idt +\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\space}% + \def\next{\jvl@fixa{#1}\space}% \else - \let\next\jvl@output + \def\next{\jvl@output{#1}}% \fi\next} -\def\jvl@output#1\jvl@eol{\jvl@typeset{#1}} +{\obeylines\gdef\jvl@output#1#2 + {\jvl@typeset{#2}#1}} + +{\catcode`\ =\active% +\gdef\jvl@obeyspaces{\frenchspacing\catcode`\ =\active\let \space}} +{\catcode`\`=\active\gdef`{\relax\lq}} +\gdef\jvl@noligs{\catcode`\`=\active} +\def\jvl@fixparsing{\let\do\@makeother\dospecials\catcode`\^^I=12 + \jvl@obeyspaces\jvl@noligs\hyphenchar\font\m@ne} + +\newcount\jvl@tmphyphenchar +\def\jvl@begingroup{\jvl@tmphyphenchar=\hyphenchar\font + \begingroup \parskip0pt \advance\leftskip by\@totalleftmargin} +\def\jvl@endgroup{\endgroup \hyphenchar\font=\jvl@tmphyphenchar} \begingroup \catcode`|=0 \catcode`[=1 \catcode`]=2 @@ -85,14 +108,15 @@ |gdef|jvl@makemarker#1[% |expandafter|gdef|csname jvl@@#1marker|endcsname[\end{#1}]] |endgroup -\def\jvl@setup{\begingroup - \parskip0pt \advance\leftskip by\@totalleftmargin - \let\do\@makeother\dospecials \catcode`\^^I=12} \def\NewListingEnvironment#1#2#3#4#5#6{\jvl@makemarker{#1}% - \expandafter\newcommand\csname #1\endcsname[#2]{#3\jvl@setup + \expandafter\newcommand\csname #1\endcsname[#2]{#3\jvl@begingroup #4\def\jvl@end{\end{#1}}\let\jvl@typeset=#5% - \expandafter\jvl@iterlines\csname jvl@@#1marker\endcsname}% - \expandafter\gdef\csname end#1\endcsname{\endgroup #6}} + \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}} \newread\jvl@fileinput \def\jvl@iterfile{\read\jvl@fileinput to\l @@ -103,7 +127,9 @@ \let\next\jvl@iterfile \fi\next} {\catcode`\^^M=12 -\gdef\jvl@iterfa#1^^M{\jvl@countspaces#1\jvl@eol}} +\gdef\jvl@iterfa#1^^M{\jvl@iterfb{#1}}} +{\obeylines\gdef\jvl@iterfb#1{\jvl@tryhook{\relax}#1 + }} \def\NewFileListingCommand#1#2#3#4#5#6{% \ifnum#2<1 \PackageError{jvlisting}{% @@ -113,11 +139,13 @@ least 1. }% \fi - \newcommand{#1}[#2]{#3\jvl@setup\catcode`\^^M=12 + \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 - \endgroup #6 - } + \jvl@endgroup#6% + \ignorespaces + }% } \newskip\listingskipamount \listingskipamount=1ex @@ -125,23 +153,18 @@ \newcount\prelistingpenalty \prelistingpenalty=100 \newcount\listingpenalty \listingpenalty=500 \newcount\postlistingpenalty \postlistingpenalty=-50 - -{\catcode`\ =\active% -\gdef\jvl@obeyspaces{\frenchspacing\catcode`\ =\active\let \space}} -{\catcode`\`=\active\gdef`{\relax\lq}} -\gdef\jvl@noligs{\catcode`\`=\active} -\def\normallistingfont{\normalfont\ttfamily - \jvl@obeyspaces\jvl@noligs\hyphenchar\font-1} +\def\normallistingfont{\normalfont\ttfamily} \let\listingfont=\normallistingfont -\newcommand{\ListingTypesetLine}[1]{\noindent\hskip\listingindent\strut - #1\par\penalty\listingpenalty} -\newcommand{\prelistingskip}{\endgraf\ifdim\lastskip<\listingskipamount +\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\listingskipamount} + \vskip-\parskip\nobreak\vskip\listingskipamount\noindent} \NewListingEnvironment{listing}{0}{\prelistingskip}% - {\listingfont}{\ListingTypesetLine}{\postlistingskip} + {\listingfont\let\ListingStartHook\listingstarthook}{\ListingTypesetLine}% + {\postlistingskip\ignorespacesafterend} \NewFileListingCommand{\filelisting}{1}{\prelistingskip}% {\listingfont}{\ListingTypesetLine}{\postlistingskip} |