3 <style|<tuple|article|tmdoc-keyboard|header-article|fangle>>
7 <assign|LyX|<macro|L<space|-0.1667em><move|Y|0fn|-0.25em><space|-0.125em>X>>
9 <assign|par-first|0fn><assign|par-par-sep|0.5fn>
11 <assign|tick|<macro|<with|font|modern|font-family|ss|\<checkmark\>>>>
13 <assign|sub-page|<\macro|x>
17 <\padded-centered|0cm|2cm>
18 <indent-both|1cm|1cm|<arg|x>>
26 <doc-data|<doc-title|Getting Started with
27 Fangle>|<doc-author-data|<author-name|Sam Liddicott>|<\author-address>
32 This document explains how to use fangle and is a companion to
33 <strong|Fangle> which explains how fangle works.
35 Of course one does not need to know how Fangle works in order to use it,
36 and one may find it easier to understand how it works when one knows how
39 Because of this it is probably better to read <strong|Getting Started
40 with Fangle> before reading <strong|Fangle>.
42 This document is not intended to cover what <em|literate programming> is,
43 or what its advantages are. It is assumed that the reader will have some
44 knowledge of this. This document covers how to use fangle for literate
45 programming, assuming that the user has at least some theoretical
46 knowledge of what this entails.
48 This document includes getting and installing fangle, starting a new
49 simple fangle project (with <TeXmacs>, <LyX>, <LaTeX>, and plain text)
50 and then making use of <strong|Makefile.inc> (from the <strong|Fangle>
51 book) for larger projects and for specific sub-modules of existing Make
54 This document should have enough detail to help someone who is
55 un-familiar with <TeXmacs> or <LyX> to become acquainted with their use
56 for literate programming, but is not intended to guide the reader in
57 making particularly effective use of these editors.
59 It is assumed that the reader will already have a functioning
60 installation of <TeXmacs>, <LyX>, <LaTeX> or whatever document
61 preparation system they intend to employ.
64 <\table-of-contents|toc>
67 <part|Getting and Installing Fangle>
69 <section|Getting Fangle>
71 The latest release of Fangle can be downloaded as a gzip'd tar file from
72 the git repository at <hlink|http://git.savannah.gnu.org/cgit/fangle.git/snapshot/latest.tar.gz|>
74 You can checkout the entire git repository read-only by cloning either
75 <hlink|git://git.sv.gnu.org/fangle.git|> or
76 <hlink|http://git.savannah.gnu.org/r/fangle.git|>
78 Users with a Savannah.gnu.org login can also clone
79 <hlink|ssh://git.sv.gnu.org/srv/git/fangle.git|> which will also give
80 commit access to project members.
82 <section|Installing Fangle>
84 There is a <verbatim|make install>, but you will first need to decide if
85 you want a system wide installation for all users, or a private
86 installation just for one user.
88 A system installation is managed with <verbatim|sudo make install> and a
89 private installation is managed with <verbatim|make install-local>
91 The only difference between these make targets is the default installation
94 <subsection|Choosing the editing environment>
96 If you don't already have a preference, <TeXmacs> is recommended, but a
97 full list of supported features is shown in table
98 <reference|feature-table>.
100 <big-table|<tabular|<tformat|<cwith|2|9|2|6|cell-halign|c>|<cwith|2|9|1|6|cell-tborder|1ln>|<cwith|1|9|1|1|cell-rborder|1ln>|<table|<row|<cell|<strong|features>>|<cell|<TeXmacs>>|<cell|<LyX>>|<cell|<TeX>>|<cell|Text>|<cell|Other
101 with Text export>>|<row|<cell|final-layout in edit
102 mode>|<cell|<tick>>|<cell|>|<cell|>|<cell|>|<cell|>>|<row|<cell|syntax
103 highlighting in edit mode>|<cell|few>|<cell|>|<cell|>|<cell|>|<cell|>>|<row|<cell|syntax
104 highlighting in PDF export>|<cell|few>|<cell|many>|<cell|many>|<cell|>|<cell|>>|<row|<cell|syntax
105 highlighting in HTML export>|<cell|few>|<cell|>|<cell|>|<cell|>|<cell|>>|<row|<cell|line-numbers
106 in edit mode>|<cell|<tick>>|<cell|>|<cell|>|<cell|>|<cell|>>|<row|<cell|hyperlinks
107 in edit mode>|<cell|<tick>>|<cell|>|<cell|>|<cell|>|<cell|>>|<row|<cell|hyperlinks
108 in PDF export>|<cell|<tick>>|<cell|<tick>>|<cell|<tick>>|<cell|>|<cell|>>|<row|<cell|hyperlinks
109 in HTML export>|<cell|<tick>>|<cell|<tick>>|<cell|<tick>>|<cell|>|<cell|>>>>>|Feature
110 comparison table<label|feature-table>>
112 <subsection|For personal use>
114 If the default private installation directories are acceptable, then type:
116 <verbatim|make install-local>
118 which will install in the following locations
120 <block|<tformat|<table|<row|<cell|>|<cell|files>|<cell|locations>|<cell|override>>|<row|<cell|executables>|<cell|<verbatim|fangle>>|<cell|<verbatim|$HOME/.local/bin>>|<cell|<verbatim|BINDIR>>>|<row|<cell|<TeXmacs>
121 plugins>|<cell|<verbatim|fangle.ts>>|<cell|<verbatim|$HOME/.TeXmacs><em|/plugins>>|<cell|<verbatim|TEXMACS_DIR>>>|<row|<cell|<LyX>
122 modules>|<cell|<verbatim|fangle.module>>|<cell|<verbatim|$HOME/.lyx><em|/modules>>|<cell|<verbatim|LYX_DIR>>>>>>
126 <subsubsection|Executables>
128 Executables need installing to where personal programs are kept. This could
129 just be the git checkout directory or the place where you un-tar'd
132 I keep my personal programs in a private <verbatim|.local/bin> directory
133 which I keep in my path.
135 You could overide this to <verbatim|$HOME/bin> like this:
137 <verbatim|make local-install BINDIR=$HOME/bin>
139 If you don't have the target folder in your path (and you use bash) you
140 could add it like this:
142 <verbatim|echo 'export PATH=$PATH:$HOME/.local/bin' \<gtr\>\<gtr\>
145 and if you don't want to have to login again, also set the path for the
148 <verbatim|<verbatim|export PATH=$PATH:$HOME/.local/bin>>
150 <subsubsection|<TeXmacs> plugins>
152 If you are using <TeXmacs>, then the fangle plugin needs copying to your
153 private <TeXmacs> plugins folder, normally
154 <verbatim|$HOME/.TeXmacs/plugins/> where a folder <verbatim|fangle> is
155 created to contain the plugin files.\
157 You could override this to <verbatim|$HOME/usr/local/texmacs/TeXmacs/plugins>
160 <verbatim|make local-install TEXMACS_DIR=$HOME/usr/local/texmacs/TeXmacs>
162 Note that you do not have to specify the sub-folder <verbatim|plugins>
163 <emdash> this is automatically added onto the provided
164 <verbatim|TEXMACS_DIR>
166 <subsubsection|The <LyX> stylesheet>
168 If you are using <LyX>, then <verbatim|fangle.module> needs copying to your
169 private <LyX> modules folder, normally <verbatim|$HOME/.lyx/modules/>
171 You could override this to <verbatim|$HOME/usr/local/lyx/modules> like
174 <verbatim|make local-install LYX_DIR=$HOME/usr/local/lyx>
176 Note that you do not have to specify the sub-folder <verbatim|modules>
177 <emdash> this is automatically added onto the provided <verbatim|LYX_DIR>
179 You will also need to have Norman Ramsey's <name|noweb> stylesheet
180 installed as part of your <TeX> installation.
182 <subsubsection|The <TeX> stylesheet>
184 <todo|Still needs ripping off out of the .module maybe>
186 You will also need to have Norman Ramsey's noweb stylesheet installed.
188 <subsection|For system-wide use>
190 If the default system installation directories are acceptable, then type:
192 <verbatim|sudo make install>
194 which will install in the following locations
196 <block|<tformat|<table|<row|<cell|>|<cell|files>|<cell|locations>|<cell|override>>|<row|<cell|executables>|<cell|<verbatim|fangle>>|<cell|<verbatim|/usr/local/bin>>|<cell|<verbatim|BINDIR>>>|<row|<cell|<TeXmacs>
197 plugins>|<cell|<verbatim|fangle.ts>>|<cell|<verbatim|/usr/share/texmacs/TeXmacs><em|/plugins>>|<cell|<verbatim|TEXMACS_DIR>>>|<row|<cell|<LyX>
198 modules>|<cell|<verbatim|fangle.module>>|<cell|<verbatim|/usr/share/lyx><em|/modules>>|<cell|<verbatim|LYX_DIR>>>>>>
200 <subsubsection|Executables>
202 Executables need installing where all users will find them, usually
203 somewhere in the system <verbatim|PATH>. This defaults to
204 <verbatim|/usr/local/bin> but you could overide to <verbatim|/usr/bin> like
207 <verbatim|sudo make install BINDIR=/usr/bin>
209 You could extract the entire package to <verbatim|/opt/fangle> but might
210 want to add <verbatim|/opt/fangle> to the system-wide path. You could do
214 sudo make install BINDIR=/opt/fangle/bin
216 echo 'PATH=$PATH:/opt/fangle' \<gtr\>\<gtr\> /etc/profile.d/fangle.sh
218 echo export PATH \<gtr\>\<gtr\> /etc/profile.d/fangle.sh
221 <subsubsection|The <TeXmacs> stylesheet>
223 If you are using <TeXmacs> then you will need to install
224 <verbatim|fangle.ts> into the <TeXmacs> system-wide plugins folder. This
225 might be in <verbatim|/usr/share/texmacs/TeXmacs> but may vary across
228 You could override like this:
230 <verbatim|sudo make install TEXMACS_DIR=/usr/local/share/texmacs/TeXmacs>
232 Note that you do not have to specify the sub-folder <verbatim|plugins>
233 <emdash> this is automatically added onto the provided
234 <verbatim|TEXMACS_DIR>
236 <subsubsection|The <LyX> stylesheet>
238 If you are using <LyX>, then you will need to install
239 <verbatim|fangle.module> into the <LyX> system-wide modules folder. This
240 might be in <verbatim|/usr/share/lyx/> but may vary across installations.
242 You could override like this:
244 <verbatim|sudo make install LYX_DIR=/usr/share/lyx>
246 Note that you do not have to specify the sub-folder <verbatim|modules>
247 <emdash> this is automatically added onto the provided <verbatim|LYX_DIR>
249 You will also need to have Norman Ramsey's <name|noweb> stylesheet
250 installed as part of your <TeX> installation.
252 <subsubsection|The <TeX> stylesheet>
254 <todo|Still needs ripping off out of the .module maybe>
256 You will also need to have Norman Ramsey's noweb stylesheet installed.
258 <part|Authoring with Fangle>
260 Fangle has editor style-sheets for <TeXmacs> and <LyX> to aid document
263 Fangle can untangle<\footnote>
264 <em|untangling> is the historical term referring to the extraction or
265 generation of source code from the documentation
266 </footnote> sources from text files produced by <TeXmacs>'s verbatim
267 export, from <TeX> files generated by <LyX>, from plain hand-edited <LaTeX>
268 or <TeX> files, and from plain text files that adhere to certain
269 conventions (either hand-written or generated from other document editors).
271 This part will show how to start a simple project for <TeXmacs>, <LyX>,
272 <LaTeX>/<TeX> and plain text.
274 The instructions cover more than mere use of the fangle style-sheet.
275 Literate programming is more than just pretty-looks or a bound booklet
276 <emdash> it is a mind-set. Good titles, author information, abstracts, good
277 structure and good narrative are essential to stop the whole thing being a
278 good-looking waste of time.
282 This section does not assume a large degree of familiarity with <TeXmacs>,
283 but you should have spent at least a few minutes figuring out how to use
286 <subsection|Load fangle style-sheet>
289 <item>Start <TeXmacs> with a new document.
291 <item>Choose an appropriate document style:
293 From the menu: <menu|Document|Style|article>
295 For small informal projects I usually choose <em|article>, and for longer
296 more formal projects I usually choose a <em|book>.
298 <item>Add the fangle package:
300 From the menu: <menu|Document|Add package|fangle>
302 If the <em|fangle> package isn't listed, then update your styles
305 <menu|Tools|Update|Styles> and then try again
307 <item>Optionally, (if you prefer this style):
309 <menu|Document|View|Create preamble> (or <menu|Document|View|Show
310 preamble>) and insert this:
312 <verbatim|\<less\>assign\|par-first\|0fn\<gtr\>\<less\>assign\|par-par-sep\|0.5fn\<gtr\>>
314 and then: <menu|Document|View|Show all parts>
317 <subsection|Save the document>
319 Save the document, and call it <verbatim|hello-world.tm>
321 From the menu: <menu|File|Save>
323 <subsection|Sandard document parts>
325 <subsubsection|Insert your title>
327 <menu|Insert|Title|Insert title>
330 <item>Type the name of your document:
331 <keys|L|i|t|e|r|a|t|e|space|E|x|a|m|p|l|e>
333 <item>Press <key|enter> and then type your name.
335 <item>Press <key|enter> and then type your email address.
337 <item>Press <key|right> to leave the title block
340 <subsubsection|Insert your abstract>
342 <menu|Insert|Title|Abstract>
344 The abstract should explain what the document is about and help the reader
345 discover if the document is relevant to them. It should not contain
346 explanations that the document contains but it should explain what it is
347 that the document contains.
349 See the abstract to this document for a fair example.
351 After you have entered the abstract, press <key|right> to leave the
354 <subsubsection|Insert a table of contents>
356 <menu|Insert|Automatic|Table of contents>
358 <subsubsection|Start a new section (or chapter)>
360 <menu|Insert|Section|Section> (or if you are writing a book
361 <menu|Insert|Section|Chapter>), and then type the name of the section (or
364 <keys|H|e|l|l|o|space|W|o|r|l|d|enter>
366 The first chapter will generally illustrate the problem to be solved and
367 explain how the book is to be used to understand and provide the solution.
369 <subsection|Talk about your code>
371 Before you insert a chunk of code, you introduce it.
373 Usually you will have introduced some aspect of the main problem that the
374 program as a whole will solve, and will then outline the aspect of the
375 solution that this chunk will provide.
377 We will introduce our hello-world chunk by typing:
379 <key|T h e> <key|space> <key|t y p i c a l> <key|space> <key|h e l l o>
380 <key|space> <key|w o r l d> <key|space> <key|p r o g r a m> <key|space>
381 <key|l o o k s> <key|space> <key|l i k e> <key|space> <key|t h i s :>
384 <subsection|Insert your first code chunk>
386 Fangle currently has no menus; all commands are entered with a back-slash.
387 This may annoy you, but it is much faster to keep your hands off the mouse.
389 <todo|Add some menus bindings>
391 Fangle chunks are (currently) called: <verbatim|nf-chunk> and are entered
395 <item>type: <keys|\\|n|f|-|c|h|u|n|k> <emdash> it will appear like this:
396 <inactive|<hybrid|nf-chunk>>
398 <item>press <key|enter><math|>
400 Depending on your <TeXmacs> environment, you may get either this
401 <inactive|<nf-chunk|<fake-caret>|||>> which is the inactive view, or the
402 active view shown below:
405 <\nf-fake-chunk|<fake-caret>>
407 </nf-fake-chunk|||1|1a|||||>
410 If the text insertion point (represented by the red verticle line
411 <fake-caret>) does not appear as shown above, then press <key|left> so
414 <item>Type the name of your chunk: <keys|h|e|l|l|o|-|w|o|r|l|d>
416 This will give you either <inactive|<nf-chunk|hello-world<fake-caret>|||>>
417 for the inactive view, or the active view shown as below:
420 <\nf-fake-chunk|hello-world<fake-caret>>
422 </nf-fake-chunk|||1|1a|||||>
426 <subsection|Optional chunk parameters>
428 Press <key|right> to move the text insertion point to the second argument
431 This is to specify parameters to the code that will be contained in the
432 chunk. Chunks can take optional parameters, and behave somewhat like C
435 Usually chunks will not have parameters, although parameters can be useful
436 when a chunk is used to express an algorithm (like a sort) or a class of
437 behaviours (like binary tree management). In such cases, a set of
438 parameterized chunks can work a bit like generics or C++ templates.
440 If chunk has parameters, they must be enclosed in a tuple. When I
441 understand DRD's a bit better this will be done for you, but for now if you
442 want chunk parameters then you create a tuple, otherwise skip to the next
445 <subsubsection|Create a tuple>
447 Press <key|\\>. If this comes out as a backslash <with|color|red|\\>
448 (perhaps red) instead of in angle brackets like this
449 <with|color|blue|<math|\<langle\>\\\<rangle\>>> then press <key|backspace>
450 and enter a command-backslash using the meta key (probably the windows
451 button) by pressing <key|M-\\>.\
453 Once you have the <with|color|blue|<math|\<langle\>\\\<rangle\>>>, type
454 <keys|t|u|p|l|e|enter>.
456 Type the first chunk argument, and then for additional arguments,
457 <key|M-right> (windows key and right arrow).
459 You can type multiple parameters:
460 <inactive|<nf-chunk|hello-world|<tuple|message|language<fake-caret>>||>> or
463 <\nf-fake-chunk|hello-world>
465 </nf-fake-chunk||<tuple|message|language<fake-caret>>|1|1a|||||>
468 <subsection|Typing code>
470 Press <key|right> to move the text insertion point to the main code area.
472 If your chunk shows as inactive then this will be visible as the third
473 argument, but you may prefer to activate your chunk at this point. You
474 should be able to do this by pressing <key|enter> or clicking the
475 <image|<tuple|<#89504E470D0A1A0A0000000D49484452000000110000001108060000003B6D47FA000000017352474200AECE1CE900000006624B474400FF00FF00FFA0BDA793000000097048597300000B1300000B1301009A9C180000000774494D4507DB06120F0303780569BC0000001974455874436F6D6D656E74004372656174656420776974682047494D5057810E17000000924944415438CBBD94D10D80200C440FE3127E38846C0303EA3665083F1CA37E95102D52A2B17F90DCCB91BBE22811E3E50CF860C6F2E0176F1652221D020031C42660DDD6BA935EB119721532339C733688888FFDC877D33CD99C68620130731D52A67215B700B927129706E82A1B2552DFDC72A136B60459002A2486584DA16B77046471F11831805BA94C9072A97EFF0A4E5C193CCC5933FA210000000049454E44AE426082>|png>|2ex|||>
476 icon on the toolbar. Sometimes the <image|<tuple|<#89504E470D0A1A0A0000000D49484452000000110000001108060000003B6D47FA000000017352474200AECE1CE900000006624B474400FF00FF00FFA0BDA793000000097048597300000B1300000B1301009A9C180000000774494D4507DB06120F0303780569BC0000001974455874436F6D6D656E74004372656174656420776974682047494D5057810E17000000924944415438CBBD94D10D80200C440FE3127E38846C0303EA3665083F1CA37E95102D52A2B17F90DCCB91BBE22811E3E50CF860C6F2E0176F1652221D020031C42660DDD6BA935EB119721532339C733688888FFDC877D33CD99C68620130731D52A67215B700B927129706E82A1B2552DFDC72A136B60459002A2486584DA16B77046471F11831805BA94C9072A97EFF0A4E5C193CCC5933FA210000000049454E44AE426082>|png>|2ex|||>
477 icon is absent and pressing enter does nothing <emdash> in which case try
478 the <menu|Tools|Update|Styles> and if that doesn't work then I don't know
481 The code body is an enumerate style. Press <key|enter> to insert a new
482 numbered line. (You'll probably want to press <keys|left|backspace|right>
483 to delete the blank line that is somehow there. <todo|stop that from
487 <\nf-fake-chunk|hello-world>
489 </nf-fake-chunk||<tuple|message|language>|1|1a|||||>
492 At this point, start typing code.
494 When you press <key|enter>, a new line number will be inserted at the left
495 of the listing. If you press <key|S-enter> then you can break the line for
496 layout purposes, but it will not be considered a new-line when the code is
497 extracted, and leading white-space will be stripped.
500 <\nf-fake-chunk|hello-world>
501 <item>#include stdio.c
507 <item> \ printf("<fake-caret>
508 </nf-fake-chunk||<tuple|message|language>|1|1a|||||>
511 The listing above is incomplete. Instead of typing the the traditional
512 <verbatim|hello world!>, we can make use of our chunk arguments. Let's
513 place the value of the argument <with|color|blue|message> at this point.
515 The command for a chunk argument is <keys|\\|n|f|-|a|r|g>, but when you
516 press the <key|\\> it will enter a literal <verbatim|\\> because the cursor
517 is in a code block. To enter a command-backslash in code block, use the
518 meta key (probably the windows button): <keys|M-\\|n|f|-|a|r|g> and this
519 will produce: <inactive*|<nf-arg|>>
521 To enter the name of the argument <with|color|blue|message>, type
522 <keys|m|e|s|s|a|g|e|right> which will produce <nf-arg|message>
524 Finish typing the code as shown below:
527 <\nf-fake-chunk|hello-world>
528 <item>#include stdio.c
534 <item> \ printf("<nf-arg|message>\\n");
537 </nf-fake-chunk||<tuple|message|language>|1|1a|||||>
540 We've now defined a chunk of code which can potentially produce the famous
541 <verbatim|hello world!> in any language.
543 If the chunk were more complicated, we could break off part-way through and
544 provide more explanation, and then insert another chunk <em|with the same
545 name> to continue the code. In this way a single chunk can be broken across
546 sections and spread across the whole document and still be assembled in
549 Let's define some file-chunks that use this chunk.
551 <subsection|File chunks>
553 By convention, file chunk is just a regular chunk whose name begins with
554 <verbatim|./> which signifies to build-tools that it should be extracted
557 <subsubsection|French hello-world>
559 Insert a new sub-section for french:
561 <menu|Insert|Section|Subsection> (or <menu|Insert|Section|Section>) and
562 type the name of the subsection:
564 <key|I n> <key|space> <key|F r e n c h> <key|enter>
566 Then introduce the next code chunk, type:
567 <keys|W|e|space|w|i|l|l|space|d|e|r|i|v|e|space|t|h|e|space|f|r|e|n|c|h|space|h|e|l|l|o|-|w|o|r|l|d|space|p|r|o|g|r|a|m|space|l|i|k|e|space|t|h|i|s|:|enter>
569 Then, create a chunk called hello-world.fr.c, by typing:
570 <keys|\\|n|f|-|c|h|u|n|k|enter> and then the chunk name
571 <keys|.|/|h|e|l|l|o|-|w|o|r|l|d|.|f|r|.|c|right|right>
574 <strong|<small|1.1 In French>><htab|0mm>
576 We will derive the french hello-world program like this:<htab|0mm>
578 <\nf-fake-chunk|./hello-world.fr.c>
580 </nf-fake-chunk||<tuple>|1|1b|||||>
583 To include our previous chunk with the <verbatim|nf-ref> command, type
584 <keys|M-\\|n|f|-|r|e|f|enter> and then type the name of our previous chunk,
585 <keys|h|e|l|l|o|-|w|o|r|l|d>
587 We then move to the arguments part of the <verbatim|nf-ref>, <key|right>,
588 and type the argument <em|Bonjour tout le monde> in a tuple:
590 <keys|M-\\|t|u|p|l|e|enter|B|o|n|j|o|u|r|space|t|o|u|t|space|l|e|space|m|o|n|d|e|enter>
593 <strong|<small|1.1 In French>><htab|0mm>
595 We will derive the french hello-world program like this:<htab|0mm>
597 <\nf-fake-chunk|./hello-world.fr.c>
598 <item><nf-fake-ref|hello-world|<tuple|Bonjour tout le
599 monde>|1a><fake-caret>
600 </nf-fake-chunk||<tuple>|1|1b|||||>
603 Note that when there are no arguments to the reference, the parenthesis do
604 not appear, but they appear automatically when there are arguments.
606 <subsubsection|German hello-world>
608 And let's create a similar chunk for german. Insert a new sub-section:
610 <menu|Insert|Section|Subsection> (or <menu|Insert|Section|Section>) and
611 type the name of the subsection:
613 <key|I n> <key|space> <key|G e r m a n> <key|enter>
615 Then introduce the next code chunk, type:
616 <keys|W|e|space|w|i|l|l|space|d|e|r|i|v|e|space|t|h|e|space|g|e|r|m|a|n|space|h|e|l|l|o|-|w|o|r|l|d|space|p|r|o|g|r|a|m|space|l|i|k|e|space|t|h|i|s|:|enter>
618 Create a chunk called hello-world.de.c, by typing:
619 <keys|\\|n|f|-|c|h|u|n|k|enter> and then the chunk name
620 <keys|.|/|h|e|l|l|o|-|w|o|r|l|d|.|d|e|.|c|right|right>
623 <strong|<small|1.2 In German>><htab|0mm>
625 We will derive the german hello-world program like this:<htab|0mm>
627 <\nf-fake-chunk|./hello-world.de.c>
628 <item><nf-fake-ref|hello-world|<tuple|Hallo welt>|1a><fake-caret>
629 </nf-fake-chunk||<tuple>|1|1c|||||>
632 <subsection|Additional parameters>
634 Astute readers will have noticed that the <verbatim|hello-world> chunk has
635 two parameters but that our french and german invocations only have one
636 argument. This is not really a problem as the <verbatim|hello-world> chunk
637 only uses one; but let's change that:
640 <\nf-fake-chunk|hello-world>
641 <item>/* The traditional hello-world program in <nf-arg|language>\
643 <item> * generated using fangle literate programming macros
649 <item>#include stdio.c
655 <item> \ printf("<nf-arg|message>\\n");
658 </nf-fake-chunk||<tuple|message|language>|1|1a|||||>
661 We will now modify our french and german .c files by clicking inside
662 <with|color|blue|Bonjour tout le monde> and pressing <key|M-right> and then
663 typing: <key|f r e n c h>
666 <\nf-fake-chunk|./hello-world.fr.c>
667 <item><nf-fake-ref|hello-world|<tuple|Bonjour tout le
668 monde|french>|1a><fake-caret>
669 </nf-fake-chunk||<tuple>|1|1b|||||>
672 And doing similarly for the german:
675 <\nf-fake-chunk|./hello-world.de.c>
676 <item><nf-fake-ref|hello-world|<tuple|Hallo
677 welt|german>|1a><fake-caret>
678 </nf-fake-chunk||<tuple>|1|1c|||||>
681 <subsection|Extracting individual files>
683 Later on, automatic extraction using <verbatim|Makefile.inc> is shown, but
684 this is how to extract chunks manually from a <TeXmacs> document.
687 <item>Save the <verbatim|hello-world.tm> document\
689 <item>Generate a text file hello-world.txt, either with
690 <menu|File|Export\|Verbatim> or with this command line:
692 <verbatim|texmacs -s -c hello-world.tm hello-world.txt -q>
694 <item>Extract the french and german files:
697 fangle -R./hello-world.fr.c hello-world.txt \<gtr\> hello-world.fr.c
699 fangle -R./hello-world.de.c hello-world.txt \<gtr\> hello-world.de.c
703 The resultant french file should look like this:
707 <\with|par-par-sep|0fn>
708 /* The traditional hello-world program in french\
710 \ * generated using fangle literate programming macros
722 \ \ printf("Bonjour tout le monde\\n");
729 <subsection|Extracting all files>
731 A list of all the chunks can be obtained with:
733 <verbatim|fangle -r hello-world.txt>
735 So we can extract all files like this:
738 texmacs -s -c hello-world.tm hello-world.txt -q &&
740 fangle -r hello-world.txt \| while read file
742 do fangle -R"$file" hello-world.txt \<gtr\> "$file"
747 If you have <em|noweb> installed then you can use <verbatim|cpif> to avoid
748 updating files that haven't changed:
751 texmacs -s -c hello-world.tm hello-world.txt -q &&
753 fangle -r hello-world.txt \| while read file
755 do fangle -R"$file" hello-world.txt \| cpif "$file"
760 <subsection|The completed document>
762 The document you typed might look something like this:<no-page-break>
765 <htab|0mm><strong|Literate Example><htab|0mm>
767 <\with|par-par-sep|0fn>
769 Joe Soap<htab|0mm>joe@example.com
773 <htab|0mm><small|<strong|Abstract>><htab|0mm>
776 This is a simple example of how to use literate programming templates,
779 Hello-world is a famous <em|first program> with a visible side effect.
781 This example produces hello-world in mulfake-caretle languages.
784 <strong|Table of Contents>
786 <\with|par-par-sep|0fn>
787 <with|font-series|bold|math-font-series|bold|1<space|2spc>Hello World>
788 <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
791 <with|par-left|1.5fn| \ \ \ 1.1<space|2spc>In French
792 <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
793 <no-break>1><vspace|0.0fn>
795 <with|par-left|1.5fn| \ \ \ 1.2<space|2spc>In German
796 <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
797 <no-break>1><vspace|0.5fn>
800 <with|font-series|bold|math-font-series|bold|1 Hello World>
802 The typical hello-world program looks something like this:
804 <\nf-fake-chunk|hello-world>
805 <item>/* The traditional hello-world program in <nf-arg|language>\
807 <item> * generated using fangle literate programming macros
813 <item>#include stdio.c
819 <item> \ printf("<nf-arg|message>\\n");
822 </nf-fake-chunk||<tuple|message|language>|1|1a|||||>
824 <strong|<small|1.1 In French>>
826 We will derive the french hello-world program like this:<htab|0mm>
828 <\nf-fake-chunk|./hello-world.fr.c>
829 <item><nf-fake-ref|hello-world|<tuple|Bonjour tout le monde|french>|1a>
830 </nf-fake-chunk||<tuple>|1|1b|||||>
832 <small|<strong|1.2 In German>>
834 We will derive the german hello-world program like this:<htab|0mm>
836 <\nf-fake-chunk|./hello-world.de.c>
837 <item><nf-fake-ref|hello-world|<tuple|Hallo welt|german>|1a>
838 </nf-fake-chunk||<tuple>|1|1c|||||>
841 <no-page-break*>Which demonstrates nicely how to use fangle in terms of
842 function, but less so in terms of style.
847 <associate|page-medium|papyrus>
848 <associate|page-screen-height|746496tmpt>
849 <associate|page-screen-margin|false>
850 <associate|page-screen-width|1268736tmpt>
851 <associate|preamble|false>