author | wenzelm |
Sun, 10 Dec 2017 14:29:14 +0100 | |
changeset 67173 | e746db6db903 |
parent 67145 | e77c5bfca9aa |
child 67175 | 4e5ba4b23731 |
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 |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
2 |
Author: Markus Wenzel, TU Muenchen |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
3 |
|
15801 | 4 |
LaTeX presentation elements -- based on outer lexical syntax. |
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 |
67145 | 9 |
val output_name: string -> string |
58716
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
10 |
val output_ascii: string -> string |
63935
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
11 |
val latex_control: Symbol.symbol |
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
12 |
val is_latex_control: Symbol.symbol -> bool |
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
13 |
val embed_raw: string -> string |
14924 | 14 |
val output_known_symbols: (string -> bool) * (string -> bool) -> |
15 |
Symbol.symbol list -> string |
|
11719 | 16 |
val output_symbols: Symbol.symbol list -> string |
67145 | 17 |
val output_syms: string -> string |
67173 | 18 |
val output_file: Position.T -> string |
19 |
val output_range: Position.T -> string |
|
20 |
val range_output: Position.T -> string -> string |
|
61455 | 21 |
val output_token: Token.T -> string |
17081 | 22 |
val begin_delim: string -> string |
23 |
val end_delim: string -> string |
|
24 |
val begin_tag: string -> string |
|
25 |
val end_tag: string -> string |
|
61462 | 26 |
val environment: string -> string -> string |
9707 | 27 |
val tex_trailer: string |
67173 | 28 |
val isabelle_theory: Position.T -> string -> string -> string |
14924 | 29 |
val symbol_source: (string -> bool) * (string -> bool) -> |
30 |
string -> Symbol.symbol list -> string |
|
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
31 |
val theory_entry: string -> string |
66021 | 32 |
val latexN: string |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
33 |
end; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
34 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
35 |
structure Latex: LATEX = |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
36 |
struct |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
37 |
|
67145 | 38 |
(* output name for LaTeX macros *) |
39 |
||
40 |
val output_name = |
|
41 |
translate_string |
|
42 |
(fn "_" => "UNDERSCORE" |
|
43 |
| "'" => "PRIME" |
|
44 |
| "0" => "ZERO" |
|
45 |
| "1" => "ONE" |
|
46 |
| "2" => "TWO" |
|
47 |
| "3" => "THREE" |
|
48 |
| "4" => "FOUR" |
|
49 |
| "5" => "FIVE" |
|
50 |
| "6" => "SIX" |
|
51 |
| "7" => "SEVEN" |
|
52 |
| "8" => "EIGHT" |
|
53 |
| "9" => "NINE" |
|
54 |
| s => s); |
|
55 |
||
56 |
fun enclose_name bg en = enclose bg en o output_name; |
|
57 |
||
58 |
||
61455 | 59 |
(* output verbatim ASCII *) |
58716
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
60 |
|
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
61 |
val output_ascii = |
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
62 |
translate_string |
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
63 |
(fn " " => "\\ " |
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
64 |
| "\t" => "\\ " |
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
65 |
| "\n" => "\\isanewline\n" |
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
66 |
| s => |
61578 | 67 |
if exists_string (fn s' => s = s') "\"#$%&',-<>\\^_`{}~" |
58716
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
68 |
then enclose "{\\char`\\" "}" s else s); |
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
69 |
|
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
55828
diff
changeset
|
70 |
|
61455 | 71 |
(* output symbols *) |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
72 |
|
63935
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
73 |
val latex_control = "\<^latex>"; |
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
74 |
fun is_latex_control s = s = latex_control; |
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
75 |
|
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
76 |
val embed_raw = prefix latex_control o cartouche; |
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
77 |
|
7900 | 78 |
local |
79 |
||
40402
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
80 |
val char_table = |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
81 |
Symtab.make |
63590
4854f7ee0987
proper latex rendering of abbrevs templates (e.g. src/HOL/Nonstandard_Analysis/HLim.thy);
wenzelm
parents:
61595
diff
changeset
|
82 |
[("\007", "{\\isacharbell}"), |
4854f7ee0987
proper latex rendering of abbrevs templates (e.g. src/HOL/Nonstandard_Analysis/HLim.thy);
wenzelm
parents:
61595
diff
changeset
|
83 |
("!", "{\\isacharbang}"), |
40402
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
84 |
("\"", "{\\isachardoublequote}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
85 |
("#", "{\\isacharhash}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
86 |
("$", "{\\isachardollar}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
87 |
("%", "{\\isacharpercent}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
88 |
("&", "{\\isacharampersand}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
89 |
("'", "{\\isacharprime}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
90 |
("(", "{\\isacharparenleft}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
91 |
(")", "{\\isacharparenright}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
92 |
("*", "{\\isacharasterisk}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
93 |
("+", "{\\isacharplus}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
94 |
(",", "{\\isacharcomma}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
95 |
("-", "{\\isacharminus}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
96 |
(".", "{\\isachardot}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
97 |
("/", "{\\isacharslash}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
98 |
(":", "{\\isacharcolon}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
99 |
(";", "{\\isacharsemicolon}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
100 |
("<", "{\\isacharless}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
101 |
("=", "{\\isacharequal}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
102 |
(">", "{\\isachargreater}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
103 |
("?", "{\\isacharquery}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
104 |
("@", "{\\isacharat}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
105 |
("[", "{\\isacharbrackleft}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
106 |
("\\", "{\\isacharbackslash}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
107 |
("]", "{\\isacharbrackright}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
108 |
("^", "{\\isacharcircum}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
109 |
("_", "{\\isacharunderscore}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
110 |
("`", "{\\isacharbackquote}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
111 |
("{", "{\\isacharbraceleft}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
112 |
("|", "{\\isacharbar}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
113 |
("}", "{\\isacharbraceright}"), |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
114 |
("~", "{\\isachartilde}")]; |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
115 |
|
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
116 |
fun output_chr " " = "\\ " |
43709
717e96cf9527
discontinued special treatment of hard tabulators;
wenzelm
parents:
43485
diff
changeset
|
117 |
| 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
|
118 |
| 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
|
119 |
| output_chr c = |
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
120 |
(case Symtab.lookup char_table c of |
49320
94bd2fb83d11
discontinued experiment with literal replacement text in PDF (cf. b646316f8b3c, 2ff10e613689);
wenzelm
parents:
48628
diff
changeset
|
121 |
SOME s => s |
40402
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
122 |
| 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
|
123 |
|
14924 | 124 |
val output_chrs = translate_string output_chr; |
125 |
||
126 |
fun output_known_sym (known_sym, known_ctrl) sym = |
|
14874 | 127 |
(case Symbol.decode sym of |
128 |
Symbol.Char s => output_chr s |
|
37533
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents:
36959
diff
changeset
|
129 |
| Symbol.UTF8 s => s |
67145 | 130 |
| Symbol.Sym s => if known_sym s then enclose_name "{\\isasym" "}" s else output_chrs sym |
131 |
| Symbol.Control s => if known_ctrl s then enclose_name "\\isactrl" " " s else output_chrs sym |
|
43485 | 132 |
| Symbol.Malformed s => error (Symbol.malformed_msg s) |
133 |
| Symbol.EOF => error "Bad EOF symbol"); |
|
7900 | 134 |
|
64526
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
135 |
val scan_latex_length = |
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
136 |
Scan.many1 (fn (s, _) => Symbol.not_eof s andalso not (is_latex_control s)) |
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
137 |
>> (Symbol.length o map Symbol_Pos.symbol) || |
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
138 |
Scan.one (is_latex_control o Symbol_Pos.symbol) -- |
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
139 |
Scan.option (Scan.permissive Symbol_Pos.scan_cartouche "") >> K 0; |
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
140 |
|
63935
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
141 |
fun scan_latex known = |
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
142 |
Scan.one (is_latex_control o Symbol_Pos.symbol) |-- |
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
143 |
Symbol_Pos.scan_cartouche_content "Embedded LaTeX: " >> (implode o map Symbol_Pos.symbol) || |
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
144 |
Scan.one (Symbol.not_eof o Symbol_Pos.symbol) >> (output_known_sym known o Symbol_Pos.symbol); |
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
145 |
|
64526
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
146 |
fun read scan syms = |
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
147 |
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
|
148 |
|
7900 | 149 |
in |
150 |
||
64526
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
151 |
fun length_symbols syms = |
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
152 |
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
|
153 |
|
63935
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
154 |
fun output_known_symbols known syms = |
64526
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
155 |
if exists is_latex_control syms then |
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
156 |
(case read (scan_latex known) syms of |
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
157 |
SOME ss => implode ss |
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
158 |
| NONE => error ("Malformed embedded LaTeX: " ^ quote (Symbol.beginning 10 syms))) |
63935
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
159 |
else implode (map (output_known_sym known) syms); |
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
160 |
|
14924 | 161 |
val output_symbols = output_known_symbols (K true, K true); |
8192 | 162 |
val output_syms = output_symbols o Symbol.explode; |
7900 | 163 |
|
27874
f0364f1c0ecf
antiquotes: proper SymbolPos decoding, adapted Antiquote.read/Antiq;
wenzelm
parents:
27809
diff
changeset
|
164 |
val output_syms_antiq = |
30589 | 165 |
(fn Antiquote.Text ss => output_symbols (map Symbol_Pos.symbol ss) |
61473
34d1913f0b20
clarified control antiquotations: decode control symbol to get name;
wenzelm
parents:
61471
diff
changeset
|
166 |
| Antiquote.Control {name = (name, _), body, ...} => |
34d1913f0b20
clarified control antiquotations: decode control symbol to get name;
wenzelm
parents:
61471
diff
changeset
|
167 |
"\\isaantiqcontrol{" ^ output_symbols (Symbol.explode name) ^ "}" ^ |
34d1913f0b20
clarified control antiquotations: decode control symbol to get name;
wenzelm
parents:
61471
diff
changeset
|
168 |
output_symbols (map Symbol_Pos.symbol body) |
34d1913f0b20
clarified control antiquotations: decode control symbol to get name;
wenzelm
parents:
61471
diff
changeset
|
169 |
| Antiquote.Antiq {body, ...} => |
40402
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents:
39666
diff
changeset
|
170 |
enclose "%\n\\isaantiq\n" "{}%\n\\endisaantiq\n" |
61473
34d1913f0b20
clarified control antiquotations: decode control symbol to get name;
wenzelm
parents:
61471
diff
changeset
|
171 |
(output_symbols (map Symbol_Pos.symbol body))); |
22648
8c6b4f7548e3
output_basic: added isaantiq markup (only inside verbatim tokens);
wenzelm
parents:
19265
diff
changeset
|
172 |
|
7900 | 173 |
end; |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
174 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
175 |
|
67173 | 176 |
(* output properties *) |
177 |
||
178 |
fun output_prop (a, b) = enclose "%:%" "%:%\n" (a ^ "=" ^ b); |
|
179 |
||
180 |
fun output_file pos = |
|
181 |
(case Position.file_of pos of |
|
182 |
NONE => "" |
|
183 |
| SOME file => output_prop (Markup.fileN, file)); |
|
184 |
||
185 |
fun output_range pos = |
|
186 |
(case (Position.offset_of pos, Position.end_offset_of pos) of |
|
187 |
(NONE, _) => "" |
|
188 |
| (SOME i, NONE) => output_prop (Markup.rangeN, Value.print_int i) |
|
189 |
| (SOME i, SOME j) => output_prop (Markup.rangeN, Value.print_int i ^ ":" ^ Value.print_int j)); |
|
190 |
||
191 |
fun range_output _ "" = "" |
|
192 |
| range_output pos output = |
|
193 |
(case output_range pos of |
|
194 |
"" => output |
|
195 |
| range => split_lines output |> map (fn "" => "%\n" | line => line ^ range) |> implode); |
|
196 |
||
197 |
||
61455 | 198 |
(* output token *) |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
199 |
|
61455 | 200 |
fun output_token tok = |
67173 | 201 |
let |
202 |
val s = Token.content_of tok; |
|
203 |
val output = |
|
204 |
if Token.is_kind Token.Comment tok then "" |
|
205 |
else if Token.is_command tok then |
|
206 |
"\\isacommand{" ^ output_syms s ^ "}" |
|
207 |
else if Token.is_kind Token.Keyword tok andalso Symbol.is_ascii_identifier s then |
|
208 |
"\\isakeyword{" ^ output_syms s ^ "}" |
|
209 |
else if Token.is_kind Token.String tok then |
|
210 |
enclose "{\\isachardoublequoteopen}" "{\\isachardoublequoteclose}" (output_syms s) |
|
211 |
else if Token.is_kind Token.Alt_String tok then |
|
212 |
enclose "{\\isacharbackquoteopen}" "{\\isacharbackquoteclose}" (output_syms s) |
|
213 |
else if Token.is_kind Token.Verbatim tok then |
|
214 |
let |
|
215 |
val ants = Antiquote.read (Token.input_of tok); |
|
216 |
val out = implode (map output_syms_antiq ants); |
|
217 |
in enclose "{\\isacharverbatimopen}" "{\\isacharverbatimclose}" out end |
|
218 |
else if Token.is_kind Token.Cartouche tok then |
|
219 |
enclose "{\\isacartoucheopen}" "{\\isacartoucheclose}" (output_syms s) |
|
220 |
else output_syms s; |
|
221 |
in range_output (Token.pos_of tok) output end |
|
222 |
handle ERROR msg => error (msg ^ Position.here (Token.pos_of tok)); |
|
17081 | 223 |
|
61404 | 224 |
|
61455 | 225 |
(* tags *) |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
226 |
|
67145 | 227 |
val begin_delim = enclose_name "%\n\\isadelim" "\n"; |
228 |
val end_delim = enclose_name "%\n\\endisadelim" "\n"; |
|
229 |
val begin_tag = enclose_name "%\n\\isatag" "\n"; |
|
230 |
fun end_tag tg = enclose_name "%\n\\endisatag" "\n" tg ^ enclose "{\\isafold" "}%\n" tg; |
|
11860 | 231 |
|
232 |
||
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
233 |
(* theory presentation *) |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
234 |
|
61462 | 235 |
fun environment name = |
67145 | 236 |
enclose ("%\n\\begin{" ^ output_name name ^ "}%\n") ("%\n\\end{" ^ output_name name ^ "}"); |
61462 | 237 |
|
9707 | 238 |
val tex_trailer = |
239 |
"%%% Local Variables:\n\ |
|
9135 | 240 |
\%%% mode: latex\n\ |
241 |
\%%% TeX-master: \"root\"\n\ |
|
9144 | 242 |
\%%% End:\n"; |
8192 | 243 |
|
67173 | 244 |
fun isabelle_theory pos name txt = |
245 |
output_file pos ^ |
|
246 |
"\\begin{isabellebody}%\n\ |
|
58870
e2c0d8ef29cb
more flexibile \setisabellecontext, independently of header;
wenzelm
parents:
58861
diff
changeset
|
247 |
\\\setisabellecontext{" ^ output_syms name ^ "}%\n" ^ txt ^ |
61462 | 248 |
"%\n\\end{isabellebody}%\n" ^ tex_trailer; |
9707 | 249 |
|
58870
e2c0d8ef29cb
more flexibile \setisabellecontext, independently of header;
wenzelm
parents:
58861
diff
changeset
|
250 |
fun symbol_source known name syms = |
67173 | 251 |
isabelle_theory Position.none name |
58870
e2c0d8ef29cb
more flexibile \setisabellecontext, independently of header;
wenzelm
parents:
58861
diff
changeset
|
252 |
("\\isamarkupfile{" ^ output_known_symbols known (Symbol.explode name) ^ "}%\n" ^ |
e2c0d8ef29cb
more flexibile \setisabellecontext, independently of header;
wenzelm
parents:
58861
diff
changeset
|
253 |
output_known_symbols known syms); |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
254 |
|
9038
63d20536971f
session.tex: nsert blank lines in order to guarantee new paragraphs
wenzelm
parents:
8965
diff
changeset
|
255 |
fun theory_entry name = "\\input{" ^ name ^ ".tex}\n\n"; |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
256 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
257 |
|
8460 | 258 |
(* print mode *) |
259 |
||
8965 | 260 |
val latexN = "latex"; |
261 |
||
8460 | 262 |
fun latex_output str = |
263 |
let val syms = Symbol.explode str |
|
64526
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
wenzelm
parents:
63936
diff
changeset
|
264 |
in (output_symbols syms, length_symbols syms) end; |
19265 | 265 |
|
23621 | 266 |
fun latex_markup (s, _) = |
59123
e68e44836d04
imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents:
59081
diff
changeset
|
267 |
if s = Markup.commandN orelse s = Markup.keyword1N orelse s = Markup.keyword3N |
e68e44836d04
imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents:
59081
diff
changeset
|
268 |
then ("\\isacommand{", "}") |
e68e44836d04
imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents:
59081
diff
changeset
|
269 |
else if s = Markup.keyword2N |
e68e44836d04
imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents:
59081
diff
changeset
|
270 |
then ("\\isakeyword{", "}") |
29325 | 271 |
else Markup.no_output; |
10955 | 272 |
|
23621 | 273 |
fun latex_indent "" _ = "" |
274 |
| latex_indent s _ = enclose "\\isaindent{" "}" s; |
|
275 |
||
63935
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
wenzelm
parents:
63590
diff
changeset
|
276 |
val _ = Output.add_mode latexN latex_output embed_raw; |
23703 | 277 |
val _ = Markup.add_mode latexN latex_markup; |
278 |
val _ = Pretty.add_mode latexN latex_indent; |
|
8460 | 279 |
|
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
280 |
end; |