author | wenzelm |
Fri, 05 Aug 2022 14:44:47 +0200 | |
changeset 75764 | 07e097f60b85 |
parent 74884 | 229d7ea628c2 |
child 76371 | 1ac2416e8432 |
permissions | -rw-r--r-- |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/Thy/latex.ML |
73754 | 2 |
Author: Makarius |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
3 |
|
73754 | 4 |
LaTeX output of theory sources. |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
5 |
*) |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
6 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
7 |
signature LATEX = |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
8 |
sig |
73780
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73779
diff
changeset
|
9 |
type text = XML.body |
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67189
diff
changeset
|
10 |
val text: string * Position.T -> text |
73780
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73779
diff
changeset
|
11 |
val string: string -> text |
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73779
diff
changeset
|
12 |
val block: text -> XML.tree |
74784
d2522bb4db1b
symbolic latex_output via XML, interpreted in Isabelle/Scala;
wenzelm
parents:
74781
diff
changeset
|
13 |
val output: text -> text |
74790 | 14 |
val macro0: string -> text |
15 |
val macro: string -> text -> text |
|
16 |
val environment: string -> text -> text |
|
58716
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
17 |
val output_ascii: string -> string |
71899 | 18 |
val output_ascii_breakable: string -> string -> string |
11719 | 19 |
val output_symbols: Symbol.symbol list -> string |
67145 | 20 |
val output_syms: string -> string |
67461 | 21 |
val symbols: Symbol_Pos.T list -> text |
22 |
val symbols_output: Symbol_Pos.T list -> text |
|
73780
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73779
diff
changeset
|
23 |
val isabelle_body: string -> text -> text |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
24 |
val theory_entry: string -> string |
73754 | 25 |
type index_item = {text: text, like: string} |
26 |
type index_entry = {items: index_item list, def: bool} |
|
27 |
val index_entry: index_entry -> text |
|
73763
eccc4a13216d
clarified index antiquotation for ML: more ambitious type-setting, more accurate syntax;
wenzelm
parents:
73754
diff
changeset
|
28 |
val index_variants: (binding -> bool option -> 'a -> 'a) -> binding -> 'a -> 'a |
66021 | 29 |
val latexN: string |
69346
3c29edccf739
expose latex mode operations, to facilitate adhoc changes to it;
wenzelm
parents:
67462
diff
changeset
|
30 |
val latex_markup: string * Properties.T -> Markup.output |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
31 |
end; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
32 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
33 |
structure Latex: LATEX = |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
34 |
struct |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
35 |
|
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67189
diff
changeset
|
36 |
(* text with positions *) |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67189
diff
changeset
|
37 |
|
73780
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73779
diff
changeset
|
38 |
type text = XML.body; |
73754 | 39 |
|
74779 | 40 |
fun text (s, pos) = |
41 |
if s = "" then [] |
|
42 |
else if pos = Position.none then [XML.Text s] |
|
43 |
else [XML.Elem (Position.markup pos Markup.document_latex, [XML.Text s])]; |
|
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67189
diff
changeset
|
44 |
|
73780
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73779
diff
changeset
|
45 |
fun string s = text (s, Position.none); |
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73779
diff
changeset
|
46 |
|
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73779
diff
changeset
|
47 |
fun block body = XML.Elem (Markup.document_latex, body); |
67195 | 48 |
|
74784
d2522bb4db1b
symbolic latex_output via XML, interpreted in Isabelle/Scala;
wenzelm
parents:
74781
diff
changeset
|
49 |
fun output body = [XML.Elem (Markup.latex_output, body)]; |
d2522bb4db1b
symbolic latex_output via XML, interpreted in Isabelle/Scala;
wenzelm
parents:
74781
diff
changeset
|
50 |
|
74790 | 51 |
fun macro0 name = [XML.Elem (Markup.latex_macro0 name, [])]; |
52 |
fun macro name body = [XML.Elem (Markup.latex_macro name, body)]; |
|
53 |
fun environment name body = [XML.Elem (Markup.latex_environment name, body)]; |
|
54 |
||
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67189
diff
changeset
|
55 |
|
67145 | 56 |
(* output name for LaTeX macros *) |
57 |
||
58 |
val output_name = |
|
59 |
translate_string |
|
60 |
(fn "_" => "UNDERSCORE" |
|
61 |
| "'" => "PRIME" |
|
62 |
| "0" => "ZERO" |
|
63 |
| "1" => "ONE" |
|
64 |
| "2" => "TWO" |
|
65 |
| "3" => "THREE" |
|
66 |
| "4" => "FOUR" |
|
67 |
| "5" => "FIVE" |
|
68 |
| "6" => "SIX" |
|
69 |
| "7" => "SEVEN" |
|
70 |
| "8" => "EIGHT" |
|
71 |
| "9" => "NINE" |
|
72 |
| s => s); |
|
73 |
||
74 |
fun enclose_name bg en = enclose bg en o output_name; |
|
75 |
||
76 |
||
61455 | 77 |
(* output verbatim ASCII *) |
58716
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
78 |
|
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
79 |
val output_ascii = |
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
80 |
translate_string |
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
81 |
(fn " " => "\\ " |
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
82 |
| "\t" => "\\ " |
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
83 |
| "\n" => "\\isanewline\n" |
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
84 |
| s => |
72315
8162ca81ea8a
suppress ligatures more robustly, notably for lualatex;
wenzelm
parents:
71899
diff
changeset
|
85 |
s |
8162ca81ea8a
suppress ligatures more robustly, notably for lualatex;
wenzelm
parents:
71899
diff
changeset
|
86 |
|> exists_string (fn s' => s = s') "\"#$%&',-<>\\^_`{}~" ? enclose "{\\char`\\" "}" |
8162ca81ea8a
suppress ligatures more robustly, notably for lualatex;
wenzelm
parents:
71899
diff
changeset
|
87 |
|> suffix "{\\kern0pt}"); |
58716
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
88 |
|
71899 | 89 |
fun output_ascii_breakable sep = |
90 |
space_explode sep |
|
91 |
#> map output_ascii |
|
92 |
#> space_implode (output_ascii sep ^ "\\discretionary{}{}{}"); |
|
93 |
||
58716
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
94 |
|
61455 | 95 |
(* output symbols *) |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
96 |
|
7900 | 97 |
local |
98 |
||
40402
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
99 |
val char_table = |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
100 |
Symtab.make |
63590
4854f7ee0987
proper latex rendering of abbrevs templates (e.g. src/HOL/Nonstandard_Analysis/HLim.thy);
wenzelm
parents:
61595
diff
changeset
|
101 |
[("\007", "{\\isacharbell}"), |
4854f7ee0987
proper latex rendering of abbrevs templates (e.g. src/HOL/Nonstandard_Analysis/HLim.thy);
wenzelm
parents:
61595
diff
changeset
|
102 |
("!", "{\\isacharbang}"), |
40402
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
103 |
("\"", "{\\isachardoublequote}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
104 |
("#", "{\\isacharhash}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
105 |
("$", "{\\isachardollar}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
106 |
("%", "{\\isacharpercent}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
107 |
("&", "{\\isacharampersand}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
108 |
("'", "{\\isacharprime}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
109 |
("(", "{\\isacharparenleft}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
110 |
(")", "{\\isacharparenright}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
111 |
("*", "{\\isacharasterisk}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
112 |
("+", "{\\isacharplus}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
113 |
(",", "{\\isacharcomma}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
114 |
("-", "{\\isacharminus}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
115 |
(".", "{\\isachardot}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
116 |
("/", "{\\isacharslash}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
117 |
(":", "{\\isacharcolon}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
118 |
(";", "{\\isacharsemicolon}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
119 |
("<", "{\\isacharless}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
120 |
("=", "{\\isacharequal}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
121 |
(">", "{\\isachargreater}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
122 |
("?", "{\\isacharquery}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
123 |
("@", "{\\isacharat}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
124 |
("[", "{\\isacharbrackleft}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
125 |
("\\", "{\\isacharbackslash}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
126 |
("]", "{\\isacharbrackright}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
127 |
("^", "{\\isacharcircum}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
128 |
("_", "{\\isacharunderscore}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
129 |
("`", "{\\isacharbackquote}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
130 |
("{", "{\\isacharbraceleft}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
131 |
("|", "{\\isacharbar}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
132 |
("}", "{\\isacharbraceright}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
133 |
("~", "{\\isachartilde}")]; |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
134 |
|
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
135 |
fun output_chr " " = "\\ " |
43709
717e96cf9527
discontinued special treatment of hard tabulators;
wenzelm
parents:
43485
diff
changeset
|
136 |
| output_chr "\t" = "\\ " |
40402
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
137 |
| output_chr "\n" = "\\isanewline\n" |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
138 |
| output_chr c = |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
139 |
(case Symtab.lookup char_table c of |
72315
8162ca81ea8a
suppress ligatures more robustly, notably for lualatex;
wenzelm
parents:
71899
diff
changeset
|
140 |
SOME s => s ^ "{\\kern0pt}" |
40402
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
141 |
| NONE => if Symbol.is_ascii_digit c then enclose "{\\isadigit{" "}}" c else c); |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
142 |
|
67263 | 143 |
fun output_sym sym = |
14874 | 144 |
(case Symbol.decode sym of |
145 |
Symbol.Char s => output_chr s |
|
37533
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents:
36959
diff
changeset
|
146 |
| Symbol.UTF8 s => s |
67263 | 147 |
| Symbol.Sym s => enclose_name "{\\isasym" "}" s |
148 |
| Symbol.Control s => enclose_name "\\isactrl" " " s |
|
43485 | 149 |
| Symbol.Malformed s => error (Symbol.malformed_msg s) |
150 |
| Symbol.EOF => error "Bad EOF symbol"); |
|
7900 | 151 |
|
67428 | 152 |
open Basic_Symbol_Pos; |
153 |
||
64526
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
154 |
val scan_latex_length = |
67428 | 155 |
Scan.many1 (fn (s, _) => s <> Symbol.latex andalso Symbol.not_eof s) |
64526
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
156 |
>> (Symbol.length o map Symbol_Pos.symbol) || |
67428 | 157 |
$$ Symbol.latex -- Scan.option (Scan.permissive Symbol_Pos.scan_cartouche "") >> K 0; |
64526
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
158 |
|
67263 | 159 |
val scan_latex = |
67428 | 160 |
$$ Symbol.latex |-- Symbol_Pos.scan_cartouche_content "Embedded LaTeX: " |
161 |
>> (implode o map Symbol_Pos.symbol) || |
|
67263 | 162 |
Scan.one (Symbol.not_eof o Symbol_Pos.symbol) >> (output_sym o Symbol_Pos.symbol); |
63935
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
163 |
|
64526
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
164 |
fun read scan syms = |
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
165 |
Scan.read Symbol_Pos.stopper (Scan.repeat scan) (map (rpair Position.none) syms); |
63935
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
166 |
|
7900 | 167 |
in |
168 |
||
64526
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
169 |
fun length_symbols syms = |
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
170 |
fold Integer.add (these (read scan_latex_length syms)) 0; |
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
171 |
|
67263 | 172 |
fun output_symbols syms = |
67428 | 173 |
if member (op =) syms Symbol.latex then |
67263 | 174 |
(case read scan_latex syms of |
64526
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
175 |
SOME ss => implode ss |
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
176 |
| NONE => error ("Malformed embedded LaTeX: " ^ quote (Symbol.beginning 10 syms))) |
67263 | 177 |
else implode (map output_sym syms); |
63935
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
178 |
|
8192 | 179 |
val output_syms = output_symbols o Symbol.explode; |
7900 | 180 |
|
181 |
end; |
|
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
182 |
|
67461 | 183 |
fun symbols syms = text (Symbol_Pos.content syms, #1 (Symbol_Pos.range syms)); |
184 |
fun symbols_output syms = |
|
185 |
text (output_symbols (map Symbol_Pos.symbol syms), #1 (Symbol_Pos.range syms)); |
|
186 |
||
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
187 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
188 |
(* theory presentation *) |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
189 |
|
67263 | 190 |
fun isabelle_body name = |
74881 | 191 |
XML.enclose |
67263 | 192 |
("%\n\\begin{isabellebody}%\n\\setisabellecontext{" ^ output_syms name ^ "}%\n") |
193 |
"%\n\\end{isabellebody}%\n"; |
|
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
194 |
|
9038
63d20536971f
session.tex: nsert blank lines in order to guarantee new paragraphs
wenzelm
parents:
8965
diff
changeset
|
195 |
fun theory_entry name = "\\input{" ^ name ^ ".tex}\n\n"; |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
196 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
197 |
|
73754 | 198 |
(* index entries *) |
199 |
||
200 |
type index_item = {text: text, like: string}; |
|
201 |
type index_entry = {items: index_item list, def: bool}; |
|
202 |
||
203 |
fun index_item (item: index_item) = |
|
74786 | 204 |
XML.wrap_elem ((Markup.latex_index_item, #text item), XML.string (#like item)); |
73754 | 205 |
|
206 |
fun index_entry (entry: index_entry) = |
|
74786 | 207 |
[XML.Elem (Markup.latex_index_entry (if #def entry then "isaindexdef" else "isaindexref"), |
208 |
map index_item (#items entry))]; |
|
73754 | 209 |
|
73763
eccc4a13216d
clarified index antiquotation for ML: more ambitious type-setting, more accurate syntax;
wenzelm
parents:
73754
diff
changeset
|
210 |
fun index_binding NONE = I |
eccc4a13216d
clarified index antiquotation for ML: more ambitious type-setting, more accurate syntax;
wenzelm
parents:
73754
diff
changeset
|
211 |
| index_binding (SOME def) = Binding.map_name (suffix (if def then "_def" else "_ref")); |
eccc4a13216d
clarified index antiquotation for ML: more ambitious type-setting, more accurate syntax;
wenzelm
parents:
73754
diff
changeset
|
212 |
|
eccc4a13216d
clarified index antiquotation for ML: more ambitious type-setting, more accurate syntax;
wenzelm
parents:
73754
diff
changeset
|
213 |
fun index_variants setup binding = |
eccc4a13216d
clarified index antiquotation for ML: more ambitious type-setting, more accurate syntax;
wenzelm
parents:
73754
diff
changeset
|
214 |
fold (fn index => setup (index_binding index binding) index) [NONE, SOME true, SOME false]; |
eccc4a13216d
clarified index antiquotation for ML: more ambitious type-setting, more accurate syntax;
wenzelm
parents:
73754
diff
changeset
|
215 |
|
eccc4a13216d
clarified index antiquotation for ML: more ambitious type-setting, more accurate syntax;
wenzelm
parents:
73754
diff
changeset
|
216 |
|
8460 | 217 |
(* print mode *) |
218 |
||
8965 | 219 |
val latexN = "latex"; |
220 |
||
74884
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
221 |
local |
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
222 |
|
8460 | 223 |
fun latex_output str = |
224 |
let val syms = Symbol.explode str |
|
64526
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
225 |
in (output_symbols syms, length_symbols syms) end; |
19265 | 226 |
|
74884
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
227 |
val command_markup = YXML.output_markup (Markup.latex_macro "isacommand"); |
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
228 |
val keyword_markup = YXML.output_markup (Markup.latex_macro "isakeyword"); |
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
229 |
val indent_markup = YXML.output_markup (Markup.latex_macro "isaindent"); |
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
230 |
|
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
231 |
in |
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
232 |
|
69346
3c29edccf739
expose latex mode operations, to facilitate adhoc changes to it;
wenzelm
parents:
67462
diff
changeset
|
233 |
fun latex_markup (s, _: Properties.T) = |
74884
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
234 |
if member (op =) [Markup.commandN, Markup.keyword1N, Markup.keyword3N] s then command_markup |
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
235 |
else if s = Markup.keyword2N then keyword_markup |
29325 | 236 |
else Markup.no_output; |
10955 | 237 |
|
67428 | 238 |
val _ = Output.add_mode latexN latex_output (prefix Symbol.latex o cartouche); |
23703 | 239 |
val _ = Markup.add_mode latexN latex_markup; |
74884
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
240 |
|
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
241 |
val _ = Pretty.add_mode latexN |
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
242 |
(fn s => fn _ => if s = "" then s else uncurry enclose indent_markup s); |
8460 | 243 |
|
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
244 |
end; |
74884
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
245 |
|
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
wenzelm
parents:
74883
diff
changeset
|
246 |
end; |