]> git.lyx.org Git - lyx.git/blob - lib/examples/noweb2lyx.lyx
PDF-comment.lyx: describe a further feature
[lyx.git] / lib / examples / noweb2lyx.lyx
1 #LyX 2.1 created this file. For more info see http://www.lyx.org/
2 \lyxformat 474
3 \begin_document
4 \begin_header
5 \textclass article
6 \begin_preamble
7 %
8 % This relaxes the noweb constraint that chunks are
9 % never broken across pages.
10 %
11 % This is from the noweb FAQ
12 %
13 \def\nwendcode{\endtrivlist \endgroup}
14 \let\nwdocspar=\smallbreak
15 \end_preamble
16 \use_default_options false
17 \begin_modules
18 noweb
19 \end_modules
20 \maintain_unincluded_children false
21 \language english
22 \language_package default
23 \inputencoding default
24 \fontencoding global
25 \font_roman default
26 \font_sans default
27 \font_typewriter default
28 \font_math auto
29 \font_default_family default
30 \use_non_tex_fonts false
31 \font_sc false
32 \font_osf false
33 \font_sf_scale 100
34 \font_tt_scale 100
35 \graphics default
36 \default_output_format default
37 \output_sync 0
38 \bibtex_command default
39 \index_command default
40 \paperfontsize default
41 \spacing single
42 \use_hyperref false
43 \papersize default
44 \use_geometry false
45 \use_package amsmath 0
46 \use_package amssymb 0
47 \use_package cancel 0
48 \use_package esint 0
49 \use_package mathdots 1
50 \use_package mathtools 0
51 \use_package mhchem 1
52 \use_package stackrel 0
53 \use_package stmaryrd 0
54 \use_package undertilde 0
55 \cite_engine basic
56 \cite_engine_type default
57 \biblio_style plain
58 \use_bibtopic false
59 \use_indices false
60 \paperorientation portrait
61 \suppress_date false
62 \justification true
63 \use_refstyle 0
64 \index Index
65 \shortcut idx
66 \color #008000
67 \end_index
68 \secnumdepth 3
69 \tocdepth 3
70 \paragraph_separation indent
71 \paragraph_indentation default
72 \quotes_language english
73 \papercolumns 1
74 \papersides 1
75 \paperpagestyle default
76 \tracking_changes false
77 \output_changes false
78 \html_math_output 0
79 \html_css_as_file 0
80 \html_be_strict false
81 \end_header
82
83 \begin_body
84
85 \begin_layout Title
86
87 \noun on
88 noweb2lyx
89 \end_layout
90
91 \begin_layout Author
92 Kayvan A.
93  Sylvan <kayvan@sylvan.com>
94 \end_layout
95
96 \begin_layout Date
97 May 6, 1999
98 \end_layout
99
100 \begin_layout Abstract
101 This document describes and implements a perl script for importing noweb
102  files into LyX
103 \end_layout
104
105 \begin_layout Standard
106 \begin_inset CommandInset toc
107 LatexCommand tableofcontents
108
109 \end_inset
110
111
112 \end_layout
113
114 \begin_layout Standard
115 \begin_inset Newpage newpage
116 \end_inset
117
118
119 \end_layout
120
121 \begin_layout Section
122 Introduction
123 \end_layout
124
125 \begin_layout Standard
126 Since version 1.0.1, LyX now supports Literate Programming using 
127 \noun on
128 noweb
129 \noun default
130 .
131  This addition to LyX made it very pleasant to write programs in the literate
132  style (like this one).
133  In addition to being able to write new literate programs, it would be quite
134  useful if old 
135 \noun on
136 noweb
137 \noun default
138  code could be imported into LyX in some fashion.
139  That's where this program comes in.
140 \end_layout
141
142 \begin_layout Standard
143 The purpose of 
144 \noun on
145 noweb2lyx
146 \noun default
147  is to convert a 
148 \noun on
149 noweb
150 \noun default
151  file to LyX.
152 \end_layout
153
154 \begin_layout Standard
155 \begin_inset Flex Chunk
156 status open
157
158 \begin_layout Plain Layout
159
160 \begin_inset Argument 1
161 status open
162
163 \begin_layout Plain Layout
164 noweb2lyx.in
165 \end_layout
166
167 \end_inset
168
169 #!@PERL@
170 \end_layout
171
172 \begin_layout Plain Layout
173
174
175 \end_layout
176
177 \begin_layout Plain Layout
178
179 # Copyright (C) 1999 Kayvan A.
180  Sylvan <kayvan@sylvan.com>
181 \end_layout
182
183 \begin_layout Plain Layout
184
185 # You are free to use and modify this code under the terms of
186 \end_layout
187
188 \begin_layout Plain Layout
189
190 # the GNU General Public Licence version 2 or later.
191 \end_layout
192
193 \begin_layout Plain Layout
194
195 #
196 \end_layout
197
198 \begin_layout Plain Layout
199
200 # Written with assistance from:
201 \end_layout
202
203 \begin_layout Plain Layout
204
205 #   Edmar Wienskoski Jr.
206  <edmar-w-jr@technologist.com>
207 \end_layout
208
209 \begin_layout Plain Layout
210
211 #   Amir Karger <karger@post.harvard.edu>
212 \end_layout
213
214 \begin_layout Plain Layout
215
216 #
217 \end_layout
218
219 \begin_layout Plain Layout
220
221 # $Id: noweb2lyx.lyx,v 1.5 2005/07/18 09:42:27 jamatos Exp $
222 \end_layout
223
224 \begin_layout Plain Layout
225
226 #
227 \end_layout
228
229 \begin_layout Plain Layout
230
231 # NOTE: This file was automatically generated from noweb2lyx.lyx using noweb.
232 \end_layout
233
234 \begin_layout Plain Layout
235
236 #
237 \end_layout
238
239 \begin_layout Plain Layout
240
241 <<Setup variables from user supplied args>>
242 \end_layout
243
244 \begin_layout Plain Layout
245
246 <<Subroutines>>
247 \end_layout
248
249 \begin_layout Plain Layout
250
251 <<Convert noweb to LyX>>
252 \end_layout
253
254 \end_inset
255
256
257 \end_layout
258
259 \begin_layout Section
260 The Noweb file defined
261 \end_layout
262
263 \begin_layout Standard
264
265 \noun on
266 noweb
267 \noun default
268  file is a collection of documentation and code chunks.
269  Documentation chunks simply start with an ``@'' and have no name:
270 \end_layout
271
272 \begin_layout LyX-Code
273 @ Here is some documentation.
274 \end_layout
275
276 \begin_layout Standard
277 \begin_inset ERT
278 status open
279
280 \begin_layout Plain Layout
281
282 We can do arbitrary LaTeX code here.
283 \end_layout
284
285 \begin_layout Plain Layout
286
287 [...
288  blah blah blah ...]
289 \end_layout
290
291 \end_inset
292
293
294 \end_layout
295
296 \begin_layout Standard
297 Code chunks look like this:
298 \end_layout
299
300 \begin_layout LyX-Code
301 <
302 \begin_inset ERT
303 status collapsed
304
305 \begin_layout Plain Layout
306
307 {}
308 \end_layout
309
310 \end_inset
311
312 <Name of chunk here>
313 \begin_inset ERT
314 status collapsed
315
316 \begin_layout Plain Layout
317
318 {}
319 \end_layout
320
321 \end_inset
322
323 >=
324 \begin_inset Newline newline
325 \end_inset
326
327 {...
328  code for the chunk goes here ...}
329 \begin_inset Newline newline
330 \end_inset
331
332
333 \end_layout
334
335 \begin_layout Standard
336 The ``@'' is a necessary delimiter to end the code chunk.
337  The other form that the ``@'' line takes is as follows:
338 \end_layout
339
340 \begin_layout LyX-Code
341 <
342 \begin_inset ERT
343 status collapsed
344
345 \begin_layout Plain Layout
346
347 {}
348 \end_layout
349
350 \end_inset
351
352 <Name of chunk here>
353 \begin_inset ERT
354 status collapsed
355
356 \begin_layout Plain Layout
357
358 {}
359 \end_layout
360
361 \end_inset
362
363 >=
364 \begin_inset Newline newline
365 \end_inset
366
367 {...
368  code for the chunk ...}
369 \begin_inset Newline newline
370 \end_inset
371
372 @ %def identifier1 identifier2
373 \end_layout
374
375 \begin_layout Standard
376 In the latter form, we are declaring to 
377 \noun on
378 noweb
379 \noun default
380  that this code chunk defines identifier1, identifier2, etc.
381 \end_layout
382
383 \begin_layout Standard
384 When first tackling this problem, I spoke with members of the LyX team that
385  knew about the literate programming extensions and reLyX (the LaTeX importing
386  code).
387 \end_layout
388
389 \begin_layout Standard
390 One of the first ideas was to extend the reLyX code to understand the 
391 \noun on
392 noweb
393 \noun default
394  code chunks.
395  This proved to be too hard and presents other problems
396 \begin_inset Foot
397 status collapsed
398
399 \begin_layout Plain Layout
400 Not the least of these problems is the fact that << is a quote in French.
401 \end_layout
402
403 \end_inset
404
405 .
406  On the other hand, it turns out that reLyX contains a very useful literal
407  quoting mechanism.
408  If the input file contains the construct
409 \end_layout
410
411 \begin_layout LyX-Code
412
413 \backslash
414 begin{reLyXskip}
415 \begin_inset Newline newline
416 \end_inset
417
418 {...
419  LaTeX stuff ...}
420 \begin_inset Newline newline
421 \end_inset
422
423
424 \backslash
425 end{reLyXskip}
426 \end_layout
427
428 \begin_layout Standard
429 then reLyX will copy the surrounded code to the output file verbatim.
430  Given this, the first part of the translation is easy; we simply have to
431  copy the code chunks into an intermediate file that surrounds them with
432  
433 \family typewriter
434
435 \backslash
436 begin{reLyXskip}
437 \family default
438  and 
439 \family typewriter
440
441 \backslash
442 end{reLyXskip}
443 \family default
444 .
445 \end_layout
446
447 \begin_layout Standard
448 Once reLyX is done with the input file, the problem is reduced to changing
449  the code chunks from LyX's LaTeX layout to the Chunk layout.
450 \end_layout
451
452 \begin_layout Standard
453 There is one final constraint on 
454 \noun on
455 noweb2lyx
456 \noun default
457 .
458  We want to be able to run it as a simple pre-processor and post-processor
459  from within reLyX.
460  We can accomplish this by setting the flags 
461 \family roman
462 \series medium
463 \shape up
464 \size normal
465 \emph off
466 \bar no
467 \noun off
468 \color none
469
470 \begin_inset ERT
471 status collapsed
472
473 \begin_layout Plain Layout
474
475 [[pre_only]]
476 \end_layout
477
478 \end_inset
479
480
481 \family default
482 \series default
483 \shape default
484 \size default
485 \emph default
486 \bar default
487 \noun default
488  
489 \color inherit
490 and
491 \color none
492  
493 \family roman
494 \series medium
495 \shape up
496 \size normal
497 \emph off
498 \bar no
499 \noun off
500
501 \begin_inset ERT
502 status collapsed
503
504 \begin_layout Plain Layout
505
506 [[post_only]]
507 \end_layout
508
509 \end_inset
510
511
512 \family default
513 \series default
514 \shape default
515 \size default
516 \emph default
517 \bar default
518 \noun default
519  
520 \color inherit
521 before we reach the main conversion code.
522 \end_layout
523
524 \begin_layout Standard
525 With all that preamble out of the way, we now have the basic high-level
526  outline for our code:
527 \end_layout
528
529 \begin_layout Standard
530 \begin_inset Flex Chunk
531 status open
532
533 \begin_layout Plain Layout
534
535 \begin_inset Argument 1
536 status open
537
538 \begin_layout Plain Layout
539 Convert noweb to LyX
540 \end_layout
541
542 \end_inset
543
544 if (!$post_only) {
545 \end_layout
546
547 \begin_layout Plain Layout
548
549   <<Transform noweb for reLyX>>
550 \end_layout
551
552 \begin_layout Plain Layout
553
554 }
555 \end_layout
556
557 \begin_layout Plain Layout
558
559 if ((!$pre_only) && (!$post_only)) {
560 \end_layout
561
562 \begin_layout Plain Layout
563
564   <<Run reLyX on intermediate file>>
565 \end_layout
566
567 \begin_layout Plain Layout
568
569 }
570 \end_layout
571
572 \begin_layout Plain Layout
573
574 if (!$pre_only) {
575 \end_layout
576
577 \begin_layout Plain Layout
578
579   <<Fix up LyX file>>
580 \end_layout
581
582 \begin_layout Plain Layout
583
584 }
585 \end_layout
586
587 \begin_layout Plain Layout
588
589 <<Clean up>>
590 \end_layout
591
592 \end_inset
593
594
595 \end_layout
596
597 \begin_layout Section
598 Making a file that reLyX can process
599 \end_layout
600
601 \begin_layout Standard
602 In this section, we present the code that performs the task of creating
603  the intermediate file that reLyX can process, using the algorithm that
604  we just outlined.
605  This algorithm is outlined in the code that follows:
606 \end_layout
607
608 \begin_layout Standard
609 \begin_inset Flex Chunk
610 status open
611
612 \begin_layout Plain Layout
613
614 \end_layout
615
616 \begin_layout Plain Layout
617
618 <<Transform noweb for reLyX>>=
619 \end_layout
620
621 \begin_layout Plain Layout
622
623 <<Setup INPUT and OUTPUT>>
624 \end_layout
625
626 \begin_layout Plain Layout
627
628 inputline: while(<INPUT>)
629 \end_layout
630
631 \begin_layout Plain Layout
632
633 {
634 \end_layout
635
636 \begin_layout Plain Layout
637
638   if (/^
639 \backslash
640 s*
641 \backslash
642 <
643 \backslash
644 <.*
645 \backslash
646 >
647 \backslash
648 >=/) { # Beginning of a noweb chunk
649 \end_layout
650
651 \begin_layout Plain Layout
652
653     <<Read in and output the noweb code chunk>>
654 \end_layout
655
656 \begin_layout Plain Layout
657
658   } elsif (/^@
659 \backslash
660 s+(.*)/) { # Beginning of a documentation chunk
661 \end_layout
662
663 \begin_layout Plain Layout
664
665     print OUTPUT $1; # We do not need the ``@'' part
666 \end_layout
667
668 \begin_layout Plain Layout
669
670   } elsif (/
671 \backslash
672 [
673 \backslash
674 [.+
675 \backslash
676 ]
677 \backslash
678 ]/) { # noweb quoted code
679 \end_layout
680
681 \begin_layout Plain Layout
682
683     <<Perform special input quoting of [[var]]>>
684 \end_layout
685
686 \begin_layout Plain Layout
687
688   } else {
689 \end_layout
690
691 \begin_layout Plain Layout
692
693     print OUTPUT; # Just let the line pass through
694 \end_layout
695
696 \begin_layout Plain Layout
697
698   }
699 \end_layout
700
701 \begin_layout Plain Layout
702
703 }
704 \end_layout
705
706 \begin_layout Plain Layout
707
708 <<Close INPUT and OUTPUT>>
709 \end_layout
710
711 \end_inset
712
713
714 \end_layout
715
716 \begin_layout Standard
717 In the code above, we do some pre-processing of the noweb ``[[...]]'' construct.
718  This avoids some problems with reLyX confusing lists composed of ``[[...]]''
719  constructs.
720 \end_layout
721
722 \begin_layout Standard
723 \begin_inset ERT
724 status open
725
726 \begin_layout Plain Layout
727
728 <<Perform special input quoting of [[var]]>>=
729 \end_layout
730
731 \begin_layout Plain Layout
732
733 s/
734 \backslash
735 [
736 \backslash
737 [.+?
738 \backslash
739 ]{2,}/{$&}/g;
740 \end_layout
741
742 \begin_layout Plain Layout
743
744 print OUTPUT;
745 \end_layout
746
747 \begin_layout Plain Layout
748
749 @
750 \end_layout
751
752 \end_inset
753
754
755 \end_layout
756
757 \begin_layout Standard
758 While reading in the 
759 \family roman
760 \series medium
761 \shape up
762 \size normal
763 \emph off
764 \bar no
765 \noun off
766 \color none
767
768 \begin_inset ERT
769 status collapsed
770
771 \begin_layout Plain Layout
772
773 [[INPUT]]
774 \end_layout
775
776 \end_inset
777
778
779 \family default
780 \series default
781 \shape default
782 \size default
783 \emph default
784 \bar default
785 \noun default
786  
787 \color inherit
788 file, once we have identified a 
789 \noun on
790 noweb
791 \noun default
792  code chunk, we transform it into a form that is usable by reLyX.
793 \end_layout
794
795 \begin_layout Standard
796 \begin_inset Flex Chunk
797 status open
798
799 \begin_layout Plain Layout
800
801 \begin_inset Argument 1
802 status open
803
804 \begin_layout Plain Layout
805 Read in and output the noweb code chunk
806 \end_layout
807
808 \end_inset
809
810 <<Save the beginning of the chunk to savedchunk>>
811 \end_layout
812
813 \begin_layout Plain Layout
814
815 <<Concatenate the rest of the chunk>>
816 \end_layout
817
818 \begin_layout Plain Layout
819
820 <<print out the chunk in a reLyXskip block>>
821 \end_layout
822
823 \end_inset
824
825
826 \end_layout
827
828 \begin_layout Subsection
829 File input and output for the pre-processing step
830 \end_layout
831
832 \begin_layout Standard
833 In 
834 \noun on
835 noweb2lyx
836 \noun default
837 , we will use 
838 \family roman
839 \series medium
840 \shape up
841 \size normal
842 \emph off
843 \bar no
844 \noun off
845 \color none
846
847 \begin_inset ERT
848 status collapsed
849
850 \begin_layout Plain Layout
851
852 [[INPUT]]
853 \end_layout
854
855 \end_inset
856
857
858 \family default
859 \series default
860 \shape default
861 \size default
862 \emph default
863 \bar default
864 \noun default
865  
866 \color inherit
867 and
868 \color none
869  
870 \family roman
871 \series medium
872 \shape up
873 \size normal
874 \emph off
875 \bar no
876 \noun off
877
878 \begin_inset ERT
879 status collapsed
880
881 \begin_layout Plain Layout
882
883 [[OUTPUT]]
884 \end_layout
885
886 \end_inset
887
888
889 \family default
890 \series default
891 \shape default
892 \size default
893 \emph default
894 \bar default
895 \noun default
896  
897 \color inherit
898 to read and write files.
899  In the code fragment above, we need to read from the input file and write
900  to a file that will be later transformed by reLyX.
901  If we are being called only to pre-process the input file, then there is
902  no need to create a temporary file.
903 \end_layout
904
905 \begin_layout Standard
906 \begin_inset Flex Chunk
907 status open
908
909 \begin_layout Plain Layout
910
911 \begin_inset Argument 1
912 status open
913
914 \begin_layout Plain Layout
915 Setup INPUT and OUTPUT
916 \end_layout
917
918 \end_inset
919
920 if ($pre_only) {
921 \end_layout
922
923 \begin_layout Plain Layout
924
925   &setup_files($input_file, $output_file);
926 \end_layout
927
928 \begin_layout Plain Layout
929
930 } else {
931 \end_layout
932
933 \begin_layout Plain Layout
934
935   $relyx_file = "temp$$";
936 \end_layout
937
938 \begin_layout Plain Layout
939
940   &setup_files($input_file, $relyx_file);
941 \end_layout
942
943 \begin_layout Plain Layout
944
945 }
946 \end_layout
947
948 \end_inset
949
950
951 \end_layout
952
953 \begin_layout Standard
954 This code uses a small perl subroutine, 
955 \family roman
956 \series medium
957 \shape up
958 \size normal
959 \emph off
960 \bar no
961 \noun off
962 \color none
963
964 \begin_inset ERT
965 status collapsed
966
967 \begin_layout Plain Layout
968
969 [[setup_files]]
970 \end_layout
971
972 \end_inset
973
974
975 \family default
976 \series default
977 \shape default
978 \size default
979 \emph default
980 \bar default
981 \noun default
982 \color inherit
983 , which we define below:
984 \end_layout
985
986 \begin_layout Standard
987 \begin_inset ERT
988 status open
989
990 \begin_layout Plain Layout
991
992 <<Subroutines>>=
993 \end_layout
994
995 \begin_layout Plain Layout
996
997 sub setup_files {
998 \end_layout
999
1000 \begin_layout Plain Layout
1001
1002   my($in, $out) = @_;
1003 \end_layout
1004
1005 \begin_layout Plain Layout
1006
1007   open(INPUT, "<$in") || die "Cannot read $in: $!
1008 \backslash
1009 n";
1010 \end_layout
1011
1012 \begin_layout Plain Layout
1013
1014   open(OUTPUT, ">$out") || die "Cannot write $out: $!
1015 \backslash
1016 n";
1017 \end_layout
1018
1019 \begin_layout Plain Layout
1020
1021 }
1022 \end_layout
1023
1024 \begin_layout Plain Layout
1025
1026 @ %def setup_files
1027 \end_layout
1028
1029 \end_inset
1030
1031
1032 \end_layout
1033
1034 \begin_layout Subsection
1035 Reading in the 
1036 \noun on
1037 noweb
1038 \noun default
1039  chunk
1040 \end_layout
1041
1042 \begin_layout Standard
1043 After we see the beginning of the chunk, we need to read in and save the
1044  rest of the chunk for output.
1045 \end_layout
1046
1047 \begin_layout Standard
1048 \begin_inset Flex Chunk
1049 status open
1050
1051 \begin_layout Plain Layout
1052
1053 \begin_inset Argument 1
1054 status open
1055
1056 \begin_layout Plain Layout
1057 Save the beginning of the chunk to savedchunk
1058 \end_layout
1059
1060 \end_inset
1061
1062 $savedchunk = $_;
1063 \end_layout
1064
1065 \begin_layout Plain Layout
1066
1067 $endLine = "";
1068 \end_layout
1069
1070 \end_inset
1071
1072
1073 \end_layout
1074
1075 \begin_layout Standard
1076 \begin_inset ERT
1077 status open
1078
1079 \begin_layout Plain Layout
1080
1081 <<Concatenate the rest of the chunk>>=
1082 \end_layout
1083
1084 \begin_layout Plain Layout
1085
1086 chunkline: while (<INPUT>) {
1087 \end_layout
1088
1089 \begin_layout Plain Layout
1090
1091  last chunkline if /^@
1092 \backslash
1093 s+/;
1094 \end_layout
1095
1096 \begin_layout Plain Layout
1097
1098  $savedchunk .= $_;
1099 \end_layout
1100
1101 \begin_layout Plain Layout
1102
1103 };
1104 \end_layout
1105
1106 \begin_layout Plain Layout
1107
1108 switch: {
1109 \end_layout
1110
1111 \begin_layout Plain Layout
1112
1113  if (/^@
1114 \backslash
1115 s+$/) {$savedchunk .= $_; last switch; }
1116 \end_layout
1117
1118 \begin_layout Plain Layout
1119
1120  if (/^@
1121 \backslash
1122 s+%def.*$/) {$savedchunk .= $_; last switch; }
1123 \end_layout
1124
1125 \begin_layout Plain Layout
1126
1127  if (/^@
1128 \backslash
1129 s+(.*)$/) {$savedchunk .= "@
1130 \backslash
1131 n"; $endLine = "$1
1132 \backslash
1133 n"; }
1134 \end_layout
1135
1136 \begin_layout Plain Layout
1137
1138 }
1139 \end_layout
1140
1141 \begin_layout Plain Layout
1142
1143 @
1144 \end_layout
1145
1146 \end_inset
1147
1148
1149 \end_layout
1150
1151 \begin_layout Subsection
1152 Printing out the chunk
1153 \end_layout
1154
1155 \begin_layout Standard
1156 The final piece of the first pass of the conversion is done by this code.
1157 \end_layout
1158
1159 \begin_layout Standard
1160 \begin_inset Flex Chunk
1161 status open
1162
1163 \begin_layout Plain Layout
1164
1165 \begin_inset Argument 1
1166 status open
1167
1168 \begin_layout Plain Layout
1169 print out the chunk in a reLyXskip block
1170 \end_layout
1171
1172 \end_inset
1173
1174 print OUTPUT "
1175 \backslash
1176
1177 \backslash
1178 begin{reLyXskip}
1179 \backslash
1180 n";
1181 \end_layout
1182
1183 \begin_layout Plain Layout
1184
1185 print OUTPUT $savedchunk;
1186 \end_layout
1187
1188 \begin_layout Plain Layout
1189
1190 print OUTPUT "
1191 \backslash
1192
1193 \backslash
1194 end{reLyXskip}
1195 \backslash
1196 n
1197 \backslash
1198 n";
1199 \end_layout
1200
1201 \begin_layout Plain Layout
1202
1203 print OUTPUT "$endLine";
1204 \end_layout
1205
1206 \end_inset
1207
1208
1209 \end_layout
1210
1211 \begin_layout Standard
1212 Finally, we need to close the 
1213 \family roman
1214 \series medium
1215 \shape up
1216 \size normal
1217 \emph off
1218 \bar no
1219 \noun off
1220 \color none
1221
1222 \begin_inset ERT
1223 status collapsed
1224
1225 \begin_layout Plain Layout
1226
1227 [[INPUT]]
1228 \end_layout
1229
1230 \end_inset
1231
1232
1233 \family default
1234 \series default
1235 \shape default
1236 \size default
1237 \emph default
1238 \bar default
1239 \noun default
1240  
1241 \color inherit
1242 and
1243 \color none
1244  
1245 \family roman
1246 \series medium
1247 \shape up
1248 \size normal
1249 \emph off
1250 \bar no
1251 \noun off
1252
1253 \begin_inset ERT
1254 status collapsed
1255
1256 \begin_layout Plain Layout
1257
1258 [[OUTPUT]]
1259 \end_layout
1260
1261 \end_inset
1262
1263
1264 \family default
1265 \series default
1266 \shape default
1267 \size default
1268 \emph default
1269 \bar default
1270 \noun default
1271  
1272 \color inherit
1273 files.
1274 \end_layout
1275
1276 \begin_layout Standard
1277 \begin_inset Flex Chunk
1278 status open
1279
1280 \begin_layout Plain Layout
1281
1282 \begin_inset Argument 1
1283 status open
1284
1285 \begin_layout Plain Layout
1286 Close INPUT and OUTPUT
1287 \end_layout
1288
1289 \end_inset
1290
1291 close(INPUT);
1292 \end_layout
1293
1294 \begin_layout Plain Layout
1295
1296 close(OUTPUT);
1297 \end_layout
1298
1299 \end_inset
1300
1301
1302 \end_layout
1303
1304 \begin_layout Section
1305 Running reLyX
1306 \end_layout
1307
1308 \begin_layout Standard
1309 In this section, we describe and implement the code that runs reLyX on the
1310  intermediate file 
1311 \family roman
1312 \series medium
1313 \shape up
1314 \size normal
1315 \emph off
1316 \bar no
1317 \noun off
1318 \color none
1319
1320 \begin_inset ERT
1321 status collapsed
1322
1323 \begin_layout Plain Layout
1324
1325 [[relyx_file]]
1326 \end_layout
1327
1328 \end_inset
1329
1330
1331 \family default
1332 \series default
1333 \shape default
1334 \size default
1335 \emph default
1336 \bar default
1337 \noun default
1338 \color inherit
1339 .
1340  
1341 \end_layout
1342
1343 \begin_layout Subsection
1344 Selecting the document class
1345 \end_layout
1346
1347 \begin_layout Standard
1348 In order to run reLyX, we need to know the article class of the input document
1349  (to choose the corresponding literate document layout).
1350  For this, we need to parse the intermediate file.
1351 \end_layout
1352
1353 \begin_layout Standard
1354 \begin_inset Flex Chunk
1355 status open
1356
1357 \begin_layout Plain Layout
1358
1359 \begin_inset Argument 1
1360 status open
1361
1362 \begin_layout Plain Layout
1363 Run reLyX on intermediate file
1364 \end_layout
1365
1366 \end_inset
1367
1368 <<Parse for document class>>
1369 \end_layout
1370
1371 \begin_layout Plain Layout
1372
1373 <<Run reLyX with document class>>
1374 \end_layout
1375
1376 \end_inset
1377
1378
1379 \end_layout
1380
1381 \begin_layout Standard
1382 In the code below, you'll see a strange regular expression to search for
1383  the document class.
1384  The reason for this kludge is that without it, we can't run 
1385 \noun on
1386 noweb2lyx
1387 \noun default
1388  on the 
1389 \emph on
1390 noweb2lyx.nw
1391 \emph default
1392  file that is generated by LyX
1393 \begin_inset Foot
1394 status collapsed
1395
1396 \begin_layout Plain Layout
1397 reLyX searches for 
1398 \backslash
1399
1400 \backslash
1401 doc
1402 \family roman
1403 \series medium
1404 \shape up
1405 \size normal
1406 \emph off
1407 \bar no
1408 \noun off
1409 \color none
1410
1411 \begin_inset ERT
1412 status collapsed
1413
1414 \begin_layout Plain Layout
1415
1416 {}
1417 \end_layout
1418
1419 \end_inset
1420
1421
1422 \family default
1423 \series default
1424 \shape default
1425 \size default
1426 \emph default
1427 \bar default
1428 \noun default
1429 \color inherit
1430 ument
1431 \family roman
1432 \series medium
1433 \shape up
1434 \size normal
1435 \emph off
1436 \bar no
1437 \noun off
1438 \color none
1439
1440 \begin_inset ERT
1441 status collapsed
1442
1443 \begin_layout Plain Layout
1444
1445 {}
1446 \end_layout
1447
1448 \end_inset
1449
1450
1451 \family default
1452 \series default
1453 \shape default
1454 \size default
1455 \emph default
1456 \bar default
1457 \noun default
1458 \color inherit
1459 class and gets confused, so we have to obfuscate it slightly.
1460 \end_layout
1461
1462 \end_inset
1463
1464 .
1465  With the regular expression as it is, we can actually run 
1466 \noun on
1467 noweb2lyx
1468 \noun default
1469  on itself and a produce a quite reasonable LyX file.
1470 \end_layout
1471
1472 \begin_layout Standard
1473 \begin_inset Flex Chunk
1474 status open
1475
1476 \begin_layout Plain Layout
1477
1478 \begin_inset Argument 1
1479 status open
1480
1481 \begin_layout Plain Layout
1482 Parse for document class
1483 \end_layout
1484
1485 \end_inset
1486
1487 open(INPUT, "<$relyx_file") ||
1488 \end_layout
1489
1490 \begin_layout Plain Layout
1491
1492   die "Cannot read $relyx_file: $!
1493 \backslash
1494 n";
1495 \end_layout
1496
1497 \begin_layout Plain Layout
1498
1499 $class = "article"; # default if none found
1500 \end_layout
1501
1502 \begin_layout Plain Layout
1503
1504 parse: while(<INPUT>) {
1505 \end_layout
1506
1507 \begin_layout Plain Layout
1508
1509   if (/
1510 \backslash
1511
1512 \backslash
1513 docu[m]entclass{(.*)}/) {
1514 \end_layout
1515
1516 \begin_layout Plain Layout
1517
1518     $class = $1;
1519 \end_layout
1520
1521 \begin_layout Plain Layout
1522
1523     last parse;
1524 \end_layout
1525
1526 \begin_layout Plain Layout
1527
1528   }
1529 \end_layout
1530
1531 \begin_layout Plain Layout
1532
1533 }
1534 \end_layout
1535
1536 \begin_layout Plain Layout
1537
1538 close(INPUT);
1539 \end_layout
1540
1541 \end_inset
1542
1543
1544 \end_layout
1545
1546 \begin_layout Subsection
1547 Running reLyX with the corresponding literate document layout
1548 \end_layout
1549
1550 \begin_layout Standard
1551 Now that we know what the document class ought to be, we do:
1552 \end_layout
1553
1554 \begin_layout Standard
1555 \begin_inset ERT
1556 status open
1557
1558 \begin_layout Plain Layout
1559
1560 <<Run reLyX with document class>>= 
1561 \end_layout
1562
1563 \begin_layout Plain Layout
1564
1565 $doc_class = "literate-" .
1566  $class;
1567 \end_layout
1568
1569 \begin_layout Plain Layout
1570
1571 die "reLyX returned non-zero: $!
1572 \backslash
1573 n"
1574 \end_layout
1575
1576 \begin_layout Plain Layout
1577
1578   if (system("reLyX -c $doc_class $relyx_file"));
1579 \end_layout
1580
1581 \begin_layout Plain Layout
1582
1583 @
1584 \end_layout
1585
1586 \end_inset
1587
1588
1589 \end_layout
1590
1591 \begin_layout Standard
1592 reLyX performs the main bulk of the translation work.
1593  Note that if the ``literate-
1594 \emph on
1595 class
1596 \emph default
1597 '' document layout is not found, then reLyX will fail with an error.
1598  In that case, you may need to modify your 
1599 \noun on
1600 noweb
1601 \noun default
1602  input file to a supported document type.
1603 \end_layout
1604
1605 \begin_layout Section
1606 Fixing the reLyX output
1607 \end_layout
1608
1609 \begin_layout Standard
1610 We need to perform some post-processing of what reLyX produces in order
1611  to have the best output for our literate document.
1612  The outline of the post-processing steps are:
1613 \end_layout
1614
1615 \begin_layout Standard
1616 \begin_inset Flex Chunk
1617 status open
1618
1619 \begin_layout Plain Layout
1620
1621 \begin_inset Argument 1
1622 status open
1623
1624 \begin_layout Plain Layout
1625 Fix up LyX file
1626 \end_layout
1627
1628 \end_inset
1629
1630 <<Setup INPUT and OUTPUT for the final output>>
1631 \end_layout
1632
1633 \begin_layout Plain Layout
1634
1635 line: while(<INPUT>)
1636 \end_layout
1637
1638 \begin_layout Plain Layout
1639
1640 {
1641 \end_layout
1642
1643 \begin_layout Plain Layout
1644
1645   <<Fix code chunks in latex layout>>
1646 \end_layout
1647
1648 \begin_layout Plain Layout
1649
1650   <<Fix [[var]] noweb construct>>
1651 \end_layout
1652
1653 \begin_layout Plain Layout
1654
1655   print OUTPUT; # default
1656 \end_layout
1657
1658 \begin_layout Plain Layout
1659
1660
1661 \end_layout
1662
1663 \begin_layout Plain Layout
1664
1665 <<Close INPUT and OUTPUT>>
1666 \end_layout
1667
1668 \end_inset
1669
1670
1671 \end_layout
1672
1673 \begin_layout Standard
1674 Note that in the perl code that is contained in the 
1675 \family roman
1676 \series medium
1677 \shape up
1678 \size normal
1679 \emph off
1680 \bar no
1681 \noun off
1682 \color none
1683
1684 \begin_inset ERT
1685 status collapsed
1686
1687 \begin_layout Plain Layout
1688
1689 [[while(<INPUT>)]]
1690 \end_layout
1691
1692 \end_inset
1693
1694
1695 \family default
1696 \series default
1697 \shape default
1698 \size default
1699 \emph default
1700 \bar default
1701 \noun default
1702  
1703 \color inherit
1704 loop above, the perl construct
1705 \color none
1706  
1707 \family roman
1708 \series medium
1709 \shape up
1710 \size normal
1711 \emph off
1712 \bar no
1713 \noun off
1714
1715 \begin_inset ERT
1716 status collapsed
1717
1718 \begin_layout Plain Layout
1719
1720 [[next line]]
1721 \end_layout
1722
1723 \end_inset
1724
1725
1726 \family default
1727 \series default
1728 \shape default
1729 \size default
1730 \emph default
1731 \bar default
1732 \noun default
1733  
1734 \color inherit
1735 is sufficient to restart the loop.
1736  We can use this construct to do some relatively complex parsing of the
1737  reLyX generated file.
1738 \end_layout
1739
1740 \begin_layout Subsection
1741 File input and output for the post-processing
1742 \end_layout
1743
1744 \begin_layout Standard
1745 Setting up the 
1746 \family roman
1747 \series medium
1748 \shape up
1749 \size normal
1750 \emph off
1751 \bar no
1752 \noun off
1753 \color none
1754
1755 \begin_inset ERT
1756 status collapsed
1757
1758 \begin_layout Plain Layout
1759
1760 [[INPUT]]
1761 \end_layout
1762
1763 \end_inset
1764
1765
1766 \family default
1767 \series default
1768 \shape default
1769 \size default
1770 \emph default
1771 \bar default
1772 \noun default
1773  
1774 \color inherit
1775 and
1776 \color none
1777  
1778 \family roman
1779 \series medium
1780 \shape up
1781 \size normal
1782 \emph off
1783 \bar no
1784 \noun off
1785
1786 \begin_inset ERT
1787 status collapsed
1788
1789 \begin_layout Plain Layout
1790
1791 [[OUTPUT]]
1792 \end_layout
1793
1794 \end_inset
1795
1796
1797 \family default
1798 \series default
1799 \shape default
1800 \size default
1801 \emph default
1802 \bar default
1803 \noun default
1804  
1805 \color inherit
1806 is taken care of by this code:
1807 \end_layout
1808
1809 \begin_layout Standard
1810 \begin_inset Flex Chunk
1811 status open
1812
1813 \begin_layout Plain Layout
1814
1815 \begin_inset Argument 1
1816 status open
1817
1818 \begin_layout Plain Layout
1819 Setup INPUT and OUTPUT for the final output
1820 \end_layout
1821
1822 \end_inset
1823
1824 if ($post_only) {
1825 \end_layout
1826
1827 \begin_layout Plain Layout
1828
1829   &setup_files("$input_file", "$output_file");
1830 \end_layout
1831
1832 \begin_layout Plain Layout
1833
1834 } else {
1835 \end_layout
1836
1837 \begin_layout Plain Layout
1838
1839   &setup_files("$relyx_file.lyx", "$output_file");
1840 \end_layout
1841
1842 \begin_layout Plain Layout
1843
1844 }
1845 \end_layout
1846
1847 \end_inset
1848
1849
1850 \end_layout
1851
1852 \begin_layout Subsection
1853 Making sure the code chunks are in the Chunk layout
1854 \end_layout
1855
1856 \begin_layout Standard
1857 Now, as we outlined before, the final step is transforming the code-chunks
1858  which have been put into a LaTeX layout by LyX into the Chunk layout.
1859 \end_layout
1860
1861 \begin_layout Standard
1862 \begin_inset Flex Chunk
1863 status open
1864
1865 \begin_layout Plain Layout
1866
1867 \begin_inset Argument 1
1868 status open
1869
1870 \begin_layout Plain Layout
1871 Fix code chunks in latex layout
1872 \end_layout
1873
1874 \end_inset
1875
1876 if (/
1877 \backslash
1878
1879 \backslash
1880 latex latex/) { # Beginning of some latex code
1881 \end_layout
1882
1883 \begin_layout Plain Layout
1884
1885   if (($line = <INPUT>) =~ /^
1886 \backslash
1887 s*<</) { # code chunk
1888 \end_layout
1889
1890 \begin_layout Plain Layout
1891
1892     <<Transform this chunk into layout chunk>>
1893 \end_layout
1894
1895 \begin_layout Plain Layout
1896
1897   } else {
1898 \end_layout
1899
1900 \begin_layout Plain Layout
1901
1902     # print the 
1903 \backslash
1904 latex latex line + next line
1905 \end_layout
1906
1907 \begin_layout Plain Layout
1908
1909     print OUTPUT "$_$line";
1910 \end_layout
1911
1912 \begin_layout Plain Layout
1913
1914   }
1915 \end_layout
1916
1917 \begin_layout Plain Layout
1918
1919   next line;
1920 \end_layout
1921
1922 \begin_layout Plain Layout
1923
1924 }
1925 \end_layout
1926
1927 \end_inset
1928
1929
1930 \end_layout
1931
1932 \begin_layout Standard
1933 When we are sure that we are in a code chunk, we must read in the rest of
1934  the code chunk and output a chunk layout for it:
1935 \end_layout
1936
1937 \begin_layout Standard
1938 \begin_inset ERT
1939 status open
1940
1941 \begin_layout Plain Layout
1942
1943 <<Transform this chunk into layout chunk>>=
1944 \end_layout
1945
1946 \begin_layout Plain Layout
1947
1948 \end_layout
1949
1950 \begin_layout Plain Layout
1951
1952 $savedchunk = "
1953 \backslash
1954
1955 \backslash
1956 layout Chunk
1957 \backslash
1958 n
1959 \backslash
1960 n$line";
1961 \end_layout
1962
1963 \begin_layout Plain Layout
1964
1965 codeline: while (<INPUT>) {
1966 \end_layout
1967
1968 \begin_layout Plain Layout
1969
1970  $savedchunk .= $_;
1971 \end_layout
1972
1973 \begin_layout Plain Layout
1974
1975  last codeline if /^@
1976 \backslash
1977 s+/;
1978 \end_layout
1979
1980 \begin_layout Plain Layout
1981
1982 };
1983 \end_layout
1984
1985 \begin_layout Plain Layout
1986
1987 print OUTPUT $savedchunk;
1988 \end_layout
1989
1990 \begin_layout Plain Layout
1991
1992 <<Slurp up to the end of the latex layout>>
1993 \end_layout
1994
1995 \begin_layout Plain Layout
1996
1997 @
1998 \end_layout
1999
2000 \end_inset
2001
2002
2003 \end_layout
2004
2005 \begin_layout Standard
2006 Okay, now we just need to eat the rest of the latex layout.
2007  There should only be a few different types of lines for us to match:
2008 \end_layout
2009
2010 \begin_layout Standard
2011 \begin_inset Flex Chunk
2012 status open
2013
2014 \begin_layout Plain Layout
2015
2016 \begin_inset Argument 1
2017 status open
2018
2019 \begin_layout Plain Layout
2020 Slurp up to the end of the latex layout
2021 \end_layout
2022
2023 \end_inset
2024
2025 slurp: while (<INPUT>) {
2026 \end_layout
2027
2028 \begin_layout Plain Layout
2029
2030   last slurp if /
2031 \backslash
2032
2033 \backslash
2034 latex /;
2035 \end_layout
2036
2037 \begin_layout Plain Layout
2038
2039   next slurp if /
2040 \backslash
2041
2042 \backslash
2043 newline/;
2044 \end_layout
2045
2046 \begin_layout Plain Layout
2047
2048   next slurp if /^
2049 \backslash
2050 s*$/;
2051 \end_layout
2052
2053 \begin_layout Plain Layout
2054
2055   warn "confused by line: $_";
2056 \end_layout
2057
2058 \begin_layout Plain Layout
2059
2060 }
2061 \end_layout
2062
2063 \end_inset
2064
2065
2066 \end_layout
2067
2068 \begin_layout Subsection
2069 Taking care of the 
2070 \noun on
2071 noweb
2072 \noun default
2073  
2074 \emph on
2075 [[quoted code]]
2076 \emph default
2077  construct
2078 \end_layout
2079
2080 \begin_layout Standard
2081
2082 \noun on
2083 noweb
2084 \noun default
2085  allows the user to use a special code quoting mechanism in documentation
2086  chunks.
2087  Fixing this ``[[quoted-code]]'' 
2088 \noun on
2089 noweb
2090 \noun default
2091  syntax means putting the ``[[quoted-code]]'' in a LaTeX layout in the LyX
2092  file.
2093  Otherwise, LyX will backslash-quote the brackets, creating ugly output.
2094  The quoted-code is transformed by 
2095 \noun on
2096 noweb
2097 \noun default
2098  when it generates the final LaTeX code.
2099 \end_layout
2100
2101 \begin_layout Standard
2102 \begin_inset Flex Chunk
2103 status open
2104
2105 \begin_layout Plain Layout
2106
2107 \begin_inset Argument 1
2108 status open
2109
2110 \begin_layout Plain Layout
2111 Fix [[var]] noweb construct
2112 \end_layout
2113
2114 \end_inset
2115
2116 if (/
2117 \backslash
2118 [
2119 \backslash
2120 [.+
2121 \backslash
2122 ]
2123 \backslash
2124 ]/) { # special code for [[var]]
2125 \end_layout
2126
2127 \begin_layout Plain Layout
2128
2129   s/
2130 \backslash
2131 [
2132 \backslash
2133 [.+?
2134 \backslash
2135 ]{2,}/
2136 \backslash
2137 n
2138 \backslash
2139
2140 \backslash
2141 latex latex
2142 \backslash
2143 n$&
2144 \backslash
2145 n
2146 \backslash
2147
2148 \backslash
2149 latex default
2150 \backslash
2151 n/g;
2152 \end_layout
2153
2154 \begin_layout Plain Layout
2155
2156   print OUTPUT;
2157 \end_layout
2158
2159 \begin_layout Plain Layout
2160
2161   next line;
2162 \end_layout
2163
2164 \begin_layout Plain Layout
2165
2166 }
2167 \end_layout
2168
2169 \end_inset
2170
2171
2172 \end_layout
2173
2174 \begin_layout Section
2175 Cleaning up intermediate files
2176 \end_layout
2177
2178 \begin_layout Standard
2179 The cleanup code is very simple:
2180 \end_layout
2181
2182 \begin_layout Standard
2183 \begin_inset Flex Chunk
2184 status open
2185
2186 \begin_layout Plain Layout
2187
2188 \begin_inset Argument 1
2189 status open
2190
2191 \begin_layout Plain Layout
2192 Clean up
2193 \end_layout
2194
2195 \end_inset
2196
2197 system("rm -f $relyx_file*") unless ($post_only || $pre_only);
2198 \end_layout
2199
2200 \end_inset
2201
2202
2203 \end_layout
2204
2205 \begin_layout Section
2206 User supplied arguments
2207 \end_layout
2208
2209 \begin_layout Standard
2210 The 
2211 \noun on
2212 noweb2lyx
2213 \noun default
2214  script understands two arguments, input-file and output-file.
2215  It is also set up to be used internally by reLyX to pre-process or postprocess
2216  files in the import pipeline.
2217 \end_layout
2218
2219 \begin_layout Standard
2220 \begin_inset ERT
2221 status open
2222
2223 \begin_layout Plain Layout
2224
2225 <<Setup variables from user supplied args>>=
2226 \end_layout
2227
2228 \begin_layout Plain Layout
2229
2230 &usage() if ($#ARGV < 1); # zero or one argument 
2231 \end_layout
2232
2233 \begin_layout Plain Layout
2234
2235 if ($ARGV[0] eq "-pre") {
2236 \end_layout
2237
2238 \begin_layout Plain Layout
2239
2240   &usage unless ($#ARGV == 2);
2241 \end_layout
2242
2243 \begin_layout Plain Layout
2244
2245   $input_file = $ARGV[1]; $output_file = $ARGV[2]; $pre_only = 1;
2246 \end_layout
2247
2248 \begin_layout Plain Layout
2249
2250 } elsif ($ARGV[0] eq "-post") {
2251 \end_layout
2252
2253 \begin_layout Plain Layout
2254
2255   &usage unless ($#ARGV == 2);
2256 \end_layout
2257
2258 \begin_layout Plain Layout
2259
2260   $input_file = $ARGV[1]; $output_file = $ARGV[2]; $post_only = 1;
2261 \end_layout
2262
2263 \begin_layout Plain Layout
2264
2265 } else {
2266 \end_layout
2267
2268 \begin_layout Plain Layout
2269
2270   &usage unless ($#ARGV == 1);
2271 \end_layout
2272
2273 \begin_layout Plain Layout
2274
2275   $input_file = $ARGV[0]; $output_file = $ARGV[1];
2276 \end_layout
2277
2278 \begin_layout Plain Layout
2279
2280   $pre_only = 0; $post_only = 0;
2281 \end_layout
2282
2283 \begin_layout Plain Layout
2284
2285 }
2286 \end_layout
2287
2288 \begin_layout Plain Layout
2289
2290 @ %def input_file output_file pre_only post_only
2291 \end_layout
2292
2293 \begin_layout Plain Layout
2294
2295 <<Subroutines>>=
2296 \end_layout
2297
2298 \begin_layout Plain Layout
2299
2300 sub usage() {
2301 \end_layout
2302
2303 \begin_layout Plain Layout
2304
2305   print "Usage: noweb2lyx [-pre | -post] input-file output-file
2306 \end_layout
2307
2308 \begin_layout Plain Layout
2309
2310 \end_layout
2311
2312 \begin_layout Plain Layout
2313
2314 If -pre is specified, only pre-processes the input-file for reLyX.
2315 \end_layout
2316
2317 \begin_layout Plain Layout
2318
2319 Similarly, in the case of -post, post-processes reLyX output.
2320 \end_layout
2321
2322 \begin_layout Plain Layout
2323
2324 In case of bugs, Email Kayvan Sylvan <kayvan
2325 \backslash
2326 @sylvan.com>.
2327 \backslash
2328 n";
2329 \end_layout
2330
2331 \begin_layout Plain Layout
2332
2333   exit;
2334 \end_layout
2335
2336 \begin_layout Plain Layout
2337
2338 }
2339 \end_layout
2340
2341 \begin_layout Plain Layout
2342
2343 @ %def usage
2344 \end_layout
2345
2346 \end_inset
2347
2348
2349 \end_layout
2350
2351 \begin_layout Section
2352 Generating the 
2353 \noun on
2354 noweb2lyx
2355 \noun default
2356  script
2357 \end_layout
2358
2359 \begin_layout Standard
2360 The noweb2lyx script can be tangled from LyX if you set 
2361 \family typewriter
2362
2363 \backslash
2364 build_command
2365 \family default
2366  to call a generic script that always extracts a chunk named 
2367 \family typewriter
2368 build-script
2369 \family default
2370  and executes it.
2371  Here is an example of such a script:
2372 \end_layout
2373
2374 \begin_layout LyX-Code
2375 #!/bin/sh
2376 \begin_inset Newline newline
2377 \end_inset
2378
2379 notangle -Rbuild-script $1 | env NOWEB_SOURCE=$1 NOWEB_OUTPUT_DIR=$2 sh
2380 \end_layout
2381
2382 \begin_layout Standard
2383 \begin_inset Flex Chunk
2384 status open
2385
2386 \begin_layout Plain Layout
2387
2388 \begin_inset Argument 1
2389 status open
2390
2391 \begin_layout Plain Layout
2392 build-script
2393 \end_layout
2394
2395 \end_inset
2396
2397 PREFIX=/usr
2398 \end_layout
2399
2400 \begin_layout Plain Layout
2401
2402 notangle -Rnoweb2lyx.in noweb2lyx.nw > noweb2lyx.in
2403 \end_layout
2404
2405 \begin_layout Plain Layout
2406
2407 sed -e "s=@PERL@=$PREFIX/bin/perl=" noweb2lyx.in > noweb2lyx
2408 \end_layout
2409
2410 \begin_layout Plain Layout
2411
2412 chmod +x noweb2lyx
2413 \end_layout
2414
2415 \end_inset
2416
2417
2418 \end_layout
2419
2420 \begin_layout Standard
2421 \begin_inset Newpage newpage
2422 \end_inset
2423
2424
2425 \end_layout
2426
2427 \begin_layout Section*
2428 Macros
2429 \end_layout
2430
2431 \begin_layout Standard
2432
2433 \family roman
2434 \series medium
2435 \shape up
2436 \size normal
2437 \emph off
2438 \bar no
2439 \noun off
2440 \color none
2441 \begin_inset ERT
2442 status collapsed
2443
2444 \begin_layout Plain Layout
2445
2446
2447 \backslash
2448 nowebchunks
2449 \end_layout
2450
2451 \end_inset
2452
2453
2454 \end_layout
2455
2456 \begin_layout Section*
2457 Identifiers
2458 \end_layout
2459
2460 \begin_layout Standard
2461
2462 \family roman
2463 \series medium
2464 \shape up
2465 \size normal
2466 \emph off
2467 \bar no
2468 \noun off
2469 \color none
2470 \begin_inset ERT
2471 status collapsed
2472
2473 \begin_layout Plain Layout
2474
2475
2476 \backslash
2477 nowebindex
2478 \end_layout
2479
2480 \end_inset
2481
2482
2483 \end_layout
2484
2485 \end_body
2486 \end_document