X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fexamples%2Fnoweb2lyx.lyx;h=5acd467f6492d14534bf9876adde545170426b5f;hb=3fd0cc27d47d79513487e56a254c90e1794b6b0e;hp=9c4b72312454fde53796a8b14f0671f41329fafd;hpb=4f6c0b520208b397f07c4aa9f0fe6cfcd02d7a2f;p=lyx.git diff --git a/lib/examples/noweb2lyx.lyx b/lib/examples/noweb2lyx.lyx index 9c4b723124..5acd467f64 100644 --- a/lib/examples/noweb2lyx.lyx +++ b/lib/examples/noweb2lyx.lyx @@ -1,7 +1,9 @@ -#LyX 2.1 created this file. For more info see http://www.lyx.org/ -\lyxformat 448 +#LyX 2.3 created this file. For more info see http://www.lyx.org/ +\lyxformat 544 \begin_document \begin_header +\save_transient_properties true +\origin /systemlyxdir/examples/ \textclass article \begin_preamble % @@ -22,16 +24,18 @@ noweb \language_package default \inputencoding default \fontencoding global -\font_roman default -\font_sans default -\font_typewriter default -\font_math auto +\font_roman "default" "default" +\font_sans "default" "default" +\font_typewriter "default" "default" +\font_math "auto" "auto" \font_default_family default \use_non_tex_fonts false \font_sc false \font_osf false -\font_sf_scale 100 -\font_tt_scale 100 +\font_sf_scale 100 100 +\font_tt_scale 100 100 +\use_microtype false +\use_dash_ligatures false \graphics default \default_output_format default \output_sync 0 @@ -42,15 +46,18 @@ noweb \use_hyperref false \papersize default \use_geometry false -\use_package amsmath 0 -\use_package amssymb 0 -\use_package esint 0 +\use_package amsmath 1 +\use_package amssymb 1 +\use_package cancel 1 +\use_package esint 1 \use_package mathdots 1 -\use_package mathtools 0 +\use_package mathtools 1 \use_package mhchem 1 -\use_package undertilde 0 +\use_package stackrel 1 +\use_package stmaryrd 1 +\use_package undertilde 1 \cite_engine basic -\cite_engine_type numerical +\cite_engine_type default \biblio_style plain \use_bibtopic false \use_indices false @@ -58,6 +65,7 @@ noweb \suppress_date false \justification true \use_refstyle 0 +\use_minted 0 \index Index \shortcut idx \color #008000 @@ -66,7 +74,10 @@ noweb \tocdepth 3 \paragraph_separation indent \paragraph_indentation default -\quotes_language english +\is_math_indent 0 +\math_numbering_side default +\quotes_style english +\dynamic_quotes 0 \papercolumns 1 \papersides 1 \paperpagestyle default @@ -96,7 +107,8 @@ May 6, 1999 \begin_layout Abstract This document describes and implements a perl script for importing noweb - files into LyX + files into \SpecialChar LyX + \end_layout \begin_layout Standard @@ -120,19 +132,22 @@ Introduction \end_layout \begin_layout Standard -Since version 1.0.1, LyX now supports Literate Programming using +Since version 1.0.1, \SpecialChar LyX + now supports Literate Programming using \noun on noweb \noun default . - This addition to LyX made it very pleasant to write programs in the literate + This addition to \SpecialChar LyX + made it very pleasant to write programs in the literate style (like this one). In addition to being able to write new literate programs, it would be quite useful if old \noun on noweb \noun default - code could be imported into LyX in some fashion. + code could be imported into \SpecialChar LyX + in some fashion. That's where this program comes in. \end_layout @@ -145,104 +160,114 @@ noweb2lyx \noun on noweb \noun default - file to LyX. + file to \SpecialChar LyX +. \end_layout -\begin_layout Chunk +\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 Chunk +\end_inset #!@PERL@ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # Copyright (C) 1999 Kayvan A. Sylvan \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # You are free to use and modify this code under the terms of \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # the GNU General Public Licence version 2 or later. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # Written with assistance from: \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # Edmar Wienskoski Jr. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # Amir Karger \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # $Id: noweb2lyx.lyx,v 1.5 2005/07/18 09:42:27 jamatos Exp $ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # NOTE: This file was automatically generated from noweb2lyx.lyx using noweb. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Section @@ -262,20 +287,26 @@ noweb @ Here is some documentation. \end_layout -\begin_layout Chunk - -\end_layout +\begin_layout Standard +\begin_inset ERT +status open -\begin_layout Chunk +\begin_layout Plain Layout We can do arbitrary LaTeX code here. -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout [... blah blah blah ...] \end_layout +\end_inset + + +\end_layout + \begin_layout Standard Code chunks look like this: \end_layout @@ -364,13 +395,16 @@ noweb \end_layout \begin_layout Standard -When first tackling this problem, I spoke with members of the LyX team that - knew about the literate programming extensions and reLyX (the LaTeX importing - code). +When first tackling this problem, I spoke with members of the \SpecialChar LyX + team that + knew about the literate programming extensions and re\SpecialChar LyX + (the \SpecialChar LaTeX + importing code). \end_layout \begin_layout Standard -One of the first ideas was to extend the reLyX code to understand the +One of the first ideas was to extend the re\SpecialChar LyX + code to understand the \noun on noweb \noun default @@ -386,7 +420,8 @@ Not the least of these problems is the fact that << is a quote in French. \end_inset . - On the other hand, it turns out that reLyX contains a very useful literal + On the other hand, it turns out that re\SpecialChar LyX + contains a very useful literal quoting mechanism. If the input file contains the construct \end_layout @@ -394,42 +429,51 @@ Not the least of these problems is the fact that << is a quote in French. \begin_layout LyX-Code \backslash -begin{reLyXskip} +begin{re\SpecialChar LyX +skip} \begin_inset Newline newline \end_inset {... - LaTeX stuff ...} + \SpecialChar LaTeX + stuff ...} \begin_inset Newline newline \end_inset \backslash -end{reLyXskip} +end{re\SpecialChar LyX +skip} \end_layout \begin_layout Standard -then reLyX will copy the surrounded code to the output file verbatim. +then re\SpecialChar LyX + will copy the surrounded code to the output file verbatim. Given this, the first part of the translation is easy; we simply have to copy the code chunks into an intermediate file that surrounds them with \family typewriter \backslash -begin{reLyXskip} +begin{re\SpecialChar LyX +skip} \family default and \family typewriter \backslash -end{reLyXskip} +end{re\SpecialChar LyX +skip} \family default . \end_layout \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 Chunk layout. +Once re\SpecialChar LyX + is done with the input file, the problem is reduced to changing + the code chunks from \SpecialChar LyX +'s \SpecialChar LaTeX + layout to the Chunk layout. \end_layout \begin_layout Standard @@ -439,7 +483,8 @@ noweb2lyx \noun default . We want to be able to run it as a simple pre-processor and post-processor - from within reLyX. + from within re\SpecialChar LyX +. We can accomplish this by setting the flags \family roman \series medium @@ -509,102 +554,118 @@ With all that preamble out of the way, we now have the basic high-level outline for our code: \end_layout -\begin_layout Chunk +\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 \SpecialChar LyX -<>= \end_layout -\begin_layout Chunk +\end_inset if (!$post_only) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if ((!$pre_only) && (!$post_only)) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if (!$pre_only) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Section -Making a file that reLyX can process +Making a file that re\SpecialChar LyX + can process \end_layout \begin_layout Standard In this section, we present the code that performs the task of creating - the intermediate file that reLyX can process, using the algorithm that - we just outlined. + the intermediate file that re\SpecialChar LyX + can process, using the algorithm that we + just outlined. This algorithm is outlined in the code that follows: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout inputline: while() \end_layout -\begin_layout Chunk +\begin_layout Plain Layout { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if (/^ \backslash @@ -619,24 +680,24 @@ s* >=/) { # Beginning of a noweb chunk \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } elsif (/^@ \backslash s+(.*)/) { # Beginning of a documentation chunk \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT $1; # We do not need the ``@'' part \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } elsif (/ \backslash @@ -649,53 +710,58 @@ s+(.*)/) { # Beginning of a documentation chunk ]/) { # noweb quoted code \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } else { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT; # Just let the line pass through \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Standard In the code above, we do some pre-processing of the noweb ``[[...]]'' construct. - This avoids some problems with reLyX confusing lists composed of ``[[...]]'' + This avoids some problems with re\SpecialChar LyX + confusing lists composed of ``[[...]]'' constructs. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout s/ \backslash @@ -704,16 +770,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 @@ -749,32 +822,42 @@ file, once we have identified a \noun on noweb \noun default - code chunk, we transform it into a form that is usable by reLyX. + code chunk, we transform it into a form that is usable by re\SpecialChar LyX +. \end_layout -\begin_layout 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 Chunk +\end_inset <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Subsection @@ -849,49 +932,59 @@ status collapsed \color inherit to read and write files. In the code fragment above, we need to read from the input file and write - to a file that will be later transformed by reLyX. + to a file that will be later transformed by re\SpecialChar LyX +. If we are being called only to pre-process the input file, then there is no need to create a temporary file. \end_layout -\begin_layout Chunk +\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 Chunk +\end_inset if ($pre_only) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &setup_files($input_file, $output_file); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } else { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $relyx_file = "temp$$"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &setup_files($input_file, $relyx_file); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Standard @@ -927,43 +1020,52 @@ status collapsed , which we define below: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout sub setup_files { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout my($in, $out) = @_; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout open(INPUT, "<$in") || die "Cannot read $in: $! \backslash n"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout open(OUTPUT, ">$out") || die "Cannot write $out: $! \backslash n"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + +@ %def setup_files +\end_layout + +\end_inset + -@ %def setup_files \end_layout \begin_layout Subsection @@ -979,83 +1081,111 @@ 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 Chunk +\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 Chunk +\end_inset $savedchunk = $_; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $endLine = ""; \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout chunkline: while () { -\begin_inset Newline newline -\end_inset +\end_layout - last chunkline if /^@ +\begin_layout Plain Layout + + last chunkline if /^@ \backslash s+/; -\begin_inset Newline newline -\end_inset +\end_layout - $savedchunk .= $_; -\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+$/) {$savedchunk .= $_; last switch; } -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout - if (/^@ + if (/^@ \backslash s+%def.*$/) {$savedchunk .= $_; last switch; } -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout - if (/^@ + if (/^@ \backslash 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 chunk \end_layout @@ -1064,12 +1194,22 @@ Printing out the chunk The final piece of the first pass of the conversion is done by this code. \end_layout -\begin_layout Chunk +\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 re\SpecialChar LyX +skip block \end_layout -\begin_layout Chunk +\end_inset print OUTPUT " \backslash @@ -1080,12 +1220,12 @@ begin{reLyXskip} n"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT $savedchunk; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT " \backslash @@ -1098,14 +1238,14 @@ n n"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT "$endLine"; \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Standard @@ -1173,32 +1313,43 @@ status collapsed files. \end_layout -\begin_layout Chunk +\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 Chunk +\end_inset close(INPUT); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout close(OUTPUT); \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Section -Running reLyX +Running re\SpecialChar LyX + \end_layout \begin_layout Standard -In this section, we describe and implement the code that runs reLyX on the +In this section, we describe and implement the code that runs re\SpecialChar LyX + on the intermediate file \family roman \series medium @@ -1237,29 +1388,40 @@ Selecting the document class \end_layout \begin_layout Standard -In order to run reLyX, we need to know the article class of the input document +In order to run re\SpecialChar LyX +, we need to know the article class of the input document (to choose the corresponding literate document layout). For this, we need to parse the intermediate file. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open -<>= +\begin_layout Plain Layout + +Run re\SpecialChar LyX + on intermediate file \end_layout -\begin_layout Chunk +\end_inset <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Standard @@ -1273,12 +1435,14 @@ noweb2lyx \emph on noweb2lyx.nw \emph default - file that is generated by LyX + file that is generated by \SpecialChar LyX + \begin_inset Foot status collapsed \begin_layout Plain Layout -reLyX searches for +re\SpecialChar LyX + searches for \backslash \backslash @@ -1350,37 +1514,47 @@ class and gets confused, so we have to obfuscate it slightly. \noun on noweb2lyx \noun default - on itself and a produce a quite reasonable LyX file. + on itself and a produce a quite reasonable \SpecialChar LyX + file. \end_layout -\begin_layout Chunk +\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 Chunk +\end_inset open(INPUT, "<$relyx_file") || \end_layout -\begin_layout Chunk +\begin_layout Plain Layout die "Cannot read $relyx_file: $! \backslash n"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $class = "article"; # default if none found \end_layout -\begin_layout Chunk +\begin_layout Plain Layout parse: while() { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if (/ \backslash @@ -1389,75 +1563,91 @@ parse: while() { docu[m]entclass{(.*)}/) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $class = $1; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout last parse; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout close(INPUT); \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Subsection -Running reLyX with the corresponding literate document layout +Running re\SpecialChar LyX + with the corresponding literate document layout \end_layout \begin_layout Standard Now that we know what the document class ought to be, we do: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= -\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. +re\SpecialChar LyX + performs the main bulk of the translation work. Note that if the ``literate- \emph on class \emph default -'' document layout is not found, then reLyX will fail with an error. +'' document layout is not found, then re\SpecialChar LyX + will fail with an error. In that case, you may need to modify your \noun on noweb @@ -1466,63 +1656,75 @@ noweb \end_layout \begin_layout Section -Fixing the reLyX output +Fixing the re\SpecialChar LyX + output \end_layout \begin_layout Standard -We need to perform some post-processing of what reLyX produces in order - to have the best output for our literate document. +We need to perform some post-processing of what re\SpecialChar LyX + produces in order to + have the best output for our literate document. The outline of the post-processing steps are: \end_layout -\begin_layout Chunk +\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 \SpecialChar LyX + file \end_layout -\begin_layout Chunk +\end_inset <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout line: while() \end_layout -\begin_layout Chunk +\begin_layout Plain Layout { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT; # default \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Standard @@ -1589,7 +1791,8 @@ status collapsed \color inherit is sufficient to restart the loop. We can use this construct to do some relatively complex parsing of the - reLyX generated file. + re\SpecialChar LyX + generated file. \end_layout \begin_layout Subsection @@ -1661,39 +1864,48 @@ status collapsed is taken care of by this code: \end_layout -\begin_layout Chunk +\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 Chunk +\end_inset if ($post_only) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &setup_files("$input_file", "$output_file"); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } else { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &setup_files("$relyx_file.lyx", "$output_file"); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Subsection @@ -1702,15 +1914,26 @@ Making sure the code chunks are in the Chunk 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 Chunk layout. + which have been put into a \SpecialChar LaTeX + layout by \SpecialChar LyX + into the Chunk layout. \end_layout -\begin_layout Chunk +\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 Chunk +\end_inset if (/ \backslash @@ -1719,53 +1942,53 @@ if (/ latex latex/) { # Beginning of some latex code \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if (($line = ) =~ /^ \backslash s*<> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } else { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # print the \backslash latex latex line + next line \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT "$_$line"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout next line; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Standard @@ -1773,16 +1996,20 @@ When we are sure that we are in a code chunk, we must read in the rest of the code chunk and output a chunk layout for it: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $savedchunk = " \backslash @@ -1793,54 +2020,75 @@ layout Chunk n \backslash n$line"; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout codeline: while () { -\begin_inset Newline newline -\end_inset +\end_layout - $savedchunk .= $_; -\begin_inset Newline newline -\end_inset +\begin_layout Plain Layout + + $savedchunk .= $_; +\end_layout - last codeline if /^@ +\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 + +\begin_layout Plain Layout print OUTPUT $savedchunk; -\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 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 Chunk +\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 Chunk +\end_inset slurp: while () { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout last slurp if / \backslash @@ -1849,7 +2097,7 @@ slurp: while () { latex /; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout next slurp if / \backslash @@ -1858,26 +2106,26 @@ latex /; newline/; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout next slurp if /^ \backslash s*$/; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout warn "confused by line: $_"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Subsection @@ -1903,22 +2151,34 @@ noweb \noun on noweb \noun default - syntax means putting the ``[[quoted-code]]'' in a LaTeX layout in the LyX + syntax means putting the ``[[quoted-code]]'' in a \SpecialChar LaTeX + layout in the \SpecialChar LyX file. - Otherwise, LyX will backslash-quote the brackets, creating ugly output. + Otherwise, \SpecialChar LyX + will backslash-quote the brackets, creating ugly output. The quoted-code is transformed by \noun on noweb \noun default - when it generates the final LaTeX code. + when it generates the final \SpecialChar LaTeX + code. \end_layout -\begin_layout Chunk +\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 Chunk +\end_inset if (/ \backslash @@ -1931,7 +2191,7 @@ if (/ ]/) { # special code for [[var]] \end_layout -\begin_layout Chunk +\begin_layout Plain Layout s/ \backslash @@ -1958,24 +2218,24 @@ latex default n/g; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout next line; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Section @@ -1986,19 +2246,28 @@ Cleaning up intermediate files The cleanup code is very simple: \end_layout -\begin_layout Chunk +\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 Chunk +\end_inset system("rm -f $relyx_file*") unless ($post_only || $pre_only); \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Section @@ -2011,127 +2280,143 @@ The noweb2lyx \noun default script understands two arguments, input-file and output-file. - It is also set up to be used internally by reLyX to pre-process or postprocess + It is also set up to be used internally by re\SpecialChar LyX + to pre-process or postprocess files in the import pipeline. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &usage() if ($#ARGV < 1); # zero or one argument \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if ($ARGV[0] eq "-pre") { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &usage unless ($#ARGV == 2); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $input_file = $ARGV[1]; $output_file = $ARGV[2]; $pre_only = 1; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } elsif ($ARGV[0] eq "-post") { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &usage unless ($#ARGV == 2); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $input_file = $ARGV[1]; $output_file = $ARGV[2]; $post_only = 1; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } else { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &usage unless ($#ARGV == 1); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $input_file = $ARGV[0]; $output_file = $ARGV[1]; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $pre_only = 0; $post_only = 0; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout @ %def input_file output_file pre_only post_only \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout sub usage() { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print "Usage: noweb2lyx [-pre | -post] input-file output-file \end_layout -\begin_layout Chunk +\begin_layout Plain Layout -\begin_inset Newline newline -\end_inset +\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 . \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 @@ -2141,7 +2426,8 @@ noweb2lyx \end_layout \begin_layout Standard -The noweb2lyx script can be tangled from LyX if you set +The noweb2lyx script can be tangled from \SpecialChar LyX + if you set \family typewriter \backslash @@ -2163,34 +2449,43 @@ build-script notangle -Rbuild-script $1 | env NOWEB_SOURCE=$1 NOWEB_OUTPUT_DIR=$2 sh \end_layout -\begin_layout Chunk +\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 Chunk +\end_inset PREFIX=/usr \end_layout -\begin_layout Chunk +\begin_layout Plain Layout notangle -Rnoweb2lyx.in noweb2lyx.nw > noweb2lyx.in \end_layout -\begin_layout Chunk +\begin_layout Plain Layout sed -e "s=@PERL@=$PREFIX/bin/perl=" noweb2lyx.in > noweb2lyx \end_layout -\begin_layout Chunk +\begin_layout Plain Layout chmod +x noweb2lyx \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Standard