# How to get noweb and listings to cooperate?

The introduction of the Linux subsystem for Windows has made it possible again to use noweb (https://www.cs.tufts.edu/~nr/noweb/) under Windows. I'd like to pretty-print the resulting code, for which arguably the listings package is the method of choice.

% -*- TeX:UK -*-
\NeedsTeXFormat{LaTeX2e}
\documentclass[british,pdftex,twoside,12pt,notitlepage]{article}
\usepackage[utf8]{inputenc}%suitable for most modern operating systems
\usepackage[T1]{fontenc}
\usepackage{babel,%foreign language support
xcolor,%handle colours
css-colors,%defines named web-safe colors
listings,%typeset computer code
noweb}%support for literate programming
\frenchspacing
\selectlanguage{british}
\lstset{backgroundcolor=\color{Cornsilk},
language=[Borland6]Pascal,
numbers=left, numberstyle=\tiny, stepnumber=1, numbersep=5pt,
}
\title{Example}
\author{Engelbert Buxbaum }
\date{\today}
\begin{document}
@
\maketitle
\abstract{Noweb is a simple to use system for literate programming. It
is suitable for all programming languages, but has no
pretty-printing capabilities. Listings can pretty-print, but has no
literate programming ability. A combination of both would be ideal. }
The example code is:
\begin{lstlisting}
<<*>>=
program HelloWorld;
begin
write('Hello, World');
end
@
\end{lstlisting}
Unfortunately, the output is not what was intended.
\end{document}


noweave -delay test.nw > test.tex produces the following LaTeX-code (critical piece only):

\begin{lstlisting}
\nwenddocs{}\nwbegincode{2}\moddef{*}\endmoddef\nwstartdeflinemarkup
\nwenddeflinemarkup
program HelloWorld;
begin
write('Hello, World');
end
\nwendcode{}\nwbegindocs{3}\nwdocspar
\end{lstlisting}


iow, some code for noweb.sty ends up in the listings environment and is printed verbatim rather than executed. Putting the \begin{lstlisting} and \end{lstlisting} between the <<*>> and @ is of course no solution.

How can I do this? Thanks in advance.

Engelbert

• Do you have any news for us? Is your issue solved? How? Jun 23, 2019 at 19:27
• No, unfortunately not. Currently, I maintain the docs and the source code separately, which of course is contrary to literate programming doctrine. Jun 25, 2019 at 14:47
• Well, then you should perhaps explain what "noweb" is, never heared of it. Just explain your issue better ... Jun 29, 2019 at 0:46
• As I mentioned, noweb (cs.tufts.edu/~nr/noweb) is a tool for literate programming. Unlike Knuth's original web (and its successor cweb) it is language-independent as it has no pretty-printing ability. Literate programming means that the source code of a program and its docu are maintained in a single file, from which (no)weave extracts the docu and (no)tangle the source code. The idea behind that is that because code and docu are maintained in a single file, they are always updated together, and the docu always reflects the current state of the code. Jun 30, 2019 at 9:52