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 \lst@Key{append}\relax{\def\newfangle@chunk@append{#1}}%
35 \def\newfanglecaption{\protect\newfangle@caption}%
36 \newcounter{newfangle@chunkcounter}%
37 \def\newfangle@caption{%
38 \edef\chunkcount{lst-chunk-\lst@intname}%
39 \@ifundefined{\chunkcount}{%
40 \expandafter\gdef\csname \chunkcount\endcsname{0}%
41 \setcounter{newfangle@chunkcounter}{\csname \chunkcount\endcsname}%
42 \let\prevchunkname\relax%
44 \setcounter{newfangle@chunkcounter}{\csname \chunkcount\endcsname}%
45 \edef\prevchunkname{\lst@intname-\arabic{newfangle@chunkcounter}}%
47 \addtocounter{newfangle@chunkcounter}{1}%
48 \global\expandafter\edef\csname \chunkcount\endcsname{\arabic{newfangle@chunkcounter}}%
49 \edef\chunkname{\lst@intname-\arabic{newfangle@chunkcounter}}%
50 \edef\firstchunkname{\lst@intname-1}%
51 \addtocounter{newfangle@chunkcounter}{1}%
52 \edef\nextchunkname{\lst@intname-\arabic{newfangle@chunkcounter}}%
53 \@ifundefined{r@label-\nextchunkname}{\let\nextchunkname\relax}{}%
54 \sublabel{\chunkname}%
55 % define this label for every chunk instance, so we
56 % can tell when we are the last chunk of this name
57 \label{label-\chunkname}%
58 \addcontentsline{lol}{lstlisting}{\lst@name~[\protect\subpageref{\chunkname}]}%
62 \subpageref{\chunkname}%
70 \@ifundefined{newfangle@chunk@params}{}{%
71 (\newfangle@chunk@params)%
73 [\csname \chunkcount\endcsname]~%
74 \subpageref{\firstchunkname}%
76 \@ifundefined{newfangle@chunk@append}{}{%
77 \ifx{}\newfangle@chunk@append{x}\else%
78 ,~add~to~\newfangle@chunk@append%
81 \global\def\newfangle@chunk@append{}%
85 \ifx\relax\prevchunkname\endmoddef\else\plusendmoddef\fi%
86 % \nwstartdeflinemarkup%
87 \nwprevnextdefs{\prevchunkname}{\nextchunkname}%
88 % \nwenddeflinemarkup%
90 %\lst@BeginAspect{newfangle}
91 %\lst@Key{newfangle}{true}[t]{\lstKV@SetIf{#1}{true}}
92 \lst@AddToHookExe{PreSet}{\global\let\lst@intname\lst@chunkname}
93 \lst@AddToHook{Init}{}%\newfangle@caption}
95 \def\chunkref@args#1,{%
97 \lst@ReplaceIn\arg\lst@filenamerpl%
99 \@ifnextchar){\relax}{, \chunkref@args}%
101 \newcommand\chunkref[2][0]{%
102 \@ifnextchar({\chunkref@i{#1}{#2}}{\chunkref@i{#1}{#2}()}%
104 \def\chunkref@i#1#2(#3){%
110 \def\chunkname{#2-1}%
112 \def\chunkname{#2-\chunkno}%
115 \lst@ReplaceIn\chunk\lst@filenamerpl%
124 \ifx\chunkargs\empty%
126 (\chunkref@args #3,)%
128 ~\subpageref{\chunkname}%