Skip to content

Commit c9ce729

Browse files
GAPgap
authored andcommitted
Simpler code for extraction of manual examples 'units'-wise;
experimental. git-svn-id: path/gapdoc/trunk@113
1 parent a7055d9 commit c9ce729

File tree

6 files changed

+127
-103
lines changed

6 files changed

+127
-103
lines changed

TODO

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11

22
Some reminders for the authors
33

4-
$Id: TODO,v 1.8 2007-01-31 13:45:09 gap Exp $
4+
$Id: TODO,v 1.9 2007-03-05 16:51:11 gap Exp $
55

6-
- use InfoClass(es) instead of Print's
7-
8-
- MakeDocDoc: only pdf-version from LaTeX
9-
10-
- document SetGapDocLaTeXOptions
6+
- give record with predefined entities to ParseTreeXML...
7+
(and use this for the predefined GAPDoc entities)
118

129
- document StringBibAs..., change doc for <Bibliography>
1310

14-
- remove mention of DeclarePackageAutoDocumentation and so on.
15-
1611
- maybe add links to "the" example in the reference section of doc?
1712
(not so sure, if this is necessary).
1813

@@ -29,9 +24,6 @@
2924
- finalize lib/Examples.g for builtin manual example tester and include and
3025
document it.
3126

32-
- improve explanations of encodings, maybe add example how to handle a
33-
latin-2 special character. How about handling UTF-8?
34-
3527
- allow the distribution of different output documents (html, text, pdf,...)
3628
into different directories (needs to change the handler for GAPDoc books).
3729

init.g

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
##
33
#A init.g GAPDoc Frank Lübeck / Max Neunhöffer
44
##
5-
#H @(#)$Id: init.g,v 1.12 2007-02-20 16:56:27 gap Exp $
5+
#H @(#)$Id: init.g,v 1.13 2007-03-05 16:51:11 gap Exp $
66
##
77
#Y Copyright (C) 2000, Frank Lübeck and Max Neunhöffer,
88
#Y Lehrstuhl D für Mathematik, RWTH Aachen
@@ -20,6 +20,7 @@ ReadPackage("GAPDoc", "lib/GAPDoc2LaTeX.gd");
2020
ReadPackage("GAPDoc", "lib/GAPDoc2Text.gd");
2121
ReadPackage("GAPDoc", "lib/GAPDoc2HTML.gd");
2222
ReadPackage("GAPDoc", "lib/Make.g");
23+
ReadPackage("GAPDoc", "lib/Examples.gd");
2324

2425
# The handler functions for GAP's help system are read now:
2526
ReadPackage("GAPDoc", "lib/HelpBookHandler.g");

lib/Examples.g

Lines changed: 0 additions & 90 deletions
This file was deleted.

lib/Examples.gd

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#############################################################################
2+
##
3+
#W Examples.gd GAPDoc Frank Lübeck
4+
##
5+
#H @(#)$Id: Examples.gd,v 1.1 2007-03-05 16:51:11 gap Exp $
6+
##
7+
#Y Copyright (C) 2007, Frank Lübeck, Lehrstuhl D für Mathematik,
8+
#Y RWTH Aachen
9+
##
10+
## The files Examples.g{d,i} contain functions for extracting and checking
11+
## GAP examples in GAPDoc manuals.
12+
##
13+
14+
DeclareGlobalFunction("GetTextXMLTree");
15+
DeclareGlobalFunction("XMLElements");
16+
DeclareGlobalFunction("ManualExamplesXMLTree");
17+
DeclareGlobalFunction("ManualExamples");
18+
DeclareGlobalFunction("TestExamplesString");
19+

lib/Examples.gi

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#############################################################################
2+
##
3+
#W Examples.gi GAPDoc Frank Lübeck
4+
##
5+
#H @(#)$Id: Examples.gi,v 1.1 2007-03-05 16:51:11 gap Exp $
6+
##
7+
#Y Copyright (C) 2007, Frank Lübeck, Lehrstuhl D für Mathematik,
8+
#Y RWTH Aachen
9+
##
10+
## The files Examples.g{d,i} contain functions for extracting and checking
11+
## GAP examples in GAPDoc manuals.
12+
##
13+
14+
# extract and collect text in elements recursively
15+
InstallGlobalFunction(GetTextXMLTree, function(r)
16+
local res, fun;
17+
res := "";
18+
fun := function(r)
19+
if IsString(r.content) then
20+
Append(res, r.content);
21+
fi;
22+
end;
23+
ApplyToNodesParseTree(r, fun);
24+
return res;
25+
end);
26+
27+
# return list of nodes of elements with name in 'eltnames' from XML tree r
28+
InstallGlobalFunction(XMLElements, function(r, eltnames)
29+
local res, fun;
30+
res := [];
31+
fun := function(r)
32+
if r.name in eltnames then
33+
Add(res, r);
34+
fi;
35+
end;
36+
ApplyToNodesParseTree(r, fun);
37+
return res;
38+
end);
39+
40+
# Extract examples units-wise from a GAPDoc document as XML tree,
41+
# 'units' can either be: "Chapter" or "Section" or "Subsection" or "Single"
42+
# then a list of strings is returned
43+
# For all other values of 'units' one string with all examples is returned.
44+
# Before each extracted example there is its paragraph number in a comment:
45+
# [ chapter, section, subsection, paragraph ]
46+
47+
InstallGlobalFunction(ManualExamplesXMLTree, function( tree, units )
48+
local secelts, sec, exelts, res, str, a, ex;
49+
if units = "Chapter" then
50+
secelts := ["Chapter", "Appendix"];
51+
elif units = "Section" then
52+
secelts := ["Section"];
53+
elif units = "Subsection" then
54+
secelts := ["Subsection", "ManSection"];
55+
elif units = "Single" then
56+
secelts := ["Example"];
57+
else
58+
secelts := 0;
59+
fi;
60+
if secelts <> 0 then
61+
sec := XMLElements(tree, secelts);
62+
else
63+
sec := [tree];
64+
fi;
65+
# want to put section numbers in comments
66+
AddParagraphNumbersGapDocTree(tree);
67+
exelts := List(sec, a-> XMLElements(a, ["Example"]));
68+
res := [];
69+
for a in exelts do
70+
str := "";
71+
for ex in a do
72+
Append(str, "# from paragraph ");
73+
Append(str, String(ex.count));
74+
Append(str, "\n");
75+
Append(str, GetTextXMLTree(ex));
76+
Append(str, "\n");
77+
od;
78+
Add(res, str);
79+
od;
80+
if secelts = 0 then
81+
res := res[1];
82+
fi;
83+
return res;
84+
end);
85+
86+
# compose and parse document, then extract examples units-wise
87+
InstallGlobalFunction(ManualExamples, function( path, main, files, units )
88+
local str, xmltree;
89+
str:= ComposedDocument( "GAPDoc", path, main, files, true );
90+
xmltree:= ParseTreeXMLString( str[1], str[2] );
91+
return ManualExamplesXMLTree(xmltree, units);
92+
end);
93+
94+
# test a string with examples
95+
InstallGlobalFunction(TestExamplesString, function(str)
96+
local file;
97+
file := InputTextString(str);
98+
ReadTest(file);
99+
CloseStream(file);
100+
end);
101+

read.g

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
##
33
#A read.g GAPDoc Frank Lübeck / Max Neunhöffer
44
##
5-
#H @(#)$Id: read.g,v 1.5 2007-02-20 16:56:27 gap Exp $
5+
#H @(#)$Id: read.g,v 1.6 2007-03-05 16:51:11 gap Exp $
66
##
77
#Y Copyright (C) 2000, Frank Lübeck and Max Neunhöffer,
88
#Y Lehrstuhl D für Mathematik, RWTH Aachen
@@ -21,4 +21,5 @@ ReadPackage("GAPDoc", "lib/BibXMLextTools.gi");
2121
ReadPackage("GAPDoc", "lib/GAPDoc2LaTeX.gi");
2222
ReadPackage("GAPDoc", "lib/GAPDoc2Text.gi");
2323
ReadPackage("GAPDoc", "lib/GAPDoc2HTML.gi");
24+
ReadPackage("GAPDoc", "lib/Examples.gi");
2425

0 commit comments

Comments
 (0)