File: book2txt.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 (113 lines) | stat: -rw-r--r-- 2,702 bytes parent folder | download | duplicates (7)
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
/* convert Yacas docs back to plain text format */

Text(x) := WriteString(Nl() : x : Nl());
Book(x) := WriteString(Nl() : "				" : x : Nl());
Chapter(x) := WriteString(Nl() : "			" : x : Nl());
Section(x) := WriteString(Nl() : "		" : x : Nl());
SubSection(x) := WriteString(Nl() : "	    " : x : Nl());

Itemize(x) := Nl() : LineByLineMarkup(x, "*	") : Nl();
Enumerate(x) := Nl() : LineByLineMarkup(x, "*	0. ") : Nl();

/* Insert padding after each newline in text, except first newline and last newline */
LineByLineMarkup(x, padding) := [
	Local(i, result);
	i:=1;
	If (x[1]=Nl(), i:=2);	/* we always start with padding even if we don't have initial newline */
	For(result:=Nl() : padding, i<=Length(x), i:=i+1) [
		result := result : x[i];
		If(x[i]=Nl() And i != Length(x), result := result : padding);
	];
	Nl() : result : Nl();
];

Item(x) := StripNl(x) : Nl(); /* markup to be inserted later */

ResetEnvs() := [
	inEnum := False;
	inItemize := False;
];

HtmlNewParagraph() := [
	ResetEnvs();
	Nl() : Nl();
];

HtmlCommand(x) := Nl() : LineByLineMarkup(x, "	") : Nl();

StripNl(x) := [ /* replace all newlines by spaces */
	Local(i, result);
	result := "";
	For(i:=1, i<=Length(x), i:=i+1)
		If(x[i] != Nl(), result := result : x[i], result := result : " ");
	result;
];

HtmlEmphasis(x) := "<i>" : StripNl(x) : "</i>";
HtmlTerm(x) := "{" : StripNl(x) : "}";
HtmlBreak() := Nl();

HtmlAnchor(string) := "
*A " : string : Nl();
Bodied("HtmlAnchor", 60000);
AddBody(string) := WriteString(string);
SeeAlso(list) := WriteString(
Nl() : "*SEE " : PrintList(list) : Nl() : Nl()
);

ChapterIntro(string) := WriteString("
*INTRO " : string : "

");

TopicalStrings := {
	{"Calling Sequence", "*CALL"},
	{"Calling sequence", "*CALL"},
	{"See Also", ""},
	{"See also", ""},
	{"Parameters", "*PARMS"},
	{"parameters", "*PARMS"},
	{"Description", "*DESC"},
	{"Descriptions", "*DESC"},
	{"Examples", "*E.G."},
	{"Example", "*E.G."},
};

Topical(string) := WriteString(
Nl() : If(Contains(AssocIndices(TopicalStrings), string),
	TopicalStrings[string], "*HEAD " : string)
: Nl()
);

Bodied("Item",1);
Bodied("Book",60000);
Bodied("Title",60000);
Bodied("Author",60000);
Bodied("Chapter",60000);
Bodied("Section",60000);
Bodied("SubSection",60000);
Bodied("Topical",60000);
Bodied("Text",60000);
Bodied("Blurb",60000);
Bodied("Itemize",2);
Bodied("Enumerate",2);
//Bodied("ChapterIntro", 60000);

IncludeFile(x) := WriteString(Nl() : "*INCLUDE " : x : Nl());

StandardLib() := WriteString("
*STD
");
BuiltIn() := WriteString("
*CORE
");

CmdDescription(cmd, desc) := WriteString("
*CMD " : cmd : " --- " : desc : Nl()
);

Gt() := "\\>";
Lt() := "\\<";

AddAnchor(string) := AddBody("
*AA " : string : Nl());