Question

I am using noweb to document my C++ and C code. In the pdf file (generated after weaving and using pdflatex) some of the code is slightly off:

  • >> and << turn into proper opening and closing guillemets;
  • -- turns into an n-dash.

My weaving command is:

noweave -latex -delay -x foo.nw > foo.tex

Edit: so I probably need to use a prettyprinter. Those that are available do way too much. I will look into it and if I find a straight-forward solution I will share it.

Was it helpful?

Solution

A filter for noweave implemented as a sed script, weaving command is:

noweave -x -delay -latex -filter c2nwtex foo.nw > foo.tex

And c2nwtex is this:

#!/bin/sed -f
/^@begin code/ , /^@end code/ {
/^@text/ {
s/--/-\
@literal {}\
@text -/g
s/>>/>\
@literal {}\
@text >/g
s/<</<\
@literal {}\
@text </g
}
}

Note that that works for C, decrement and shift operators. C++11 allows now template declarations with closing angle brackets without space between them. You need to run the substitute command on >> twice to break up a sequence of > longer than two.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top