1 #\DeclareLyXModule{Newfangle Literate Listings}
3 # Newfangle literate listings allow one to write
4 # literate programs after the fashion of noweb, but without having
5 # to use noweave to generate the documentation. Instead the listings
6 # package is extended in conjunction with the noweb package to implement
7 # to code formating directly as latex.
8 # The newfangle awk script
14 \usepackage{listings}%
17 \renewcommand{\code}[1]{\texttt{#1}}%
18 \lstnewenvironment{Chunk}{\relax}{\relax}%
19 \lstset{numbers=left, stepnumber=5, numbersep=5pt,
20 breaklines=false,basicstyle=\ttfamily,
21 numberstyle=\tiny, language=C}%
22 \lstset{escapeinside={=<}{>}}%
24 %somehow re-defining maketitle gives us a left-aligned title
25 %which is extactly what our specially formatted title needs!
26 \global\let\newfangle@lst@maketitle\lst@maketitle%
27 \global\def\lst@maketitle{}%
29 \lstset{title={\newfanglecaption},name=#1}%
30 \global\edef\lst@chunkname{\lst@intname}%
32 \def\lst@chunkname{\empty}%
33 \lst@Key{params}\relax{\def\newfangle@chunk@params{#1}}%
34 \def\newfanglecaption{\protect\newfangle@caption}%
35 \newcounter{newfangle@chunkcounter}%
36 \def\newfangle@caption{%
37 \edef\chunkcount{lst-chunk-\lst@intname}%
38 \@ifundefined{\chunkcount}{%
39 \expandafter\gdef\csname \chunkcount\endcsname{0}%
40 \setcounter{newfangle@chunkcounter}{\csname \chunkcount\endcsname}%
41 \let\prevchunkname\relax%
43 \setcounter{newfangle@chunkcounter}{\csname \chunkcount\endcsname}%
44 \edef\prevchunkname{\lst@intname-\arabic{newfangle@chunkcounter}}%
46 \addtocounter{newfangle@chunkcounter}{1}%
47 \global\expandafter\edef\csname \chunkcount\endcsname{\arabic{newfangle@chunkcounter}}%
48 \edef\chunkname{\lst@intname-\arabic{newfangle@chunkcounter}}%
49 \edef\firstchunkname{\lst@intname-1}%
50 \addtocounter{newfangle@chunkcounter}{1}%
51 \edef\nextchunkname{\lst@intname-\arabic{newfangle@chunkcounter}}%
52 \@ifundefined{r@label-\nextchunkname}{\let\nextchunkname\relax}{}%
53 \sublabel{\chunkname}%
54 % define this label for every chunk instance, so we
55 % can tell when we are the last chunk of this name
56 \label{label-\chunkname}%
57 \addcontentsline{lol}{lstlisting}{\lst@name~[\protect\subpageref{\chunkname}]}%
61 \subpageref{\chunkname}%
69 \@ifundefined{newfangle@chunk@params}{}{%
70 (\newfangle@chunk@params)%
72 [\csname \chunkcount\endcsname]~%%
73 \subpageref{\firstchunkname}%
77 \ifx\relax\prevchunkname\endmoddef\else\plusendmoddef\fi%
78 % \nwstartdeflinemarkup%
79 \nwprevnextdefs{\prevchunkname}{\nextchunkname}%
80 % \nwenddeflinemarkup%
82 %\lst@BeginAspect{newfangle}
83 %\lst@Key{newfangle}{true}[t]{\lstKV@SetIf{#1}{true}}
84 \lst@AddToHookExe{PreSet}{\global\let\lst@intname\lst@chunkname}
85 \lst@AddToHook{Init}{}%\newfangle@caption}
87 \def\chunkref@args#1,{%
89 \lst@ReplaceIn\arg\lst@filenamerpl%
91 \@ifnextchar){\relax}{, \chunkref@args}%
93 \newcommand\chunkref[2][0]{%
94 \@ifnextchar({\chunkref@i{#1}{#2}}{\chunkref@i{#1}{#2}()}%
96 \def\chunkref@i#1#2(#3){%
102 \def\chunkname{#2-1}%
104 \def\chunkname{#2-\chunkno}%
107 \lst@ReplaceIn\chunk\lst@filenamerpl%
116 \ifx\chunkargs\empty%
118 (\chunkref@args #3,)%
120 ~\subpageref{\chunkname}%