Documenting C or C ++ code with noweb and LaTeX

I use 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 nuts,
  • -- turns into an n-dash.

My weaving command:

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

Edit: so I probably need to use a pretty printer. Those that are available do too much. I will look at him, and if I find a direct solution, I will share it.

+6
source share
1 answer

Filter for noweave , implemented as a sed script, weaving command:

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

And c2nwtex is:

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

Note that this works for C, decrement, and shift operators. C ++ 11 now allows you to declare patterns with closing brackets without spaces between them. You need to run the substitute command on >> twice to split the sequence > longer than two.

+1
source

All Articles