]> git.lyx.org Git - lyx.git/blobdiff - lib/examples/noweb2lyx.lyx
achemso.layout: add a flex inset
[lyx.git] / lib / examples / noweb2lyx.lyx
index 3bba1fc09efc4fe3913f1ddeba7eee942eb669c7..c951a89b5b090e47dc32522b0de9cff92590988f 100644 (file)
@@ -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 474
 \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
 \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
 \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 cancel 0
+\use_package esint 0
+\use_package mathdots 1
+\use_package mathtools 0
+\use_package mhchem 1
+\use_package stackrel 0
+\use_package stmaryrd 0
+\use_package undertilde 0
 \cite_engine basic
+\cite_engine_type default
+\biblio_style plain
 \use_bibtopic false
 \use_indices false
 \paperorientation portrait
 \suppress_date false
+\justification true
 \use_refstyle 0
 \index Index
 \shortcut idx
@@ -139,82 +151,109 @@ noweb
  file to LyX.
 \end_layout
 
-\begin_layout Scrap
-<<noweb2lyx.in>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+noweb2lyx.in
 \end_layout
 
-\begin_layout Scrap
+\end_inset
+
 #!@PERL@
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 # 
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 # Copyright (C) 1999 Kayvan A.
  Sylvan <kayvan@sylvan.com>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 # You are free to use and modify this code under the terms of
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 # the GNU General Public Licence version 2 or later.
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 #
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 # Written with assistance from:
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 #   Edmar Wienskoski Jr.
  <edmar-w-jr@technologist.com>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 #   Amir Karger <karger@post.harvard.edu>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 #
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 # $Id: noweb2lyx.lyx,v 1.5 2005/07/18 09:42:27 jamatos Exp $
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 #
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 # NOTE: This file was automatically generated from noweb2lyx.lyx using noweb.
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 #
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 <<Setup variables from user supplied args>>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 <<Subroutines>>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 <<Convert noweb to LyX>>
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
 \begin_layout Section
@@ -234,19 +273,26 @@ noweb
 @ Here is some documentation.
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Standard
+\begin_inset ERT
+status open
+
+\begin_layout Plain Layout
 
+We can do arbitrary LaTeX code here.
 \end_layout
 
-\begin_layout Scrap
-We can do arbitrary LaTeX code here.
-\begin_inset Newline newline
-\end_inset
+\begin_layout Plain Layout
 
 [...
  blah blah blah ...]
 \end_layout
 
+\end_inset
+
+
+\end_layout
+
 \begin_layout Standard
 Code chunks look like this:
 \end_layout
@@ -400,7 +446,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,52 +526,72 @@ With all that preamble out of the way, we now have the basic high-level
  outline for our code:
 \end_layout
 
-\begin_layout Scrap
-<<Convert noweb to LyX>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+Convert noweb to LyX
 \end_layout
 
-\begin_layout Scrap
+\end_inset
+
 if (!$post_only) {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   <<Transform noweb for reLyX>>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 }
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 if ((!$pre_only) && (!$post_only)) {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   <<Run reLyX on intermediate file>>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 }
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 if (!$pre_only) {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   <<Fix up LyX file>>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 }
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 <<Clean up>>
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
 \begin_layout Section
@@ -539,27 +605,36 @@ 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 Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
 
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 <<Transform noweb for reLyX>>=
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 <<Setup INPUT and OUTPUT>>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 inputline: while(<INPUT>)
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   if (/^
 \backslash
 s*
@@ -570,24 +645,28 @@ s*
 \backslash
 >
 \backslash
->=/) { # Beginning of a noweb scrap
+>=/) { # Beginning of a noweb chunk
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
     <<Read in and output the noweb code chunk>>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   } elsif (/^@
 \backslash
 s+(.*)/) { # Beginning of a documentation chunk
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
     print OUTPUT $1; # We do not need the ``@'' part
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   } elsif (/
 \backslash
 [
@@ -599,32 +678,39 @@ s+(.*)/) { # Beginning of a documentation chunk
 ]/) { # noweb quoted code
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
     <<Perform special input quoting of [[var]]>>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   } else {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
     print OUTPUT; # Just let the line pass through
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   }
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 }
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 <<Close INPUT and OUTPUT>>
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
 \begin_layout Standard
@@ -633,11 +719,17 @@ In the code above, we do some pre-processing of the noweb ``[[...]]'' construct.
  constructs.
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Standard
+\begin_inset ERT
+status open
+
+\begin_layout Plain Layout
+
 <<Perform special input quoting of [[var]]>>=
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 s/
 \backslash
 [
@@ -645,16 +737,23 @@ s/
 [.+?
 \backslash
 ]{2,}/{$&}/g;
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 print OUTPUT;
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 @
 \end_layout
 
+\end_inset
+
+
+\end_layout
+
 \begin_layout Standard
 While reading in the 
 \family roman
@@ -693,24 +792,37 @@ noweb
  code chunk, we transform it into a form that is usable by reLyX.
 \end_layout
 
-\begin_layout Scrap
-<<Read in and output the noweb code chunk>>= 
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+Read in and output the noweb code chunk
 \end_layout
 
-\begin_layout Scrap
-<<Save the beginning of the scrap to savedScrap>>
+\end_inset
+
+<<Save the beginning of the chunk to savedchunk>>
 \end_layout
 
-\begin_layout Scrap
-<<Concatenate the rest of the scrap>>
+\begin_layout Plain Layout
+
+<<Concatenate the rest of the chunk>>
 \end_layout
 
-\begin_layout Scrap
-<<print out the scrap in a reLyXskip block>>
+\begin_layout Plain Layout
+
+<<print out the chunk in a reLyXskip block>>
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
 \begin_layout Subsection
@@ -790,36 +902,52 @@ to read and write files.
  no need to create a temporary file.
 \end_layout
 
-\begin_layout Scrap
-<<Setup INPUT and OUTPUT>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+Setup INPUT and OUTPUT
 \end_layout
 
-\begin_layout Scrap
+\end_inset
+
 if ($pre_only) {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   &setup_files($input_file, $output_file);
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 } else {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   $relyx_file = "temp$$";
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   &setup_files($input_file, $relyx_file);
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 }
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
 \begin_layout Standard
@@ -855,36 +983,52 @@ status collapsed
 , which we define below:
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Standard
+\begin_inset ERT
+status open
+
+\begin_layout Plain Layout
+
 <<Subroutines>>=
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 sub setup_files {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   my($in, $out) = @_;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   open(INPUT, "<$in") || die "Cannot read $in: $!
 \backslash
 n";
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   open(OUTPUT, ">$out") || die "Cannot write $out: $!
 \backslash
 n";
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 }
 \end_layout
 
-\begin_layout Scrap
-@ %def setup_files   
+\begin_layout Plain Layout
+
+@ %def setup_files
+\end_layout
+
+\end_inset
+
+
 \end_layout
 
 \begin_layout Subsection
@@ -892,99 +1036,141 @@ 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
-<<Save the beginning of the scrap to savedScrap>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+Save the beginning of the chunk to savedchunk
 \end_layout
 
-\begin_layout Scrap
-$savedScrap = $_;
+\end_inset
+
+$savedchunk = $_;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 $endLine = "";
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
-\begin_layout Scrap
-<<Concatenate the rest of the scrap>>=
-\begin_inset Newline newline
-\end_inset
+\begin_layout Standard
+\begin_inset ERT
+status open
 
-scrapline: while (<INPUT>) {
-\begin_inset Newline newline
-\end_inset
+\begin_layout Plain Layout
+
+<<Concatenate the rest of the chunk>>=
+\end_layout
 
-  last scrapline if /^@
+\begin_layout Plain Layout
+
+chunkline: while (<INPUT>) {
+\end_layout
+
+\begin_layout Plain Layout
+
+ last chunkline if /^@
 \backslash
 s+/;
-\begin_inset Newline newline
-\end_inset
+\end_layout
 
-  $savedScrap .= $_;
-\begin_inset Newline newline
-\end_inset
+\begin_layout Plain Layout
+
+ $savedchunk .= $_;
+\end_layout
+
+\begin_layout Plain Layout
 
 };
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 switch: {
-\begin_inset Newline newline
-\end_inset
+\end_layout
 
-  if (/^@
+\begin_layout Plain Layout
+
+ if (/^@
 \backslash
-s+$/) {$savedScrap .= $_; last switch; }
-\begin_inset Newline newline
-\end_inset
+s+$/) {$savedchunk .= $_; last switch; }
+\end_layout
+
+\begin_layout Plain Layout
 
 if (/^@
+ if (/^@
 \backslash
-s+%def.*$/) {$savedScrap .= $_; last switch; }
-\begin_inset Newline newline
-\end_inset
+s+%def.*$/) {$savedchunk .= $_; last switch; }
+\end_layout
 
-  if (/^@
+\begin_layout Plain Layout
+
+ if (/^@
 \backslash
-s+(.*)$/) {$savedScrap .= "@
+s+(.*)$/) {$savedchunk .= "@
 \backslash
 n"; $endLine = "$1
 \backslash
 n"; }
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 }
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 @
 \end_layout
 
+\end_inset
+
+
+\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
-<<print out the scrap in a reLyXskip block>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+print out the chunk in a reLyXskip block
 \end_layout
 
-\begin_layout Scrap
+\end_inset
+
 print OUTPUT "
 \backslash
 
@@ -994,11 +1180,13 @@ begin{reLyXskip}
 n";
 \end_layout
 
-\begin_layout Scrap
-print OUTPUT $savedScrap;
+\begin_layout Plain Layout
+
+print OUTPUT $savedchunk;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 print OUTPUT "
 \backslash
 
 n";
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 print OUTPUT "$endLine";
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
 \begin_layout Standard
@@ -1083,20 +1273,32 @@ status collapsed
 files.
 \end_layout
 
-\begin_layout Scrap
-<<Close INPUT and OUTPUT>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+Close INPUT and OUTPUT
 \end_layout
 
-\begin_layout Scrap
+\end_inset
+
 close(INPUT);
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 close(OUTPUT);
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
 \begin_layout Section
@@ -1148,20 +1350,32 @@ 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
-<<Run reLyX on intermediate file>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+Run reLyX on intermediate file
 \end_layout
 
-\begin_layout Scrap
+\end_inset
+
 <<Parse for document class>>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 <<Run reLyX with document class>>
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
 \begin_layout Standard
@@ -1255,29 +1469,43 @@ noweb2lyx
  on itself and a produce a quite reasonable LyX file.
 \end_layout
 
-\begin_layout Scrap
-<<Parse for document class>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+Parse for document class
 \end_layout
 
-\begin_layout Scrap
+\end_inset
+
 open(INPUT, "<$relyx_file") ||
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   die "Cannot read $relyx_file: $!
 \backslash
 n";
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 $class = "article"; # default if none found
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 parse: while(<INPUT>) {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   if (/
 \backslash
 
@@ -1285,28 +1513,34 @@ parse: while(<INPUT>) {
 docu[m]entclass{(.*)}/) {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
     $class = $1;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
     last parse;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   }
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 }
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 close(INPUT);
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
 \begin_layout Subsection
@@ -1317,29 +1551,43 @@ 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 Standard
+\begin_inset ERT
+status open
+
+\begin_layout Plain Layout
+
 <<Run reLyX with document class>>= 
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 $doc_class = "literate-" .
  $class;
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 die "reLyX returned non-zero: $!
 \backslash
 n"
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
   if (system("reLyX -c $doc_class $relyx_file"));
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 @
 \end_layout
 
+\end_inset
+
+
+\end_layout
+
 \begin_layout Standard
 reLyX performs the main bulk of the translation work.
  Note that if the ``literate-
@@ -1364,44 +1612,62 @@ 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
-<<Fix up LyX file>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+Fix up LyX file
 \end_layout
 
-\begin_layout Scrap
+\end_inset
+
 <<Setup INPUT and OUTPUT for the final output>>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 line: while(<INPUT>)
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   <<Fix code chunks in latex layout>>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   <<Fix [[var]] noweb construct>>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   print OUTPUT; # default
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 } 
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 <<Close INPUT and OUTPUT>>
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
 \begin_layout Standard
@@ -1540,48 +1806,73 @@ status collapsed
 is taken care of by this code:
 \end_layout
 
-\begin_layout Scrap
-<<Setup INPUT and OUTPUT for the final output>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+Setup INPUT and OUTPUT for the final output
 \end_layout
 
-\begin_layout Scrap
+\end_inset
+
 if ($post_only) {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   &setup_files("$input_file", "$output_file");
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 } else {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   &setup_files("$relyx_file.lyx", "$output_file");
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 }
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \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
-<<Fix code chunks in latex layout>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+Fix code chunks in latex layout
 \end_layout
 
-\begin_layout Scrap
+\end_inset
+
 if (/
 \backslash
 
@@ -1589,115 +1880,153 @@ if (/
 latex latex/) { # Beginning of some latex code
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   if (($line = <INPUT>) =~ /^
 \backslash
-s*<</) { # code scrap
+s*<</) { # code chunk
 \end_layout
 
-\begin_layout Scrap
-    <<Transform this chunk into layout scrap>>
+\begin_layout Plain Layout
+
+    <<Transform this chunk into layout chunk>>
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   } else {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
     # print the 
 \backslash
 latex latex line + next line
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
     print OUTPUT "$_$line";
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   }
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   next line;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 }
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \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
-<<Transform this chunk into layout scrap>>=
+\begin_layout Standard
+\begin_inset ERT
+status open
+
+\begin_layout Plain Layout
+
+<<Transform this chunk into layout chunk>>=
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
 
 \end_layout
 
-\begin_layout Scrap
-$savedScrap = "
+\begin_layout Plain Layout
+
+$savedchunk = "
 \backslash
 
 \backslash
-layout Scrap
+layout Chunk
 \backslash
 n
 \backslash
 n$line";
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 codeline: while (<INPUT>) {
-\begin_inset Newline newline
-\end_inset
+\end_layout
 
-  $savedScrap .= $_;
-\begin_inset Newline newline
-\end_inset
+\begin_layout Plain Layout
 
-  last codeline if /^@
+ $savedchunk .= $_;
+\end_layout
+
+\begin_layout Plain Layout
+
+ last codeline if /^@
 \backslash
 s+/;
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 };
-\begin_inset Newline newline
-\end_inset
+\end_layout
 
-print OUTPUT $savedScrap;
-\begin_inset Newline newline
-\end_inset
+\begin_layout Plain Layout
+
+print OUTPUT $savedchunk;
+\end_layout
+
+\begin_layout Plain Layout
 
 <<Slurp up to the end of the latex layout>>
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 @
 \end_layout
 
+\end_inset
+
+
+\end_layout
+
 \begin_layout Standard
 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
-<<Slurp up to the end of the latex layout>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+Slurp up to the end of the latex layout
 \end_layout
 
-\begin_layout Scrap
+\end_inset
+
 slurp: while (<INPUT>) {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   last slurp if /
 \backslash
 
@@ -1705,7 +2034,8 @@ slurp: while (<INPUT>) {
 latex /;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   next slurp if /
 \backslash
 
@@ -1713,22 +2043,26 @@ latex /;
 newline/;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   next slurp if /^
 \backslash
 s*$/;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   warn "confused by line: $_";
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 }
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
 \begin_layout Subsection
@@ -1764,11 +2098,21 @@ noweb
  when it generates the final LaTeX code.
 \end_layout
 
-\begin_layout Scrap
-<<Fix [[var]] noweb construct>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+Fix [[var]] noweb construct
 \end_layout
 
-\begin_layout Scrap
+\end_inset
+
 if (/
 \backslash
 [
@@ -1780,7 +2124,8 @@ if (/
 ]/) { # special code for [[var]]
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   s/
 \backslash
 [
@@ -1806,20 +2151,24 @@ latex default
 n/g;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   print OUTPUT;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   next line;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 }
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
 \begin_layout Section
@@ -1830,16 +2179,27 @@ Cleaning up intermediate files
 The cleanup code is very simple:
 \end_layout
 
-\begin_layout Scrap
-<<Clean up>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+Clean up
 \end_layout
 
-\begin_layout Scrap
+\end_inset
+
 system("rm -f $relyx_file*") unless ($post_only || $pre_only);
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
 \begin_layout Section
@@ -1856,105 +2216,138 @@ noweb2lyx
  files in the import pipeline.
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Standard
+\begin_inset ERT
+status open
+
+\begin_layout Plain Layout
+
 <<Setup variables from user supplied args>>=
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 &usage() if ($#ARGV < 1); # zero or one argument 
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 if ($ARGV[0] eq "-pre") {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   &usage unless ($#ARGV == 2);
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   $input_file = $ARGV[1]; $output_file = $ARGV[2]; $pre_only = 1;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 } elsif ($ARGV[0] eq "-post") {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   &usage unless ($#ARGV == 2);
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   $input_file = $ARGV[1]; $output_file = $ARGV[2]; $post_only = 1;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 } else {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   &usage unless ($#ARGV == 1);
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   $input_file = $ARGV[0]; $output_file = $ARGV[1];
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   $pre_only = 0; $post_only = 0;
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 }
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 @ %def input_file output_file pre_only post_only
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 <<Subroutines>>=
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 sub usage() {
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
   print "Usage: noweb2lyx [-pre | -post] input-file output-file
 \end_layout
 
-\begin_layout Scrap
-\begin_inset Newline newline
-\end_inset
+\begin_layout Plain Layout
+
+\end_layout
+
+\begin_layout Plain Layout
 
 If -pre is specified, only pre-processes the input-file for reLyX.
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 Similarly, in the case of -post, post-processes reLyX output.
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 In case of bugs, Email Kayvan Sylvan <kayvan
 \backslash
 @sylvan.com>.
 \backslash
 n";
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
   exit;
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 }
-\begin_inset Newline newline
-\end_inset
+\end_layout
+
+\begin_layout Plain Layout
 
 @ %def usage
 \end_layout
 
+\end_inset
+
+
+\end_layout
+
 \begin_layout Section
 Generating the 
 \noun on
@@ -1970,7 +2363,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,31 +2376,45 @@ 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
-<<build-script>>=
+\begin_layout Standard
+\begin_inset Flex Chunk
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+build-script
 \end_layout
 
-\begin_layout Scrap
+\end_inset
+
 PREFIX=/usr
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 notangle -Rnoweb2lyx.in noweb2lyx.nw > noweb2lyx.in
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 sed -e "s=@PERL@=$PREFIX/bin/perl=" noweb2lyx.in > noweb2lyx
 \end_layout
 
-\begin_layout Scrap
+\begin_layout Plain Layout
+
 chmod +x noweb2lyx
 \end_layout
 
-\begin_layout Scrap
-@
+\end_inset
+
+
 \end_layout
 
 \begin_layout Standard