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
16 \renewcommand{\code}[1]{\texttt{#1}}
17 \lstset{numbers=left, stepnumber=5, numbersep=5pt,
18 breaklines=false,basicstyle=\ttfamily,
19 numberstyle=\tiny, language=C}
20 \lstset{escapeinside={=<}{>}}
22 %somehow re-defining maketitle gives us a left-aligned title
23 %which is extactly what our specially formatted title needs!
24 \global\let\newfangle@lst@maketitle\lst@maketitle%
25 \global\def\lst@maketitle{}%
27 \lstset{title={\newfanglecaption},name=#1}%
28 \global\edef\lst@chunkname{\lst@intname}%
30 \def\lst@chunkname{\empty}%
31 \lst@Key{params}\relax{\def\newfangle@chunk@params{#1}}%
32 \def\newfanglecaption{\protect\newfangle@caption}%
33 \newcounter{newfangle@chunkcounter}%
34 \def\newfangle@caption{%
35 \edef\chunkcount{lst-chunk-\lst@intname}%
36 \@ifundefined{\chunkcount}{%
37 \expandafter\gdef\csname \chunkcount\endcsname{0}%
38 \setcounter{newfangle@chunkcounter}{\csname \chunkcount\endcsname}%
39 \let\prevchunkname\relax%
41 \setcounter{newfangle@chunkcounter}{\csname \chunkcount\endcsname}%
42 \edef\prevchunkname{\lst@intname-\arabic{newfangle@chunkcounter}}%
44 \addtocounter{newfangle@chunkcounter}{1}%
45 \global\expandafter\edef\csname \chunkcount\endcsname{\arabic{newfangle@chunkcounter}}%
46 \edef\chunkname{\lst@intname-\arabic{newfangle@chunkcounter}}%
47 \edef\firstchunkname{\lst@intname-1}%
48 \addtocounter{newfangle@chunkcounter}{1}%
49 \edef\nextchunkname{\lst@intname-\arabic{newfangle@chunkcounter}}%
50 \@ifundefined{r@label-\nextchunkname}{\let\nextchunkname\relax}{}%
51 \sublabel{\chunkname}%
52 % define this label for every chunk instance, so we
53 % can tell when we are the last chunk of this name
54 \label{label-\chunkname}%
55 \addcontentsline{lol}{lstlisting}{\lst@name~[\protect\subpageref{\chunkname}]}%
59 \subpageref{\chunkname}%
66 \nwtagstyle{}\/[\csname \chunkcount\endcsname]~%%
67 \subpageref{\firstchunkname}%
71 \ifx\relax\prevchunkname\endmoddef\else\plusendmoddef\fi%
72 % \nwstartdeflinemarkup%
73 \nwprevnextdefs{\prevchunkname}{\nextchunkname}%
74 % \nwenddeflinemarkup%
76 %\lst@BeginAspect{newfangle}
77 %\lst@Key{newfangle}{true}[t]{\lstKV@SetIf{#1}{true}}
78 \lst@AddToHookExe{PreSet}{\global\let\lst@intname\lst@chunkname}
79 \lst@AddToHook{Init}{}%\newfangle@caption}
81 \newcommand\chunkref[2][1]{%
83 \def\chunkname{#2-#1}%
85 \lst@ReplaceIn\chunk\lst@filenamerpl%
90 \subpageref{\chunkname}%