From 4f6c0b520208b397f07c4aa9f0fe6cfcd02d7a2f Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 28 Nov 2012 12:54:34 +0100 Subject: [PATCH] Fix # 8414: Use the noweb module instead of literate-* article layouts Now that we have module support for literate programming, it is possible to do a noweb cleanup. This is basically a patch from Kayvan Sylvan: - get rid of literate-xxx classes - rename Scrap to Chunk, since this is the name noweb doc uses (Scrap is from nuweb) - update lyx file format and add lyx2lyx support for gettting rid of literate-xxx classes - update documentation On the top of it, update tex2lyx to - avoid creating files with literate-xxx class - fix conflict between parsing << as a quote and parsing it as a Chunk - create Chunk layouts instead of Scrap ones. --- development/FORMAT | 9 + lib/Makefile.am | 8 +- lib/configure.py | 2 +- lib/doc/Additional.lyx | 400 ++++++------ lib/examples/Literate.lyx | 543 +++++++-------- lib/examples/listerrors.lyx | 351 +++++----- lib/examples/noweb2lyx.lyx | 617 ++++++++++++------ lib/examples/sweave.lyx | 34 +- .../{layout_Scrap.png => layout_Chunk.png} | Bin .../{layout_Scrap.png => layout_Chunk.png} | Bin lib/layouts/literate-article.layout | 13 - lib/layouts/literate-book.layout | 13 - lib/layouts/literate-report.layout | 13 - lib/layouts/literate-scrap.inc | 31 - lib/layouts/noweb.module | 7 +- lib/lyx2lyx/lyx_2_1.py | 35 +- src/tex2lyx/Preamble.cpp | 2 - src/tex2lyx/tex2lyx.cpp | 2 +- src/tex2lyx/text.cpp | 30 +- src/version.h | 4 +- 20 files changed, 1127 insertions(+), 987 deletions(-) rename lib/images/classic/{layout_Scrap.png => layout_Chunk.png} (100%) rename lib/images/{layout_Scrap.png => layout_Chunk.png} (100%) delete mode 100644 lib/layouts/literate-article.layout delete mode 100644 lib/layouts/literate-book.layout delete mode 100644 lib/layouts/literate-report.layout delete mode 100644 lib/layouts/literate-scrap.inc diff --git a/development/FORMAT b/development/FORMAT index 391b414ef0..93b8004e68 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -12,6 +12,15 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx. ----------------------- +2012-11-25 Kayvan Sylvan + * Format incremented to 448: Change Noweb literate style Scrap + to Chunk to be consistent with all the other literate tools + (including noweb!) and add the needed preamble bits to Noweb module + support, also remove the literate-* layouts. + +2012-11-24 Uwe Stöhr + * Format incremented to 447: IEEEtran layout revision. + 2012-11-19 Jürgen Spitzmüller * Format incremented to 446: Change of InsetArgument syntax. InsetArgument now has a numeric identifier which determines diff --git a/lib/Makefile.am b/lib/Makefile.am index f5ef988f1f..4940d8afe5 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -399,7 +399,7 @@ dist_images_DATA = \ images/layout_Itemize.png \ images/layout_List.png \ images/layout_LyX-Code.png \ - images/layout_Scrap.png \ + images/layout_Chunk.png \ images/layout_Section.png \ images/lyx-quit.png \ images/marginalnote-insert.png \ @@ -1365,7 +1365,7 @@ dist_imagesclassic_DATA = \ images/classic/layout_Itemize.png \ images/classic/layout_List.png \ images/classic/layout_LyX-Code.png \ - images/classic/layout_Scrap.png \ + images/classic/layout_Chunk.png \ images/classic/layout_Section.png \ images/classic/marginalnote-insert.png \ images/classic/master-buffer-update.png \ @@ -1588,10 +1588,6 @@ dist_layouts_DATA =\ layouts/lettre.layout \ layouts/lilypond.module \ layouts/linguistics.module \ - layouts/literate-article.layout \ - layouts/literate-book.layout \ - layouts/literate-report.layout \ - layouts/literate-scrap.inc \ layouts/llncs.layout \ layouts/logicalmkup.module \ layouts/ltugboat.layout \ diff --git a/lib/configure.py b/lib/configure.py index 837320e091..a1fa57a800 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -647,7 +647,7 @@ def checkConverterEntries(): path, t2l = checkProg('a LaTeX/Noweb -> LyX converter', [in_place, 'tex2lyx' + version_suffix, 'tex2lyx'], rc_entry = [r'''\converter latex lyx "%% -f $$i $$o" "" -\converter literate lyx "%% -n -f $$i $$o" ""'''], not_found = 'tex2lyx') +\converter literate lyx "%% -n -m noweb -f $$i $$o" ""'''], not_found = 'tex2lyx') if path == '': logger.warning("Failed to find tex2lyx on your system.") diff --git a/lib/doc/Additional.lyx b/lib/doc/Additional.lyx index 70c435062a..a4d0c21865 100644 --- a/lib/doc/Additional.lyx +++ b/lib/doc/Additional.lyx @@ -1,5 +1,5 @@ #LyX 2.1 created this file. For more info see http://www.lyx.org/ -\lyxformat 445 +\lyxformat 447 \begin_document \begin_header \textclass scrbook @@ -38,6 +38,7 @@ % extra space for tables \newcommand{\extratablespace}[1]{\noalign{\vskip#1}} +\usepackage{enumitem} \end_preamble \options fleqn,bibliography=totoc,index=totoc,BCOR7.5mm,titlepage,captions=tableheading \use_default_options false @@ -79,7 +80,7 @@ End \font_tt_scale 100 \graphics default \default_output_format default -\output_sync 1 +\output_sync 0 \bibtex_command default \index_command default \paperfontsize 12 @@ -135,7 +136,7 @@ End \html_math_output 0 \html_css_as_file 0 \html_be_strict true -\author 274215730 "scott" +\author 819523532 "Kayvan Sylvan" \end_header \begin_body @@ -14993,7 +14994,7 @@ Poemtitle*: Same as poemtitle, but it adds no entry to the table of contents. \begin_layout Section Article (mwart), book (mwbk) and report (mwrep) -\begin_inset Argument +\begin_inset Argument status status collapsed \begin_layout Plain Layout @@ -21378,11 +21379,7 @@ Starting from there you can reach many other interesting links and even \end_layout \begin_layout Subsection -LyX and Literate Programming -\change_inserted 274215730 1350434640 - with Noweb -\change_unchanged - +LyX and Literate Programming with Noweb \end_layout \begin_layout Standard @@ -21413,51 +21410,38 @@ Generating documents and code (weaving and tangling) \end_layout \begin_layout Paragraph -Selecting the document class +Using the noweb module \end_layout \begin_layout Standard If you have installed Noweb and LyX successfully, whenever you open a new - document or try to change the document class of an existing one, you will - find that there are three new document classes available: -\end_layout - -\begin_layout Itemize -Article (Noweb) -\end_layout - -\begin_layout Itemize -Book (Noweb) -\end_layout - -\begin_layout Itemize -Report (Noweb) -\end_layout - -\begin_layout Standard -You must select one of them to create your literate documents from. - -\end_layout - -\begin_layout Standard -Note that literate documents are not limited to these three classes. - New classes can be generated from other styles like letter or in combination - with other class variations like Article (AMS). - If you have special needs that cannot be covered by one of the existing - classes, let the LyX developers list (lyx-devel@lists.lyx.org) know and we - will arrange to insert a new entry, or teach you how to do it. -\begin_inset Foot -status collapsed - -\begin_layout Plain Layout -It is very simple, it involves the creation of a file with four lines, and - re-running of the auto configuration. -\end_layout - + document, after you have chosen its document class, use the Document->Settings + menu to add the +\begin_inset Quotes eld \end_inset - Moreover, if you use a literate tool other than Noweb you may need to create - a new set of document classes for it. +noweb +\begin_inset Quotes erd +\end_inset + + module. + If Noweb is correctly installed, when you click on the +\begin_inset Quotes eld +\end_inset + +Modules +\begin_inset Quotes erd +\end_inset + + link, you will see the +\begin_inset Quotes eld +\end_inset + +noweb +\begin_inset Quotes erd +\end_inset + + module in the available list and you can add it to your document. \end_layout \begin_layout Paragraph @@ -21466,10 +21450,32 @@ Typing code in \begin_layout Standard LyX enables you to write code with a layout named +\change_inserted 819523532 1353904450 + +\begin_inset Flex Noun +status collapsed + +\begin_layout Plain Layout + +\change_inserted 819523532 1353904450 +Chunk +\change_unchanged + +\end_layout + +\end_inset + + +\change_deleted 819523532 1353904406 + \noun on Scrap +\change_unchanged + \noun default . +\change_deleted 819523532 1353904396 + \begin_inset Foot status collapsed @@ -21497,11 +21503,25 @@ scrap \end_inset - Noweb delimits scraps like this: + +\change_unchanged + Noweb delimits +\change_deleted 819523532 1353904459 +scraps +\change_inserted 819523532 1353904461 +chunks +\change_unchanged + like this: \end_layout \begin_layout LyX-Code -<>= +<>= \end_layout \begin_layout LyX-Code @@ -21535,76 +21555,13 @@ e. LyX should be prevented from making any special interpretation of what has been written. - This is handled by a special layout named Scrap, that works like a normal - paragraph but has a free spacing capability. -\end_layout - -\begin_layout Standard -The down -\change_deleted 274215730 1350432842 - + This is handled by a special layout named +\change_deleted 819523532 1353904493 +Scrap +\change_inserted 819523532 1353904494 +Chunk \change_unchanged -side of the Scrap paragraph layout is that consecutive paragraphs of code - will be spaced with one empty line in the source code and also in the printed - documentation. - The work around is to enter each line of code within a single Scrap, with - a newline (ctrl-return). - The example above will look like this: -\begin_inset Foot -status collapsed - -\begin_layout Plain Layout -If you have a printed version of this document you will not see any difference - between the previous example and this one. -\end_layout - -\end_inset - - -\end_layout - -\begin_layout LyX-Code -<>= -\begin_inset Newline newline -\end_inset - - code -\begin_inset Newline newline -\end_inset - - more code -\begin_inset Newline newline -\end_inset - - even more code -\begin_inset Newline newline -\end_inset - - @ -\end_layout - -\begin_layout Standard -This layout works fine. - The only real inconvenience is that you have to type ctrl-return instead - of a plain return. -\begin_inset Foot -status collapsed - -\begin_layout Plain Layout -It is in my list of -\begin_inset Quotes eld -\end_inset - -improvements -\begin_inset Quotes erd -\end_inset - - to fix that. -\end_layout - -\end_inset - - +, that works like a normal paragraph but has a free spacing capability. \end_layout \begin_layout Standard @@ -21616,24 +21573,53 @@ As a special note, you can also use the \begin_inset Quotes erd \end_inset - construct of Noweb in your scraps to add items to Noweb's identifier cross-refe -rence: + construct of Noweb in your +\change_deleted 819523532 1353904503 +scraps +\change_inserted 819523532 1353904504 +chunks +\change_unchanged + to add items to Noweb's identifier cross-reference: \end_layout \begin_layout LyX-Code -<>= -\begin_inset Newline newline -\end_inset +<>= +\change_inserted 819523532 1353904523 - def some_function(args): -\begin_inset Newline newline -\end_inset +\end_layout - "This is the doc string for this function." -\begin_inset Newline newline -\end_inset +\begin_layout LyX-Code - print "My args: ", args +\change_deleted 819523532 1353904528 + +\change_unchanged +def some_function(args): +\change_inserted 819523532 1353904543 + +\end_layout + +\begin_layout LyX-Code + +\change_deleted 819523532 1353904543 + +\change_unchanged + "This is the doc string for this function." +\change_inserted 819523532 1353904550 + +\end_layout + +\begin_layout LyX-Code + +\change_deleted 819523532 1353904550 + +\change_unchanged + print "My args: ", args \end_layout \begin_layout LyX-Code @@ -21703,8 +21689,13 @@ literate \begin_layout Enumerate Note that the only difference so far is in the name of the file, no special processing is required by LyX. - Given that you formatted the code using the Scrap layout that, by itself, - takes care of the business. + Given that you formatted the code using the +\change_deleted 819523532 1353904586 +Scrap +\change_inserted 819523532 1353904587 +Chunk +\change_unchanged + layout that, by itself, takes care of the business. \end_layout \begin_layout Enumerate @@ -21909,7 +21900,13 @@ Noweb->Program conversion may produce several files, and so most of these would then be deleted when LyX was closed. This is why we pass in the NOWEB_OUTPUT_DIR environment variable so that - the build-script scrap can place the generated files in that location. + the build-script +\change_deleted 819523532 1353904613 +scrap +\change_inserted 819523532 1353904614 +chunk +\change_unchanged + can place the generated files in that location. \end_layout \begin_layout Paragraph @@ -21925,9 +21922,21 @@ build-script \begin_inset Quotes erd \end_inset - scrap. + +\change_deleted 819523532 1353904625 +scrap +\change_inserted 819523532 1353904625 +chunk +\change_unchanged +. Generally, the instructions for building your program should be embedded - in a scrap of its own. + in a +\change_deleted 819523532 1353904630 +scrap +\change_inserted 819523532 1353904630 +chunk +\change_unchanged + of its own. The noweb-specific \begin_inset Quotes eld \end_inset @@ -21936,7 +21945,13 @@ build-script \begin_inset Quotes erd \end_inset - above uses the notangle command to look for this scrap (called + above uses the notangle command to look for this +\change_deleted 819523532 1353904632 +scrap +\change_inserted 819523532 1353904632 +chunk +\change_unchanged + (called \begin_inset Quotes eld \end_inset @@ -21956,50 +21971,21 @@ sh \end_layout \begin_layout Standard -Typically, such a scrap would look something like this: +Typically, such a +\change_deleted 819523532 1353904634 +scrap +\change_inserted 819523532 1353904634 +chunk +\change_unchanged + would look something like this: \end_layout \begin_layout LyX-Code -<>= -\begin_inset Newline newline -\end_inset - -#!/bin/sh -\begin_inset Newline newline -\end_inset - - -\begin_inset Newline newline -\end_inset - -if [ -z "${NOWEB_SOURCE}" ] -\begin_inset Newline newline -\end_inset - -then -\begin_inset Newline newline -\end_inset - - NOWEB_SOURCE=myfile.nw -\begin_inset Newline newline -\end_inset - -fi -\begin_inset Newline newline -\end_inset - -[... +<>=#!/bin/shif [ -z "${NOWEB_SOURCE}" ]then NOWEB_SOURCE=myfile.nw +fi[... code to extract files ... - use NOWEB_OUTPUT_DIR here ...] -\begin_inset Newline newline -\end_inset - -[... - code to compile files ...] -\begin_inset Newline newline -\end_inset - -@ + use NOWEB_OUTPUT_DIR here ...][... + code to compile files ...]@ \end_layout \begin_layout Standard @@ -22214,11 +22200,8 @@ Helpers \end_layout \begin_layout Standard -I take advantage of the new -\change_inserted 274215730 1350432999 -ly -\change_unchanged - created LyX server function and this ddd feature, and set +I take advantage of the newly created LyX server function and this ddd feature, + and set \begin_inset Quotes eld \end_inset @@ -22236,15 +22219,9 @@ echo "LYXCMD:monitor:server-goto-file-row:@FILE@ @LINE@" >~/.lyxpipe.in \begin_layout Standard With this, whenever you are using ddd and find a point in the program that you want to edit, you just press shift-ctrl-V (in the ddd window), and - ddd -\change_deleted 274215730 1350433047 -you -\change_inserted 274215730 1350433047 -will -\change_unchanged - forward this information to LyX through the LyX server and then the LyX - window will show the same file with the cursor at the same position ddd - was pointing to. + ddd will forward this information to LyX through the LyX server and then + the LyX window will show the same file with the cursor at the same position + ddd was pointing to. No more guessing or long scrolling to locate a point in the program back from debugging ! \end_layout @@ -22314,8 +22291,14 @@ LaTeX LyX-Code \family default , and +\change_deleted 819523532 1353904643 + \family sans Scrap +\change_inserted 819523532 1353904651 +Chunk +\change_unchanged + \family default . The last one is a short cut to the @@ -22381,7 +22364,13 @@ Toolbar \end_layout \begin_layout LyX-Code - Icon "layout Scrap" + Icon "layout +\change_deleted 819523532 1353904661 +Scrap +\change_inserted 819523532 1353904668 +Chunk +\change_unchanged +" \end_layout \begin_layout LyX-Code @@ -22431,9 +22420,19 @@ Preferences \family default . One of the things that bothers people is the LaTeX font color. - The default color is red, since the scraps uses LaTeX font, and there is - a lot of scraps in literate documents, you may get tired of seeing everything - in red. + The default color is red, since the +\change_deleted 819523532 1353904675 +scrap +\change_inserted 819523532 1353904675 +chunk +\change_unchanged +s uses LaTeX font, and there is a lot of +\change_deleted 819523532 1353904682 +scrap +\change_inserted 819523532 1353904682 +chunk +\change_unchanged +s in literate documents, you may get tired of seeing everything in red. You can change it by going to the tabs \family sans Look&Feel @@ -22450,26 +22449,15 @@ The next thing is the visible presence of the newline character in the screen. I recommend you choosing a color that is close to the background but not equal, that way you still can see it is there, but it is not bothering you anymore. - -\change_deleted 274215730 1350434691 - -\change_inserted 274215730 1350434708 - \end_layout \begin_layout Subsection - -\change_inserted 274215730 1350434732 LyX and knitr/Sweave \end_layout \begin_layout Standard - -\change_inserted 274215730 1350434777 Support for knitr and Sweave is documented in the knitr.lyx example file and in the Sweave manual (in the Help > Specific Manuals submenu). -\change_unchanged - \end_layout \begin_layout Chapter diff --git a/lib/examples/Literate.lyx b/lib/examples/Literate.lyx index 2211f7bc5e..bcf37a358d 100644 --- a/lib/examples/Literate.lyx +++ b/lib/examples/Literate.lyx @@ -1,9 +1,12 @@ #LyX 2.1 created this file. For more info see http://www.lyx.org/ -\lyxformat 442 +\lyxformat 448 \begin_document \begin_header -\textclass literate-article +\textclass article \use_default_options false +\begin_modules +noweb +\end_modules \maintain_unincluded_children false \language english \language_package default @@ -169,131 +172,131 @@ The filter is required to read from standard input, parse for error messages Algorithm \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk int \end_layout -\begin_layout Scrap +\begin_layout Chunk main (int argc, char **argv) \end_layout -\begin_layout Scrap +\begin_layout Chunk { \end_layout -\begin_layout Scrap +\begin_layout Chunk if (argc == 2) { \end_layout -\begin_layout Scrap +\begin_layout Chunk switch (argv[1][0]) { \end_layout -\begin_layout Scrap +\begin_layout Chunk case 'n': \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk break; \end_layout -\begin_layout Scrap +\begin_layout Chunk case 'x': \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk break; \end_layout -\begin_layout Scrap +\begin_layout Chunk case 'a': \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk break; \end_layout -\begin_layout Scrap +\begin_layout Chunk case 's': \end_layout -\begin_layout Scrap +\begin_layout Chunk case 'b': \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk break; \end_layout -\begin_layout Scrap +\begin_layout Chunk case 'g': \end_layout -\begin_layout Scrap +\begin_layout Chunk default: \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk break; \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk } else { \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk int main (int argc, char **argv); \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -308,11 +311,11 @@ We resort to some global variables to allow access from several different input. \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk char buffer[200][200]; \begin_inset Newline newline \end_inset @@ -360,37 +363,37 @@ This function has been slightly changed from EW's original to make scanning \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk void \end_layout -\begin_layout Scrap +\begin_layout Chunk output_error (int buf_size, int error_line, char *tool) \end_layout -\begin_layout Scrap +\begin_layout Chunk { \end_layout -\begin_layout Scrap +\begin_layout Chunk int i; \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk fprintf(stdout, "! Build Error: ==> %s ==> \backslash n", tool); \end_layout -\begin_layout Scrap +\begin_layout Chunk fprintf(stdout, " ... \backslash n @@ -400,49 +403,49 @@ nl.%d ... n", error_line); \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk for (i=0; i>= \end_layout -\begin_layout Scrap +\begin_layout Chunk void output_error (int buf_size, int error_line, char *tool); \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -459,39 +462,39 @@ Both noweave and notangle routines, always output one single line for each of the file. \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk { \end_layout -\begin_layout Scrap +\begin_layout Chunk last_buf_line = 0; \end_layout -\begin_layout Scrap +\begin_layout Chunk while (fgets(buffer[0], 200, stdin)) { \end_layout -\begin_layout Scrap +\begin_layout Chunk if (noweb_try(0)) \end_layout -\begin_layout Scrap +\begin_layout Chunk output_error(1, err_line, "noweb"); \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -504,87 +507,87 @@ The examination itself is very inefficient. array. \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk char *noweb_msgs[] = { \end_layout -\begin_layout Scrap +\begin_layout Chunk "couldn't open file", \end_layout -\begin_layout Scrap +\begin_layout Chunk "couldn't open temporary file", \end_layout -\begin_layout Scrap +\begin_layout Chunk "error writing temporary file", \end_layout -\begin_layout Scrap +\begin_layout Chunk "ill-formed option", \end_layout -\begin_layout Scrap +\begin_layout Chunk "unknown option", \end_layout -\begin_layout Scrap +\begin_layout Chunk "Bad format sequence", \end_layout -\begin_layout Scrap +\begin_layout Chunk "Can't open output file", \end_layout -\begin_layout Scrap +\begin_layout Chunk "Can't open temporary file", \end_layout -\begin_layout Scrap +\begin_layout Chunk "Capacity exceeded:", \end_layout -\begin_layout Scrap +\begin_layout Chunk "Ignoring unknown option -", \end_layout -\begin_layout Scrap +\begin_layout Chunk "This can't happen:", \end_layout -\begin_layout Scrap +\begin_layout Chunk "non-numeric line number in" \end_layout -\begin_layout Scrap +\begin_layout Chunk }; \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk char *noweb_msgs_mimic_gcc[] = { \end_layout -\begin_layout Scrap +\begin_layout Chunk ": unescaped << in documentation chunk" \end_layout -\begin_layout Scrap +\begin_layout Chunk }; \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -605,11 +608,11 @@ A noweb error message can be any string that contains a matching pair of > >, or any of the above strings \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \begin_inset Newline newline \end_inset @@ -761,15 +764,15 @@ noweb_try (int buf_line) @ \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk int noweb_try (int buf_line); \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -779,39 +782,39 @@ The xlc compiler always outputs one single line for each error found, thus line at a time. \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk { \end_layout -\begin_layout Scrap +\begin_layout Chunk last_buf_line = 0; \end_layout -\begin_layout Scrap +\begin_layout Chunk while (fgets(buffer[last_buf_line], 200, stdin)) { \end_layout -\begin_layout Scrap +\begin_layout Chunk if (xlc_try(0)) \end_layout -\begin_layout Scrap +\begin_layout Chunk output_error(1, err_line, "xlc"); \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -830,93 +833,93 @@ line The following routine tests if a given buffer line matches this criteria: \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk int \end_layout -\begin_layout Scrap +\begin_layout Chunk xlc_try (int buf_line) \end_layout -\begin_layout Scrap +\begin_layout Chunk { \end_layout -\begin_layout Scrap +\begin_layout Chunk char *s, *t; \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk t = buffer[buf_line]; \end_layout -\begin_layout Scrap +\begin_layout Chunk s = t+1; \end_layout -\begin_layout Scrap +\begin_layout Chunk while (*s != '"' && *s != ' ' && *s != ' \backslash 0') \end_layout -\begin_layout Scrap +\begin_layout Chunk s++; \end_layout -\begin_layout Scrap +\begin_layout Chunk if (*t != '"' || *s != '"' || strncmp(s+1, ", line ", 7) != 0) \end_layout -\begin_layout Scrap +\begin_layout Chunk return 0; \end_layout -\begin_layout Scrap +\begin_layout Chunk s += 8; \end_layout -\begin_layout Scrap +\begin_layout Chunk err_line = atoi(s); \end_layout -\begin_layout Scrap +\begin_layout Chunk return 1; \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk int xlc_try (int buf_line); \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -956,146 +959,146 @@ Every gcc error message contains a string with no space followed by a . \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk { \end_layout -\begin_layout Scrap +\begin_layout Chunk char *s, *t; \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk last_buf_line = 0; \end_layout -\begin_layout Scrap +\begin_layout Chunk while (fgets(buffer[last_buf_line], 200, stdin)) { \end_layout -\begin_layout Scrap +\begin_layout Chunk /****** Skip lines until I find an error */ \end_layout -\begin_layout Scrap +\begin_layout Chunk s = (char *)strpbrk(buffer[last_buf_line], " :"); \end_layout -\begin_layout Scrap +\begin_layout Chunk if (s == NULL || *s == ' ') \end_layout -\begin_layout Scrap +\begin_layout Chunk continue; /* No gcc error found here */ \end_layout -\begin_layout Scrap +\begin_layout Chunk do { \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk /****** OK It is an error message, get line number */ \end_layout -\begin_layout Scrap +\begin_layout Chunk err_line = atoi(s+1); \end_layout -\begin_layout Scrap +\begin_layout Chunk if (last_err_line == 0 || last_err_line == err_line) { \end_layout -\begin_layout Scrap +\begin_layout Chunk last_err_line = err_line; \end_layout -\begin_layout Scrap +\begin_layout Chunk continue; /* It's either a header or a continuation, don't output yet */ \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk /****** Completed the scan of one error message, output it to LyX */ \end_layout -\begin_layout Scrap +\begin_layout Chunk discharge_buffer(1); \end_layout -\begin_layout Scrap +\begin_layout Chunk break; \end_layout -\begin_layout Scrap +\begin_layout Chunk } while (fgets(buffer[last_buf_line], 200, stdin)); \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk /****** EOF completes the scan of whatever was being scanned */ \end_layout -\begin_layout Scrap +\begin_layout Chunk discharge_buffer(0); \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk /****** Search first ":" in the error number */ \end_layout -\begin_layout Scrap +\begin_layout Chunk s = (char *)strpbrk(buffer[last_buf_line], " :"); \end_layout -\begin_layout Scrap +\begin_layout Chunk last_buf_line++; \end_layout -\begin_layout Scrap +\begin_layout Chunk if (s == NULL || *s == ' ') \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk /****** Search second ":" in the error number */ \end_layout -\begin_layout Scrap +\begin_layout Chunk t = (char *)strpbrk(s+1, " :"); \begin_inset Newline newline \end_inset @@ -1125,40 +1128,40 @@ if (t != s+1+strspn(s+1, "0123456789")) @ \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk { \end_layout -\begin_layout Scrap +\begin_layout Chunk err_line = 0; \end_layout -\begin_layout Scrap +\begin_layout Chunk discharge_buffer(1); \end_layout -\begin_layout Scrap +\begin_layout Chunk continue; \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -1178,107 +1181,107 @@ last line In those cases we empty the buffer completely. \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk void \end_layout -\begin_layout Scrap +\begin_layout Chunk discharge_buffer (int save_last) \end_layout -\begin_layout Scrap +\begin_layout Chunk { \end_layout -\begin_layout Scrap +\begin_layout Chunk if (last_err_line != 0) { \end_layout -\begin_layout Scrap +\begin_layout Chunk clean_gcc_messages(); \end_layout -\begin_layout Scrap +\begin_layout Chunk if (save_last != 0) { \end_layout -\begin_layout Scrap +\begin_layout Chunk output_error(last_buf_line-1, last_err_line, "gcc"); \end_layout -\begin_layout Scrap +\begin_layout Chunk strcpy (buffer[0], buffer[last_buf_line-1]); \end_layout -\begin_layout Scrap +\begin_layout Chunk last_err_line = err_line; \end_layout -\begin_layout Scrap +\begin_layout Chunk last_buf_line = 1; \end_layout -\begin_layout Scrap +\begin_layout Chunk } else { \end_layout -\begin_layout Scrap +\begin_layout Chunk ++last_buf_line; \end_layout -\begin_layout Scrap +\begin_layout Chunk clean_gcc_messages(); \end_layout -\begin_layout Scrap +\begin_layout Chunk output_error(last_buf_line-1, last_err_line, "gcc"); \end_layout -\begin_layout Scrap +\begin_layout Chunk last_err_line = 0; \end_layout -\begin_layout Scrap +\begin_layout Chunk last_buf_line = 0; \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk void discharge_buffer (int save_last); \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -1307,119 +1310,119 @@ More could be done. \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk void \end_layout -\begin_layout Scrap +\begin_layout Chunk clean_gcc_messages () \end_layout -\begin_layout Scrap +\begin_layout Chunk { \end_layout -\begin_layout Scrap +\begin_layout Chunk int index; \end_layout -\begin_layout Scrap +\begin_layout Chunk char search [30]; \end_layout -\begin_layout Scrap +\begin_layout Chunk char *tail, *head; \end_layout -\begin_layout Scrap +\begin_layout Chunk int search_len = sprintf(search, ".nw:%d:", last_err_line); \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk for (index = 0; index < last_buf_line-1; index++) { \end_layout -\begin_layout Scrap +\begin_layout Chunk tail = (char *)strstr (buffer[index], search); \end_layout -\begin_layout Scrap +\begin_layout Chunk if ( tail == NULL) { \end_layout -\begin_layout Scrap +\begin_layout Chunk tail = (char *) strstr (buffer[index], ".nw:"); \end_layout -\begin_layout Scrap +\begin_layout Chunk if (tail) { \end_layout -\begin_layout Scrap +\begin_layout Chunk tail += 4; \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk } else { \end_layout -\begin_layout Scrap +\begin_layout Chunk tail += search_len; \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk if (tail != NULL) { \end_layout -\begin_layout Scrap +\begin_layout Chunk head = buffer[index]; \end_layout -\begin_layout Scrap +\begin_layout Chunk while (*(head++) = *(tail++)); \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk void clean_gcc_messages (); \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -1429,15 +1432,15 @@ To combine the scan of noweb error messages and xlc error messages is very We just try each one for every input line: \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk { \end_layout -\begin_layout Scrap +\begin_layout Chunk last_buf_line = 0; \begin_inset Newline newline \end_inset @@ -1481,129 +1484,129 @@ To combine the scan of noweb error messages and gcc error messages is simple the beginning of the scan: \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk { \end_layout -\begin_layout Scrap +\begin_layout Chunk char *s, *t; \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk last_buf_line = 0; \end_layout -\begin_layout Scrap +\begin_layout Chunk while (fgets(buffer[last_buf_line], 200, stdin)) { \end_layout -\begin_layout Scrap +\begin_layout Chunk /****** Skip lines until I find an error */ \end_layout -\begin_layout Scrap +\begin_layout Chunk if (last_buf_line == 0 && noweb_try(0)) { \end_layout -\begin_layout Scrap +\begin_layout Chunk output_error(1, err_line, "noweb"); \end_layout -\begin_layout Scrap +\begin_layout Chunk continue; \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk s = (char *)strpbrk(buffer[last_buf_line], " :"); \end_layout -\begin_layout Scrap +\begin_layout Chunk if (s == NULL || *s == ' ') \end_layout -\begin_layout Scrap +\begin_layout Chunk continue; /* No gcc error found here */ \end_layout -\begin_layout Scrap +\begin_layout Chunk do { \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk /****** OK It is an error, get line number */ \end_layout -\begin_layout Scrap +\begin_layout Chunk err_line = atoi(s+1); \end_layout -\begin_layout Scrap +\begin_layout Chunk if (last_err_line == 0 || last_err_line == err_line) { \end_layout -\begin_layout Scrap +\begin_layout Chunk last_err_line = err_line; \end_layout -\begin_layout Scrap +\begin_layout Chunk continue; /* It's either a header or a continuation, don't output yet */ \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk /****** Completed the scan of one error message, output it to LyX */ \end_layout -\begin_layout Scrap +\begin_layout Chunk discharge_buffer(1); \end_layout -\begin_layout Scrap +\begin_layout Chunk break; \end_layout -\begin_layout Scrap +\begin_layout Chunk } while (fgets(buffer[last_buf_line], 200, stdin)); \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk /****** EOF completes the scan of whatever was being scanned */ \end_layout -\begin_layout Scrap +\begin_layout Chunk discharge_buffer(0); \end_layout -\begin_layout Scrap +\begin_layout Chunk } \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -1611,35 +1614,35 @@ To combine the scan of noweb error messages and gcc error messages is simple Wrapping the code into a file \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk #include \end_layout -\begin_layout Scrap +\begin_layout Chunk #include \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -1672,31 +1675,31 @@ listerrors.c option to gcc. \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk #!/bin/sh \end_layout -\begin_layout Scrap +\begin_layout Chunk if [ -z "$NOWEB_SOURCE" ]; then NOWEB_SOURCE=Literate.nw; fi \end_layout -\begin_layout Scrap +\begin_layout Chunk if [ -z "$NOWEB_OUTPUT_DIR" ]; then NOWEB_OUTPUT_DIR=.; fi \end_layout -\begin_layout Scrap +\begin_layout Chunk notangle -L -Rlisterrors.c ${NOWEB_SOURCE} > ${NOWEB_OUTPUT_DIR}/listerrors.c \end_layout -\begin_layout Scrap +\begin_layout Chunk gcc -g -o listerrors listerrors.c \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -1707,7 +1710,7 @@ This project can be tangled and compiled from LyX if you set \backslash build_command \family default - to call a generic script that always extracts a scrap named + to call a generic script that always extracts a chunk named \family typewriter build-script \family default diff --git a/lib/examples/listerrors.lyx b/lib/examples/listerrors.lyx index 4214c4fe45..11e0383db3 100644 --- a/lib/examples/listerrors.lyx +++ b/lib/examples/listerrors.lyx @@ -1,8 +1,8 @@ #LyX 2.1 created this file. For more info see http://www.lyx.org/ -\lyxformat 442 +\lyxformat 448 \begin_document \begin_header -\textclass literate-article +\textclass article \begin_preamble % % ps2pdf stuff @@ -18,6 +18,9 @@ \let\nwdocspar=\smallbreak \end_preamble \use_default_options false +\begin_modules +noweb +\end_modules \maintain_unincluded_children false \language english \language_package default @@ -311,114 +314,114 @@ listerrors available for all other platforms. \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk #!/usr/bin/python -tt \end_layout -\begin_layout Scrap +\begin_layout Chunk """reformat noweb and compiler errors for LyX. \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk Expects to read from stdin and output to stdout. \end_layout -\begin_layout Scrap +\begin_layout Chunk """ \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk __author__ = "Kayvan A. Sylvan " \end_layout -\begin_layout Scrap +\begin_layout Chunk __date__ = "$Date: 2005/07/18 09:42:26 $" \end_layout -\begin_layout Scrap +\begin_layout Chunk __version__ = "$Revision: 1.5 $" \end_layout -\begin_layout Scrap +\begin_layout Chunk __credits__ = """Edmar Wienskoski Jr. \end_layout -\begin_layout Scrap +\begin_layout Chunk original Literate support for LyX. \end_layout -\begin_layout Scrap +\begin_layout Chunk Bernard Michael Hurley \end_layout -\begin_layout Scrap +\begin_layout Chunk modifications to original listerrors.""" \end_layout -\begin_layout Scrap +\begin_layout Chunk __copyright__ = "Copyright 2002 - Kayvan Sylvan." \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk import sys, string \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk if __name__ == "__main__": \end_layout -\begin_layout Scrap +\begin_layout Chunk main() \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -431,30 +434,30 @@ LaTeX style error message The following function mimics the TeX error message format. \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk def write_error(msg, tool = "noweb", line_number = 1): \end_layout -\begin_layout Scrap +\begin_layout Chunk """Write out the given message in TeX error style. \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk called like: write_error(msg, tool, line_number).""" \begin_inset Newline newline @@ -533,79 +536,79 @@ pushline set of functions: \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk __lines = [] # lines pushed back \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk def getline(file = sys.stdin): \end_layout -\begin_layout Scrap +\begin_layout Chunk """read a line from internal stack or from file. \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk optional file argument defaults to sys.stdin.""" \end_layout -\begin_layout Scrap +\begin_layout Chunk global __lines \end_layout -\begin_layout Scrap +\begin_layout Chunk lines = __lines \end_layout -\begin_layout Scrap +\begin_layout Chunk if lines: \end_layout -\begin_layout Scrap +\begin_layout Chunk line = lines.pop() \end_layout -\begin_layout Scrap +\begin_layout Chunk else: \end_layout -\begin_layout Scrap +\begin_layout Chunk line = file.readline() \end_layout -\begin_layout Scrap +\begin_layout Chunk return line \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk @ %def getline \end_layout @@ -614,26 +617,26 @@ def getline(file = sys.stdin): And now for the corresponding pushline function: \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk def pushline(line): \end_layout -\begin_layout Scrap +\begin_layout Chunk "push a line onto the pushback stack." \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk global __lines \begin_inset Newline newline @@ -671,57 +674,57 @@ listerrors \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk def main(): \end_layout -\begin_layout Scrap +\begin_layout Chunk """Entry point for listerrors. Takes no options. \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk Reads stdin and writes to stdout. Filter errors""" \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk while 1: \end_layout -\begin_layout Scrap +\begin_layout Chunk line = getline() \end_layout -\begin_layout Scrap +\begin_layout Chunk if line == "": break \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk @ %def main \end_layout @@ -731,16 +734,16 @@ For each line read in, we need to find out if it matches any of our tools (noweb, gcc, etc.) and act accordingly. \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk try_patterns_dispatch = [ noweb_try, gcc_try, xlc_try ] \begin_inset Newline newline @@ -776,61 +779,61 @@ Noweb errors are output on a single line, so examining just the current line is enough. \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk def noweb_try(line): \end_layout -\begin_layout Scrap +\begin_layout Chunk """see if line is a noweb error. \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk Returns 1 on success, 0 otherwise. Outputs on stdout.""" \end_layout -\begin_layout Scrap +\begin_layout Chunk retval = 0 \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk return retval \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk @ %def noweb_try \end_layout @@ -848,80 +851,80 @@ unescaped < < in documentation chunk This is the only message with an associated line number from noweb. \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk if string.find(line, ": unescaped << in documentation chunk") != -1: \end_layout -\begin_layout Scrap +\begin_layout Chunk line_parts = string.split(line, ':') \end_layout -\begin_layout Scrap +\begin_layout Chunk num_str = line_parts[1] \end_layout -\begin_layout Scrap +\begin_layout Chunk num_len = len(num_str) \end_layout -\begin_layout Scrap +\begin_layout Chunk i = 0 \end_layout -\begin_layout Scrap +\begin_layout Chunk while i < num_len and (num_str[i] in string.digits): i = i + 1 \end_layout -\begin_layout Scrap +\begin_layout Chunk if i == num_len: \end_layout -\begin_layout Scrap +\begin_layout Chunk write_error(":" + line_parts[2], "noweb", int(num_str)) \end_layout -\begin_layout Scrap +\begin_layout Chunk retval = 1 \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout \begin_layout Standard -Some noweb messages are simply about undefined scraps. +Some noweb messages are simply about undefined chunks. These can be seen by looking for matching double-angle-brackets. \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk if (not retval): \begin_inset Newline newline @@ -956,102 +959,102 @@ if (not retval): Finally, here is an additional list of explicit strings to check for. \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk if (not retval): \end_layout -\begin_layout Scrap +\begin_layout Chunk msgs_to_try = ("couldn't open file", \end_layout -\begin_layout Scrap +\begin_layout Chunk "couldn't open temporary file", \end_layout -\begin_layout Scrap +\begin_layout Chunk "error writing temporary file", \end_layout -\begin_layout Scrap +\begin_layout Chunk "ill-formed option", \end_layout -\begin_layout Scrap +\begin_layout Chunk "unknown option", \end_layout -\begin_layout Scrap +\begin_layout Chunk "Bad format sequence", \end_layout -\begin_layout Scrap +\begin_layout Chunk "Can't open output file", \end_layout -\begin_layout Scrap +\begin_layout Chunk "Can't open temporary file", \end_layout -\begin_layout Scrap +\begin_layout Chunk "Capacity exceeded:", \end_layout -\begin_layout Scrap +\begin_layout Chunk "Ignoring unknown option -", \end_layout -\begin_layout Scrap +\begin_layout Chunk "This can't happen:", \end_layout -\begin_layout Scrap +\begin_layout Chunk "non-numeric line number in") \end_layout -\begin_layout Scrap +\begin_layout Chunk for msg in msgs_to_try: \end_layout -\begin_layout Scrap +\begin_layout Chunk if string.find(line, msg) != -1: \end_layout -\begin_layout Scrap +\begin_layout Chunk write_error(line, "noweb") \end_layout -\begin_layout Scrap +\begin_layout Chunk retval = 1 \end_layout -\begin_layout Scrap +\begin_layout Chunk break \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -1068,21 +1071,21 @@ The gcc errors can be multi-line, with the following format: foo.c: In function `main': \end_layout -\begin_layout Scrap +\begin_layout Chunk foo.c:3: `bar' undeclared (first use in this function) \end_layout -\begin_layout Scrap +\begin_layout Chunk foo.c:3: (Each undeclared identifier is reported only once \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk foo.c:3: for each function it appears in.) \begin_inset Newline newline @@ -1096,52 +1099,52 @@ In order to parse this, the gcc error handler has to look ahead and return any and all lines that do not match the expected pattern. \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk def gcc_try(line): \end_layout -\begin_layout Scrap +\begin_layout Chunk """See if line is a gcc error. Read ahead to handle all the lines. \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk Returns 1 on success, 0 otherwise. Outputs on stdout.""" \end_layout -\begin_layout Scrap +\begin_layout Chunk retval = 0 \end_layout -\begin_layout Scrap +\begin_layout Chunk <> \end_layout -\begin_layout Scrap +\begin_layout Chunk return retval \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk @ %def gcc_try \end_layout @@ -1151,7 +1154,7 @@ The error message starts with a gcc header (as above) without an associated line number. \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \begin_inset Newline newline @@ -1221,67 +1224,67 @@ At the point in the code that we know that we are in the middle of an error message, we do the following: \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk num_str = next_line[first_space:num_end] \end_layout -\begin_layout Scrap +\begin_layout Chunk msgs = [line[first_space:]] \end_layout -\begin_layout Scrap +\begin_layout Chunk msgs.append(next_line[num_end + 1:]) \end_layout -\begin_layout Scrap +\begin_layout Chunk header_to_see = next_line[:num_end] \end_layout -\begin_layout Scrap +\begin_layout Chunk next_line = getline() \end_layout -\begin_layout Scrap +\begin_layout Chunk while next_line and next_line[:num_end] == header_to_see: \end_layout -\begin_layout Scrap +\begin_layout Chunk msgs.append(next_line[num_end + 1:]) \end_layout -\begin_layout Scrap +\begin_layout Chunk next_line = getline() \end_layout -\begin_layout Scrap +\begin_layout Chunk if next_line: pushline(next_line) \end_layout -\begin_layout Scrap +\begin_layout Chunk write_error(msgs, "gcc", int(num_str)) \end_layout -\begin_layout Scrap +\begin_layout Chunk retval = 1 \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout @@ -1316,106 +1319,106 @@ re \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk def xlc_try(line): \end_layout -\begin_layout Scrap +\begin_layout Chunk """see if line is an xlc error. \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk Returns 1 on success, 0 otherwise. Outputs on stdout.""" \end_layout -\begin_layout Scrap +\begin_layout Chunk retval = 0 \end_layout -\begin_layout Scrap +\begin_layout Chunk if line[0] == '"': # This is the first character of all xlc errors \end_layout -\begin_layout Scrap +\begin_layout Chunk next_quote = string.find(line, '"', 1) \end_layout -\begin_layout Scrap +\begin_layout Chunk first_space = string.find(line, ' ') \end_layout -\begin_layout Scrap +\begin_layout Chunk if (next_quote != -1) and (first_space > next_quote): # no space inisde quotes \end_layout -\begin_layout Scrap +\begin_layout Chunk if line[first_space - 1:first_space + 6] == ", line ": \end_layout -\begin_layout Scrap +\begin_layout Chunk num_start = num_end = first_space + 6 \end_layout -\begin_layout Scrap +\begin_layout Chunk while line[num_end] in string.digits: num_end = num_end + 1 \end_layout -\begin_layout Scrap +\begin_layout Chunk if num_end > num_start: \end_layout -\begin_layout Scrap +\begin_layout Chunk write_error(line, "xlc", int(line[num_start : num_end])) \end_layout -\begin_layout Scrap +\begin_layout Chunk retval = 1 \end_layout -\begin_layout Scrap +\begin_layout Chunk return retval \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk @ %def xlc_try \end_layout @@ -1433,7 +1436,7 @@ Program \begin_inset Quotes erd \end_inset - convertor to call a generic script that always extracts a scrap named + convertor to call a generic script that always extracts a chunk named \family typewriter build-script \family default @@ -1443,47 +1446,47 @@ build-script \begin_layout LyX-Code #!/bin/sh -\begin_inset Newline newline -\end_inset +\end_layout -notangle -Rbuild-script $1 | env NOWEB_SOURCE=$1 sh +\begin_layout LyX-Code +notangle -Rbuild-script $1 | env NOWEB_SOURCE=$1 NOWEB_OUTPUT_DIR=$2 sh \end_layout \begin_layout Standard This section defines our build-script, which extracts the code. \end_layout -\begin_layout Scrap +\begin_layout Chunk <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk #!/bin/sh \end_layout -\begin_layout Scrap +\begin_layout Chunk if [ -z "$NOWEB_SOURCE" ]; then NOWEB_SOURCE=listerrors.nw; fi \end_layout -\begin_layout Scrap +\begin_layout Chunk if [ -z "$NOWEB_OUTPUT_DIR" ]; then NOWEB_OUTPUT_DIR=.; fi \end_layout -\begin_layout Scrap +\begin_layout Chunk notangle -Rlisterrors ${NOWEB_SOURCE} > ${NOWEB_OUTPUT_DIR}/listerrors \end_layout -\begin_layout Scrap +\begin_layout Chunk chmod +x ${NOWEB_OUTPUT_DIR}/listerrors \end_layout -\begin_layout Scrap +\begin_layout Chunk @ \end_layout diff --git a/lib/examples/noweb2lyx.lyx b/lib/examples/noweb2lyx.lyx index 3bba1fc09e..9c4b723124 100644 --- a/lib/examples/noweb2lyx.lyx +++ b/lib/examples/noweb2lyx.lyx @@ -1,8 +1,8 @@ -#LyX 2.0 created this file. For more info see http://www.lyx.org/ -\lyxformat 413 +#LyX 2.1 created this file. For more info see http://www.lyx.org/ +\lyxformat 448 \begin_document \begin_header -\textclass literate-article +\textclass article \begin_preamble % % This relaxes the noweb constraint that chunks are @@ -14,6 +14,9 @@ \let\nwdocspar=\smallbreak \end_preamble \use_default_options false +\begin_modules +noweb +\end_modules \maintain_unincluded_children false \language english \language_package default @@ -22,13 +25,13 @@ \font_roman default \font_sans default \font_typewriter default +\font_math auto \font_default_family default \use_non_tex_fonts false \font_sc false \font_osf false \font_sf_scale 100 \font_tt_scale 100 - \graphics default \default_output_format default \output_sync 0 @@ -39,15 +42,21 @@ \use_hyperref false \papersize default \use_geometry false -\use_amsmath 0 -\use_esint 0 -\use_mhchem 1 -\use_mathdots 1 +\use_package amsmath 0 +\use_package amssymb 0 +\use_package esint 0 +\use_package mathdots 1 +\use_package mathtools 0 +\use_package mhchem 1 +\use_package undertilde 0 \cite_engine basic +\cite_engine_type numerical +\biblio_style plain \use_bibtopic false \use_indices false \paperorientation portrait \suppress_date false +\justification true \use_refstyle 0 \index Index \shortcut idx @@ -139,81 +148,100 @@ noweb file to LyX. \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + #!@PERL@ \end_layout -\begin_layout Scrap +\begin_layout Chunk + # \end_layout -\begin_layout Scrap +\begin_layout Chunk + # Copyright (C) 1999 Kayvan A. Sylvan \end_layout -\begin_layout Scrap +\begin_layout Chunk + # You are free to use and modify this code under the terms of \end_layout -\begin_layout Scrap +\begin_layout Chunk + # the GNU General Public Licence version 2 or later. \end_layout -\begin_layout Scrap +\begin_layout Chunk + # \end_layout -\begin_layout Scrap +\begin_layout Chunk + # Written with assistance from: \end_layout -\begin_layout Scrap +\begin_layout Chunk + # Edmar Wienskoski Jr. \end_layout -\begin_layout Scrap +\begin_layout Chunk + # Amir Karger \end_layout -\begin_layout Scrap +\begin_layout Chunk + # \end_layout -\begin_layout Scrap +\begin_layout Chunk + # $Id: noweb2lyx.lyx,v 1.5 2005/07/18 09:42:27 jamatos Exp $ \end_layout -\begin_layout Scrap +\begin_layout Chunk + # \end_layout -\begin_layout Scrap +\begin_layout Chunk + # NOTE: This file was automatically generated from noweb2lyx.lyx using noweb. \end_layout -\begin_layout Scrap +\begin_layout Chunk + # \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout @@ -234,11 +262,12 @@ noweb @ Here is some documentation. \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk + We can do arbitrary LaTeX code here. \begin_inset Newline newline \end_inset @@ -400,7 +429,7 @@ end{reLyXskip} \begin_layout Standard Once reLyX is done with the input file, the problem is reduced to changing - the code chunks from LyX's LaTeX layout to the Scrap layout. + the code chunks from LyX's LaTeX layout to the Chunk layout. \end_layout \begin_layout Standard @@ -480,51 +509,63 @@ With all that preamble out of the way, we now have the basic high-level outline for our code: \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + if (!$post_only) { \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + if ((!$pre_only) && (!$post_only)) { \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + if (!$pre_only) { \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout @@ -539,27 +580,32 @@ In this section, we present the code that performs the task of creating This algorithm is outlined in the code that follows: \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + inputline: while() \end_layout -\begin_layout Scrap +\begin_layout Chunk + { \end_layout -\begin_layout Scrap +\begin_layout Chunk + if (/^ \backslash s* @@ -570,24 +616,28 @@ s* \backslash > \backslash ->=/) { # Beginning of a noweb scrap +>=/) { # Beginning of a noweb chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + } elsif (/^@ \backslash s+(.*)/) { # Beginning of a documentation chunk \end_layout -\begin_layout Scrap +\begin_layout Chunk + print OUTPUT $1; # We do not need the ``@'' part \end_layout -\begin_layout Scrap +\begin_layout Chunk + } elsif (/ \backslash [ @@ -599,31 +649,38 @@ s+(.*)/) { # Beginning of a documentation chunk ]/) { # noweb quoted code \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + } else { \end_layout -\begin_layout Scrap +\begin_layout Chunk + print OUTPUT; # Just let the line pass through \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout @@ -633,11 +690,13 @@ In the code above, we do some pre-processing of the noweb ``[[...]]'' construct. constructs. \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + s/ \backslash [ @@ -693,23 +752,28 @@ noweb code chunk, we transform it into a form that is usable by reLyX. \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap -<> +\begin_layout Chunk + +<> \end_layout -\begin_layout Scrap -<> +\begin_layout Chunk + +<> \end_layout -\begin_layout Scrap -<> +\begin_layout Chunk + +<> \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout @@ -790,35 +854,43 @@ to read and write files. no need to create a temporary file. \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + if ($pre_only) { \end_layout -\begin_layout Scrap +\begin_layout Chunk + &setup_files($input_file, $output_file); \end_layout -\begin_layout Scrap +\begin_layout Chunk + } else { \end_layout -\begin_layout Scrap +\begin_layout Chunk + $relyx_file = "temp$$"; \end_layout -\begin_layout Scrap +\begin_layout Chunk + &setup_files($input_file, $relyx_file); \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout @@ -855,35 +927,42 @@ status collapsed , which we define below: \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + sub setup_files { \end_layout -\begin_layout Scrap +\begin_layout Chunk + my($in, $out) = @_; \end_layout -\begin_layout Scrap +\begin_layout Chunk + open(INPUT, "<$in") || die "Cannot read $in: $! \backslash n"; \end_layout -\begin_layout Scrap +\begin_layout Chunk + open(OUTPUT, ">$out") || die "Cannot write $out: $! \backslash n"; \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ %def setup_files \end_layout @@ -892,46 +971,51 @@ Reading in the \noun on noweb \noun default - scrap + chunk \end_layout \begin_layout Standard -After we see the beginning of the scrap, we need to read in and save the - rest of the scrap for output. +After we see the beginning of the chunk, we need to read in and save the + rest of the chunk for output. \end_layout -\begin_layout Scrap -<>= +\begin_layout Chunk + +<>= \end_layout -\begin_layout Scrap -$savedScrap = $_; +\begin_layout Chunk + +$savedchunk = $_; \end_layout -\begin_layout Scrap +\begin_layout Chunk + $endLine = ""; \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout -\begin_layout Scrap -<>= +\begin_layout Chunk + +<>= \begin_inset Newline newline \end_inset -scrapline: while () { +chunkline: while () { \begin_inset Newline newline \end_inset - last scrapline if /^@ + last chunkline if /^@ \backslash s+/; \begin_inset Newline newline \end_inset - $savedScrap .= $_; + $savedchunk .= $_; \begin_inset Newline newline \end_inset @@ -945,19 +1029,19 @@ switch: { if (/^@ \backslash -s+$/) {$savedScrap .= $_; last switch; } +s+$/) {$savedchunk .= $_; last switch; } \begin_inset Newline newline \end_inset if (/^@ \backslash -s+%def.*$/) {$savedScrap .= $_; last switch; } +s+%def.*$/) {$savedchunk .= $_; last switch; } \begin_inset Newline newline \end_inset if (/^@ \backslash -s+(.*)$/) {$savedScrap .= "@ +s+(.*)$/) {$savedchunk .= "@ \backslash n"; $endLine = "$1 \backslash @@ -973,18 +1057,20 @@ n"; } \end_layout \begin_layout Subsection -Printing out the scrap +Printing out the chunk \end_layout \begin_layout Standard The final piece of the first pass of the conversion is done by this code. \end_layout -\begin_layout Scrap -<>= +\begin_layout Chunk + +<>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + print OUTPUT " \backslash @@ -994,11 +1080,13 @@ begin{reLyXskip} n"; \end_layout -\begin_layout Scrap -print OUTPUT $savedScrap; +\begin_layout Chunk + +print OUTPUT $savedchunk; \end_layout -\begin_layout Scrap +\begin_layout Chunk + print OUTPUT " \backslash @@ -1010,11 +1098,13 @@ n n"; \end_layout -\begin_layout Scrap +\begin_layout Chunk + print OUTPUT "$endLine"; \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout @@ -1083,19 +1173,23 @@ status collapsed files. \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + close(INPUT); \end_layout -\begin_layout Scrap +\begin_layout Chunk + close(OUTPUT); \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout @@ -1148,19 +1242,23 @@ In order to run reLyX, we need to know the article class of the input document For this, we need to parse the intermediate file. \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout @@ -1255,29 +1353,35 @@ noweb2lyx on itself and a produce a quite reasonable LyX file. \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + open(INPUT, "<$relyx_file") || \end_layout -\begin_layout Scrap +\begin_layout Chunk + die "Cannot read $relyx_file: $! \backslash n"; \end_layout -\begin_layout Scrap +\begin_layout Chunk + $class = "article"; # default if none found \end_layout -\begin_layout Scrap +\begin_layout Chunk + parse: while() { \end_layout -\begin_layout Scrap +\begin_layout Chunk + if (/ \backslash @@ -1285,27 +1389,33 @@ parse: while() { docu[m]entclass{(.*)}/) { \end_layout -\begin_layout Scrap +\begin_layout Chunk + $class = $1; \end_layout -\begin_layout Scrap +\begin_layout Chunk + last parse; \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + close(INPUT); \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout @@ -1317,7 +1427,8 @@ Running reLyX with the corresponding literate document layout Now that we know what the document class ought to be, we do: \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \begin_inset Newline newline \end_inset @@ -1364,43 +1475,53 @@ We need to perform some post-processing of what reLyX produces in order The outline of the post-processing steps are: \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + line: while() \end_layout -\begin_layout Scrap +\begin_layout Chunk + { \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + print OUTPUT; # default \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout @@ -1540,48 +1661,57 @@ status collapsed is taken care of by this code: \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + if ($post_only) { \end_layout -\begin_layout Scrap +\begin_layout Chunk + &setup_files("$input_file", "$output_file"); \end_layout -\begin_layout Scrap +\begin_layout Chunk + } else { \end_layout -\begin_layout Scrap +\begin_layout Chunk + &setup_files("$relyx_file.lyx", "$output_file"); \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout \begin_layout Subsection -Making sure the code chunks are in the Scrap layout +Making sure the code chunks are in the Chunk layout \end_layout \begin_layout Standard Now, as we outlined before, the final step is transforming the code-chunks - which have been put into a LaTeX layout by LyX into the scrap layout. + which have been put into a LaTeX layout by LyX into the Chunk layout. \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + if (/ \backslash @@ -1589,65 +1719,76 @@ if (/ latex latex/) { # Beginning of some latex code \end_layout -\begin_layout Scrap +\begin_layout Chunk + if (($line = ) =~ /^ \backslash -s*<> +\begin_layout Chunk + + <> \end_layout -\begin_layout Scrap +\begin_layout Chunk + } else { \end_layout -\begin_layout Scrap +\begin_layout Chunk + # print the \backslash latex latex line + next line \end_layout -\begin_layout Scrap +\begin_layout Chunk + print OUTPUT "$_$line"; \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + next line; \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout \begin_layout Standard When we are sure that we are in a code chunk, we must read in the rest of - the code chunk and output a scrap layout for it: + the code chunk and output a chunk layout for it: \end_layout -\begin_layout Scrap -<>= +\begin_layout Chunk + +<>= \end_layout -\begin_layout Scrap +\begin_layout Chunk \end_layout -\begin_layout Scrap -$savedScrap = " +\begin_layout Chunk + +$savedchunk = " \backslash \backslash -layout Scrap +layout Chunk \backslash n \backslash @@ -1659,7 +1800,7 @@ codeline: while () { \begin_inset Newline newline \end_inset - $savedScrap .= $_; + $savedchunk .= $_; \begin_inset Newline newline \end_inset @@ -1673,7 +1814,7 @@ s+/; \begin_inset Newline newline \end_inset -print OUTPUT $savedScrap; +print OUTPUT $savedchunk; \begin_inset Newline newline \end_inset @@ -1689,15 +1830,18 @@ Okay, now we just need to eat the rest of the latex layout. There should only be a few different types of lines for us to match: \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + slurp: while () { \end_layout -\begin_layout Scrap +\begin_layout Chunk + last slurp if / \backslash @@ -1705,7 +1849,8 @@ slurp: while () { latex /; \end_layout -\begin_layout Scrap +\begin_layout Chunk + next slurp if / \backslash @@ -1713,21 +1858,25 @@ latex /; newline/; \end_layout -\begin_layout Scrap +\begin_layout Chunk + next slurp if /^ \backslash s*$/; \end_layout -\begin_layout Scrap +\begin_layout Chunk + warn "confused by line: $_"; \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout @@ -1764,11 +1913,13 @@ noweb when it generates the final LaTeX code. \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + if (/ \backslash [ @@ -1780,7 +1931,8 @@ if (/ ]/) { # special code for [[var]] \end_layout -\begin_layout Scrap +\begin_layout Chunk + s/ \backslash [ @@ -1806,19 +1958,23 @@ latex default n/g; \end_layout -\begin_layout Scrap +\begin_layout Chunk + print OUTPUT; \end_layout -\begin_layout Scrap +\begin_layout Chunk + next line; \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout @@ -1830,15 +1986,18 @@ Cleaning up intermediate files The cleanup code is very simple: \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + system("rm -f $relyx_file*") unless ($post_only || $pre_only); \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout @@ -1856,75 +2015,93 @@ noweb2lyx files in the import pipeline. \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + &usage() if ($#ARGV < 1); # zero or one argument \end_layout -\begin_layout Scrap +\begin_layout Chunk + if ($ARGV[0] eq "-pre") { \end_layout -\begin_layout Scrap +\begin_layout Chunk + &usage unless ($#ARGV == 2); \end_layout -\begin_layout Scrap +\begin_layout Chunk + $input_file = $ARGV[1]; $output_file = $ARGV[2]; $pre_only = 1; \end_layout -\begin_layout Scrap +\begin_layout Chunk + } elsif ($ARGV[0] eq "-post") { \end_layout -\begin_layout Scrap +\begin_layout Chunk + &usage unless ($#ARGV == 2); \end_layout -\begin_layout Scrap +\begin_layout Chunk + $input_file = $ARGV[1]; $output_file = $ARGV[2]; $post_only = 1; \end_layout -\begin_layout Scrap +\begin_layout Chunk + } else { \end_layout -\begin_layout Scrap +\begin_layout Chunk + &usage unless ($#ARGV == 1); \end_layout -\begin_layout Scrap +\begin_layout Chunk + $input_file = $ARGV[0]; $output_file = $ARGV[1]; \end_layout -\begin_layout Scrap +\begin_layout Chunk + $pre_only = 0; $post_only = 0; \end_layout -\begin_layout Scrap +\begin_layout Chunk + } \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ %def input_file output_file pre_only post_only \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + sub usage() { \end_layout -\begin_layout Scrap +\begin_layout Chunk + print "Usage: noweb2lyx [-pre | -post] input-file output-file \end_layout -\begin_layout Scrap +\begin_layout Chunk + \begin_inset Newline newline \end_inset @@ -1970,7 +2147,7 @@ The noweb2lyx script can be tangled from LyX if you set \backslash build_command \family default - to call a generic script that always extracts a scrap named + to call a generic script that always extracts a chunk named \family typewriter build-script \family default @@ -1983,30 +2160,36 @@ build-script \begin_inset Newline newline \end_inset -notangle -Rbuild-script $1 | sh +notangle -Rbuild-script $1 | env NOWEB_SOURCE=$1 NOWEB_OUTPUT_DIR=$2 sh \end_layout -\begin_layout Scrap +\begin_layout Chunk + <>= \end_layout -\begin_layout Scrap +\begin_layout Chunk + PREFIX=/usr \end_layout -\begin_layout Scrap +\begin_layout Chunk + notangle -Rnoweb2lyx.in noweb2lyx.nw > noweb2lyx.in \end_layout -\begin_layout Scrap +\begin_layout Chunk + sed -e "s=@PERL@=$PREFIX/bin/perl=" noweb2lyx.in > noweb2lyx \end_layout -\begin_layout Scrap +\begin_layout Chunk + chmod +x noweb2lyx \end_layout -\begin_layout Scrap +\begin_layout Chunk + @ \end_layout diff --git a/lib/examples/sweave.lyx b/lib/examples/sweave.lyx index b668753e01..fa3f1bce7c 100644 --- a/lib/examples/sweave.lyx +++ b/lib/examples/sweave.lyx @@ -1,5 +1,5 @@ -#LyX 2.0 created this file. For more info see http://www.lyx.org/ -\lyxformat 413 +#LyX 2.1 created this file. For more info see http://www.lyx.org/ +\lyxformat 445 \begin_document \begin_header \textclass article @@ -27,13 +27,13 @@ sweave \font_roman palatino \font_sans lmss \font_typewriter lmtt +\font_math auto \font_default_family default \use_non_tex_fonts false \font_sc false \font_osf false \font_sf_scale 100 \font_tt_scale 100 - \graphics default \default_output_format default \output_sync 0 @@ -44,15 +44,21 @@ sweave \use_hyperref false \papersize default \use_geometry true -\use_amsmath 1 -\use_esint 1 -\use_mhchem 1 -\use_mathdots 1 +\use_package amsmath 1 +\use_package amssymb 1 +\use_package esint 1 +\use_package mathdots 1 +\use_package mathtools 0 +\use_package mhchem 1 +\use_package undertilde 0 \cite_engine basic +\cite_engine_type numerical +\biblio_style plain \use_bibtopic false \use_indices false \paperorientation portrait \suppress_date false +\justification true \use_refstyle 0 \index Index \shortcut idx @@ -197,19 +203,7 @@ Since LyX 2.0, Sweave can be used out of the box with any document class \family sans Sweave \family default - module, which means we no longer need to modify the -\family sans -preferences -\family default - file manually or add special layouts such as -\family sans -literate-article.layout -\family default - and -\family sans -literate-book.layout -\family default - like we did before. + module. We can add the \family sans Sweave diff --git a/lib/images/classic/layout_Scrap.png b/lib/images/classic/layout_Chunk.png similarity index 100% rename from lib/images/classic/layout_Scrap.png rename to lib/images/classic/layout_Chunk.png diff --git a/lib/images/layout_Scrap.png b/lib/images/layout_Chunk.png similarity index 100% rename from lib/images/layout_Scrap.png rename to lib/images/layout_Chunk.png diff --git a/lib/layouts/literate-article.layout b/lib/layouts/literate-article.layout deleted file mode 100644 index c0ba1eb3f3..0000000000 --- a/lib/layouts/literate-article.layout +++ /dev/null @@ -1,13 +0,0 @@ -#% Do not delete the line below; configure depends on this -# \DeclareLaTeXClass[article,noweb.sty]{Noweb Article} -# \DeclareCategory{Articles} -# literate-article textclass definition file. -# Author : Edmar Wienskoski Jr. - -Format 41 -Preamble - \usepackage{noweb} -EndPreamble - -Input article.layout -Input literate-scrap.inc diff --git a/lib/layouts/literate-book.layout b/lib/layouts/literate-book.layout deleted file mode 100644 index c5c6770569..0000000000 --- a/lib/layouts/literate-book.layout +++ /dev/null @@ -1,13 +0,0 @@ -#% Do not delete the line below; configure depends on this -# \DeclareLaTeXClass[book,noweb.sty]{Noweb Book} -# \DeclareCategory{Books} -# literate-book textclass definition file. -# Author : Edmar Wienskoski Jr. - -Format 41 -Preamble - \usepackage{noweb} -EndPreamble - -Input book.layout -Input literate-scrap.inc diff --git a/lib/layouts/literate-report.layout b/lib/layouts/literate-report.layout deleted file mode 100644 index ade1909048..0000000000 --- a/lib/layouts/literate-report.layout +++ /dev/null @@ -1,13 +0,0 @@ -#% Do not delete the line below; configure depends on this -# \DeclareLaTeXClass[report,noweb.sty]{Noweb Report} -# \DeclareCategory{Reports} -# literate-report textclass definition file. -# Author : Edmar Wienskoski Jr. - -Format 41 -Preamble - \usepackage{noweb} -EndPreamble - -Input report.layout -Input literate-scrap.inc diff --git a/lib/layouts/literate-scrap.inc b/lib/layouts/literate-scrap.inc deleted file mode 100644 index 43a68d6880..0000000000 --- a/lib/layouts/literate-scrap.inc +++ /dev/null @@ -1,31 +0,0 @@ -# Suggested style to write your code: -# Within same scrap, lines are separated by newlines (Ctrl-Return), use: -# ItemSep 0.4 -# . disavantage: must type ctrl-return every single line -# . advantage: looks better (IMHO) -# resembles more closely the produced paper doc (more WYSIWYG) -# - -Format 41 -OutputType literate - -Style Scrap - Margin First_Dynamic - LatexType Paragraph - LatexName dummy - LeftMargin MMM - Align Left - AlignPossible Block,Left - NewLine 0 - FreeSpacing 1 - PassThru 1 - ParbreakIsNewline 1 - LabelType Static - LabelFont - Color magenta - EndFont - TextFont - Color latex - Family Typewriter - EndFont -End diff --git a/lib/layouts/noweb.module b/lib/layouts/noweb.module index 6fb927fa5f..aae3eb088c 100644 --- a/lib/layouts/noweb.module +++ b/lib/layouts/noweb.module @@ -7,8 +7,11 @@ Format 41 OutputType literate -# FIXME: Use the Chunk layout from the sweave module? -Style Scrap +AddToPreamble + \usepackage{noweb} +EndPreamble + +Style Chunk Margin First_Dynamic LatexType Paragraph LatexName dummy diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py index 26e2131f85..ec4ed6c7c8 100644 --- a/lib/lyx2lyx/lyx_2_1.py +++ b/lib/lyx2lyx/lyx_2_1.py @@ -1397,6 +1397,37 @@ def convert_IJMP(document): if i == -1: return +def revert_literate(document): + " Revert Literate document to old format " + if del_token(document.header, "noweb", 0): + document.textclass = "literate-" + document.textclass + i = 0 + while True: + i = find_token(document.body, "\\begin_layout Chunk", i) + if i == -1: + break + document.body[i] = "\\begin_layout Scrap" + i = i + 1 + +def convert_literate(document): + " Convert Literate document to new format" + i = find_token(document.header, "\\textclass", 0) + if (i != -1) and "literate-" in document.header[i]: + document.textclass = document.header[i].replace("\\textclass literate-", "") + j = find_token(document.header, "\\begin_modules", 0) + if (j != -1): + document.header.insert(j + 1, "noweb") + else: + document.header.insert(i + 1, "\\end_modules") + document.header.insert(i + 1, "noweb") + document.header.insert(i + 1, "\\begin_modules") + i = 0 + while True: + i = find_token(document.body, "\\begin_layout Scrap", i) + if i == -1: + break + document.body[i] = "\\begin_layout Chunk" + i = i + 1 ## # Conversion hub @@ -1437,10 +1468,12 @@ convert = [ [444, []], [445, []], [446, [convert_latexargs]], - [447, [convert_IEEEtran, convert_AASTeX, convert_AGUTeX, convert_IJMP]] + [447, [convert_IEEEtran, convert_AASTeX, convert_AGUTeX, convert_IJMP]], + [448, [convert_literate]] ] revert = [ + [447, [revert_literate]], [446, [revert_IEEEtran, revert_AASTeX, revert_AGUTeX, revert_IJMP]], [445, [revert_latexargs]], [444, [revert_uop]], diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index a567426a68..38f3918fb0 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -1648,8 +1648,6 @@ void Preamble::parse(Parser & p, string const & forceclass, // Force textclass if the user wanted it if (!forceclass.empty()) h_textclass = forceclass; - if (noweb_mode && !prefixIs(h_textclass, "literate-")) - h_textclass.insert(0, "literate-"); tc.setName(h_textclass); if (!tc.load()) { cerr << "Error: Could not read layout file for textclass \"" << h_textclass << "\"." << endl; diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp index 0e6afd9f51..dc19f78a7b 100644 --- a/src/tex2lyx/tex2lyx.cpp +++ b/src/tex2lyx/tex2lyx.cpp @@ -581,7 +581,7 @@ int parse_help(string const &, string const &) "\t-e encoding Set the default encoding (latex name).\n" "\t-f Force overwrite of .lyx files.\n" "\t-help Print this message and quit.\n" - "\t-n translate a noweb (aka literate programming) file.\n" + "\t-n translate literate programming (noweb, sweave,... ) file.\n" "\t-skipchildren Do not translate included child documents.\n" "\t-roundtrip re-export created .lyx file infile.lyx.lyx to infile.lyx.tex.\n" "\t-s syntaxfile read additional syntax file.\n" diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index af811e297a..ef334e1b7f 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -1944,27 +1944,27 @@ void copy_file(FileName const & src, string dstname) } -/// Parse a NoWeb Scrap section. The initial "<<" is already parsed. +/// Parse a NoWeb Chunk section. The initial "<<" is already parsed. void parse_noweb(Parser & p, ostream & os, Context & context) { // assemble the rest of the keyword string name("<<"); - bool scrap = false; + bool chunk = false; while (p.good()) { Token const & t = p.get_token(); if (t.asInput() == ">" && p.next_token().asInput() == ">") { name += ">>"; p.get_token(); - scrap = (p.good() && p.next_token().asInput() == "="); - if (scrap) + chunk = (p.good() && p.next_token().asInput() == "="); + if (chunk) name += p.get_token().asInput(); break; } name += t.asInput(); } - if (!scrap || !context.new_layout_allowed || - !context.textclass.hasLayout(from_ascii("Scrap"))) { + if (!chunk || !context.new_layout_allowed || + !context.textclass.hasLayout(from_ascii("Chunk"))) { cerr << "Warning: Could not interpret '" << name << "'. Ignoring it." << endl; return; @@ -1978,7 +1978,7 @@ void parse_noweb(Parser & p, ostream & os, Context & context) // always must be in an own paragraph. context.new_paragraph(os); Context newcontext(true, context.textclass, - &context.textclass[from_ascii("Scrap")]); + &context.textclass[from_ascii("Chunk")]); newcontext.check_layout(os); os << name; while (p.good()) { @@ -1990,12 +1990,12 @@ void parse_noweb(Parser & p, ostream & os, Context & context) else { ostringstream oss; Context tmp(false, context.textclass, - &context.textclass[from_ascii("Scrap")]); + &context.textclass[from_ascii("Chunk")]); tmp.need_end_layout = true; tmp.check_layout(oss); os << subst(t.asInput(), "\n", oss.str()); } - // The scrap chunk is ended by an @ at the beginning of a line. + // The chunk is ended by an @ at the beginning of a line. // After the @ the line may contain a comment and/or // whitespace, but nothing else. if (t.asInput() == "@" && p.prev_token().cat() == catNewline && @@ -2282,6 +2282,12 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, skip_braces(p); } + else if (t.asInput() == "<" + && p.next_token().asInput() == "<" && noweb_mode) { + p.get_token(); + parse_noweb(p, os, context); + } + else if (t.asInput() == "<" && p.next_token().asInput() == "<") { context.check_layout(os); begin_inset(os, "Quotes "); @@ -2291,12 +2297,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, skip_braces(p); } - else if (t.asInput() == "<" - && p.next_token().asInput() == "<" && noweb_mode) { - p.get_token(); - parse_noweb(p, os, context); - } - else if (t.cat() == catSpace || (t.cat() == catNewline && ! p.isParagraph())) check_space(p, os, context); diff --git a/src/version.h b/src/version.h index 3febd57b16..41ed5b9801 100644 --- a/src/version.h +++ b/src/version.h @@ -30,8 +30,8 @@ extern char const * const lyx_version_info; // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -#define LYX_FORMAT_LYX 447 // uwestoehr: IEEEtran layout revision -#define LYX_FORMAT_TEX2LYX 447 +#define LYX_FORMAT_LYX 448 // kayvan: fix for noweb literate docs +#define LYX_FORMAT_TEX2LYX 448 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER