File: book2ys.ys

package info (click to toggle)
yacas 1.3.6-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 7,176 kB
  • ctags: 3,520
  • sloc: cpp: 13,960; java: 12,602; sh: 11,401; makefile: 552; perl: 517; ansic: 381
file content (139 lines) | stat: -rw-r--r-- 3,339 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* book2ys - extract Yacas code from Yacas docs (by Serge Winitzki)
	version 0.2
	0.1 Extract all tab-indented lines (HtmlCommand), except for the ones that start with In> or Out> -- those are omitted
	0.2 The variable StripComments controls whether any comments are printed.
	The function ysFileName specifies an alternative output file name for code extraction.
*/

curFileName := "-";	// default file name
outputSoFar := "";	// accumulated output in case we aren't printing to the default file 

// function to change the current output file name
ysFileName(newFileName) :=
If(
	newFileName != curFileName,
	[
		// the file has changed, let's write out the old one
		If(
			curFileName != "-",	// otherwise it has already been written out
			ToFile(curFileName)WriteString(outputSoFar)
		);
		outputSoFar := "";
		curFileName := newFileName;
	]
);

/// Write either to default output or to an alternative file
10 # WriteOut("") <-- True;
20 # WriteOut(x_IsString)_(curFileName = "-") <-- WriteString(x);
30 # WriteOut(x_IsString) <-- 
[	// accumulate output here, since we can't append to files
	outputSoFar := ConcatStrings(outputSoFar, x);
];


Chapter(x) := WriteOut(
"// \\chapter{" : x : "}
");
Section(x) := WriteOut(
"// \\section{" : x : "}
");
SubSection(x) := WriteOut(
"// \\subsection*{" : x : "}
");

Enumerate(x) := x;
Itemize(x) := x;

HtmlNewParagraph() := "

";

// check whether the code sample starts with strings "In" or "Out", possibly after some newlines
is'code'sample(x) :=
[
	Local(i);
	For(i:=1, i<=Length(x)-4 And StringMid(i, 1, x) = Nl(), i++) [];
	StringMid(i, 3, x) = "In>" Or StringMid(i, 4, x) = "Out>";
];

10 # make'comments(_x)_StripComments <-- "";
20 # make'comments(_x) <--
[
	Local(i);
	For(i:=1, i<=Length(x), i++)
		If(
			StringMid(i, 1, x) = Nl(),
			x:= ConcatStrings(StringMid(1, i, x), "//", StringMid(i+1,Length(x)-i-1, x))
		);
	x;
];

HtmlCommand(x) :=
	WriteOut(
		If(
			Not is'code'sample(x), 
			x,
			make'comments(x)
		)
	);

HtmlEmphasis(x) := x;

/* decide whether to use "verb" or "texttt" based on whether the string contains any of the special characters #, _, \, &, {, }, ~ */

HtmlTerm(x) := x;

HtmlTermHeading(x) := x;

HtmlBreak() := "
";

Bodied("Item",2);	/* competes with prec. 7 of ":" */
Bodied("Book",60000);
Bodied("Title",60000);
Bodied("Author",60000);
Bodied("Chapter",60000);
Bodied("Section",60000);
Bodied("SubSection",60000);
Bodied("Text",60000);
Bodied("Blurb",60000);
Bodied("DocumentationComment",60000);
Bodied("Itemize",2);
Bodied("Enumerate",2);

IncludeFile(x) := Load(x);

HtmlLink(text, url, param1, param2) := "";

Text() text := True;

RuleBase("TeXMath", {x});
RuleBase("TeXMathD", {x});
RuleBase("TeXMathD", {x,y});
HoldArg("TeXMath", x);
HoldArg("TeXMathD", x);
/* use <-- since := would redefine everything */
TeXMath(_x) <-- x;
TeXMathD(_x) <-- x;
// special form: punctuation at the end of a displayed equation
TeXMathD(_x, _string) <-- x;

/* stuff for refman */

Bodied("ChapterIntro", 60000);

AddBody(string) := WriteOut(string);

// make SeeAlso print "See also" and do not do the Topical thing

AddAnchor(string) := "";
HtmlAnchor(string) := "";

Bodied("HtmlAnchor", 60000);
Bodied("Topical",60000);
Blurb(string) := [ True ];	// Blurb() does nothing in TeX mode
Bodied("Blurb",60000);
// special escapes
Gt() := ">";
Lt() := "<";