Go to page:

Search:   Help

Navigation

Groups

LyX documentation

Edit

Shared groups

Links

Noweb

Categories: Category noweb
<< | Page list | >>

A lyx document that explains how to get Lyx 1.6.2 working with noweb 2.11b, because sadly notangle garbles the output, and so does noweave to a lesser degree.

Goal

Generate sane C files and Latex documents from Lyx, suitable for use from a Makefile.

Sadly notangle is not able to un-lyx-ify lyx noweb documents, it requires Lyx to do TeX export, which Lyx can do:

 lyx -e literate FILENAME.lyx

which produces FILENAME.tex

If noweb is used works on the .Lyx file, we find some problems:

In a code scrap, a newline is not used to signify a newline, these signify a newline:

 \begin_inset Newline newline
 \end_inset

notangle is also unable to un-escape backslashes in the code scrap, which come out as:

 \backslash

notangles's -L mode is also broken and ruins the indentation included noweb blocks in the generated code, as well as interrupting multi-line #define's.

Noweave with Lyx also generates spoiled output, with << in the code becoming a guillemot (double chevron as a single character), the fact that chunk names fail if they have an underscore in the name; e.g. <<file_name.c>>

Solution

Some awk scripts to fixup notangle output and some sed filters to fixup the weave output.

Files

I don't have access to uploads on this wiki so the files will be somewhat out of date.

The Lyx document that explains it all is found at: uploads:/noweb/noweb-lyx.lyx

The older notanglefix is found at: uploads:/noweb/notanglefix

Installation

Ultimately you may want to have noweb-lyx.lyx accessible from your build tree so that you can automatically extract the latest notanglefix-filter and Makefile.inc, but generally you will just need to extract a Makefile.inc and notanglefix-filter and put them in your source tree.

For generating better noweave output you will need to change the Lyx noweb convertor to:

 sed '/^ *<</s/_/\\_/g' $$i |
 sed 's/{\[}{\[}/\[\[/g;s/{\]}{\]}/\]\]/g' |
 noweave -delay -index - |
 sed 's/@<\\textcompwordmark{}</<\\textcompwordmark{}</g;' |
 sed '/[^\\]\\nwbegincode/h;
      /[^\\]\\nwendcode/h;
      /<</{x;/begincode/{x;s/<</<\\textcompwordmark</g;x};x};
      />>/{x;/begincode/{x;s/>>/>\\textcompwordmark>/g;x};x}'
 > $$o

The reasoning behind this filter is explained in uploads:/noweb/noweb-lyx.lyx

Usage

If you don't have notanglefix-filter, you can extract it like this:

 notangle -Rnotanglefix-filter -filter "
                 /bin/sed '/^@nl/d;
                           /@text \\\\end_/d;
                           s/^@text \\\\begin_inset Newline newline/@nl/;
                           s/^@text \\\\backslash/@text \\\\/'
                        " noweb-lyx.lyx

 chmod +x notanglefix-filter

Example

Once you have the file ./notanglefix-filter, can invoke like this to generate #line directives in the extracted code; e.g.

  notanglefixlines=1 notangle -f ./notanglefix-filter -Rexample noweb-lyx.lyx

or without the #line directives:

  notangle -f ./notanglefix-filter -Rexample noweb-lyx.lyx

You can also use the older notanglefix to un-mangled extracted source like this:

 notangle -Rchunk file.lyx | awk -f notanglefix > chunk

Comments, Bugs

Leave this field for future bugs or comments for your script

A Python clone of noweb is available at https://github.com/JonathanAquino/noweb.py . Since LyX already uses python scripts, I think it may be a good idea checking out this project.

Contributors

Categories

Category noweb

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2013-11-26 15:24 CET