Noweave and Troff output
Closed this issue · 10 comments
I tried to send this message to arnold but it was returned undeliverable.
I have an odd issue that I am trying to figure out.
If I run the following fragment using noweave -troff I get the references section in a code like layout. If I use noweave -index -troff, the same section is formatted without newlines.
@
.SH
Notes from Lewin et al (2011)
.LP
Referenced from Berta et al (2015)
<<references.bib>>=
%T Microfoundations of internal and external absorptive capacity routines
%J Organization Science
%D 2011
%P 81-98
%V 22
%N 1
%K Lewin et al (2011)
%A Arie\0Y. Lewin
%A Silvia Massini
%A Carine Peeters
With noweave -troff (the full file replaces the ??? with a .DEFINITION 1a "references.bib" 1a (==) I get the following:
.DEFINITION ??? "references.bib" (==
.NEWLINE
&%T Microfoundations of internal and external absorptive capacity routines\c
.NEWLINE
&%J Organization Science\c
with noweave -troff -index
.DEFINITION ??? "references.bib" ??? (==
.STARTXREF
.XREFNOTUSED
%T Microfoundations of internal and external absorptive capacity routines
%J Organization Science
%D 2011
I can fix this in a long file by first doing a run and getting the definitions using noweave -index -troff and then substituting the definitions in the file generated using noweave -troff using awk - so can work around the issue. I also read somewhere that I needed to do two passes to get the file working correctly, but there appears to be a bit of a glitch here.
I'm using v 1.6 and looking at the sources on github, there's no significant difference in the noweave element of the code. I also use ms rather than mm which appears to be the default. I was just wondering if you had any thoughts on this.
The issue seems to resolve itself further down but it's a problem at the start.
Not sure when I can get to this. We'll see.
I had a look, but this issue is beyond my ability to fix.
I get a similar bug. There is no newline when I add "-index" option.
and the code is wrong format.
And I am trying to fix it.
demo code
filename demo.nw
.PP
This is pragraph.
<<c_troff.c>>=
/*
* Some comment.
*/
#include <stdio.h>
int main(vid)
{
printf("Hello World!\n");
return 0;
}
@
filename makefile(bmake you need)
target = demo
target_noindex = demo_noindex
all_objs = ${target}.troff ${target}.pdf \
${target_noindex}.troff ${target_noindex}.pdf
WEAVE = noweave
TANGLE = notangle
NOROFF = noroff
.PHONY: all
all: ${all_objs}
${target_noindex}.troff: ${target}.nw
${WEAVE} -troff ${.ALLSRC} > ${.TARGET}
.PHONY: clean
clean:
rm -f ${all_objs} ${target}.nwt
.SUFFIXES: .nw .troff .pdf
.nw.troff:
${WEAVE} -index -troff ${.ALLSRC} > ${.TARGET}
.troff.pdf:
${NOROFF} -ms -Tpdf ${.ALLSRC} > ${.TARGET}
For alternative shell scipt
noweave -index -troff demo.nw > demo.troff
noroff -ms -Tpdf demo.troff > demo.pdf
noweave -troff demo.nw > demo_noindex.troff
noroff -ms -Tpdf demo_noindex.troff > demo_noindex.pdf
There are some bug.
Bug 1: addtional right adjustion right-aligned.
in file noweb.tmac. (In fact, I think it maybe typping error)
diff noweb.tmac fix_noweb.tmac
64c64
< 'ad r \" right-adjust continuation lines
---
> .ad r \" right-adjust continuation lines
Bug 2: the font style and size is changed by macro STARTXREF. But not to reset.
you need to change font style to CW.
.de STARTXREF
.ps \\n(.s*4/5
.vs \\n(.vu*4u/5u
.ft \\n[OLDft] \"changed the old font style, but it is not code font style.
.ad \\n[OLDad] \" change the code the aligned.
.dt \\n[TRAPplace]u
.sp 0.4v
..
But for Bug2, .XREFUSES macro also need reset to code's.
I don't know if other macro need too.
Bug 3: The disappear NEWLINE (not solved)
Part file with "-index" option
file demo.troff
.BEGINCODECHUNK
.DEFINITION 1a "c_troff.c" 1a \(==
.STARTXREF
.XREFNOTUSED
/*
* Some comment.
*/
#include <stdio.h>
int main(vid)
{
printf("Hello World!\n");
return 0;
}
.ENDCODECHUNK NW4RzLIJ-4UVw3Y-1
Part file without "-index" option
file demo_noindex.troff
.BEGINCODECHUNK
.DEFINITION ??? "c_troff.c" \(==
.NEWLINE
\&/*\c
.NEWLINE
\& * Some comment.\c
.NEWLINE
\& */ \c
.NEWLINE
\&#include <stdio.h>\c
.NEWLINE
\&int main(vid)\c
.NEWLINE
\&{\c
.NEWLINE
\& printf("Hello World!\en");\c
.NEWLINE
\& return 0;\c
.NEWLINE
\&}\c
.NEWLINE
.ENDCODECHUNK
Obviously, There are some .NEWLINE gone. I glanced toroff's source code and
nothing I got.
For bug 3(NEWLINE disappear).I found "noidx" or "toroff" is error.
I checked the noweave's code.
First you need find where is you noweb' library directory. For me is /usr/lib/noweb, then copy markup, fixuses, noidx and noroff to current directory.
noweave -troff -index demo.nw
equal
./markup demo| ./finduses | ./noidx | ./noroff
The NEWLINE gone again. After test, I got the minimal demo.
file demo_newline.finduses
@begin code 1
@defn c_troff.c
@text line 1
@nl
@text line 2
@nl
@end code 1
build as follow:
cat demo_newline.finduses | ./nodix | toroff > demo_error.troff
cat demo_newline.finduses | toroff > demo_right.troff
There have two key conditions to reappear.
- code enviroment.
- have defn keyword.
There is nothing I can do. Because I don't know awk program well.
All test demo is here just in case.
filename demo.nw
<<c_troff.c>>=
/*
* Some comment.
*/
#include <stdio.h>
int main(vid)
{
printf("Hello World!\n");
return 0;
}
@
For build (noweb library path you need to find firstly)
./markup demo.nw | ./finduses | ./noidx | ./noroff > demo_error.troff
./markup demo.nw | ./finduses | ./noroff > demo_right.troff
The test code you provided violates an invariant that is state on
page 4 of the Hacker's Guide:
The first structural keyword in any code chunk must be @defn. @defn
may be preceded or followed by tagging keywords, but the next
structural keyword must be @nl
As for the bug being addressed here,
the essence of the issue appears to be as follows: toroff
assumes
that an @xref notused
tag must mark the end of the code chunk.
Since this isn't so, things go haywire.
A person wanting to work around this bug could consider writing a
Noweb filter that sinks all @xref
keywords to the end of the code
chunk in which they appear.
After readed the Hacker's Guide, I saw code again.
The variable code
of enviroment which in @begin code to @end code
has been changed by @xref notuesd
. So code go wrong.
By the way, the structural keyword @begin code is silightly odd.
Becase its contents consists of not only code, but also some comments like
This code not used in this document
.