| author | wenzelm | 
| Sat, 11 Jan 2025 21:58:47 +0100 | |
| changeset 81766 | ebf113cd6d2c | 
| parent 81704 | 9253dadbd4ac | 
| permissions | -rw-r--r-- | 
| 79503 | 1 | (* Title: Pure/General/latex.ML | 
| 73754 | 2 | Author: Makarius | 
| 7726 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 3 | |
| 79503 | 4 | Support for LaTeX. | 
| 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: 
73779diff
changeset | 9 | type text = XML.body | 
| 67194 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 wenzelm parents: 
67189diff
changeset | 10 | val text: string * Position.T -> text | 
| 73780 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 wenzelm parents: 
73779diff
changeset | 11 | val string: string -> text | 
| 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 wenzelm parents: 
73779diff
changeset | 12 | val block: text -> XML.tree | 
| 74784 
d2522bb4db1b
symbolic latex_output via XML, interpreted in Isabelle/Scala;
 wenzelm parents: 
74781diff
changeset | 13 | val output: text -> text | 
| 74790 | 14 | val macro0: string -> text | 
| 15 | val macro: string -> text -> text | |
| 16 | val environment: string -> text -> text | |
| 76371 
1ac2416e8432
tuned signature (again, amending f32ac01aef5e), e.g. relevant for Isabelle/DOF;
 wenzelm parents: 
74884diff
changeset | 17 | val output_name: string -> string | 
| 58716 
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
 wenzelm parents: 
55828diff
changeset | 18 | val output_ascii: string -> string | 
| 71899 | 19 | val output_ascii_breakable: string -> string -> string | 
| 11719 | 20 | val output_symbols: Symbol.symbol list -> string | 
| 67145 | 21 | val output_syms: string -> string | 
| 67461 | 22 | val symbols: Symbol_Pos.T list -> text | 
| 23 | val symbols_output: Symbol_Pos.T list -> text | |
| 73780 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 wenzelm parents: 
73779diff
changeset | 24 | val isabelle_body: string -> text -> text | 
| 7726 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 25 | val theory_entry: string -> string | 
| 76956 
e47fb5cfef41
clarified Latex markup: optional cite "location" consists of nested document text;
 wenzelm parents: 
76955diff
changeset | 26 |   val cite: {kind: string, citations: (string * Position.T) list, location: text} -> text
 | 
| 73754 | 27 |   type index_item = {text: text, like: string}
 | 
| 28 |   type index_entry = {items: index_item list, def: bool}
 | |
| 29 | val index_entry: index_entry -> text | |
| 73763 
eccc4a13216d
clarified index antiquotation for ML: more ambitious type-setting, more accurate syntax;
 wenzelm parents: 
73754diff
changeset | 30 | val index_variants: (binding -> bool option -> 'a -> 'a) -> binding -> 'a -> 'a | 
| 80846 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 31 | val output_: string -> Output.output | 
| 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 32 | val output_width: string -> Output.output * int | 
| 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 33 | val escape: Output.output -> string | 
| 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 34 | val output_ops: int option -> Pretty.output_ops | 
| 7726 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 35 | end; | 
| 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 36 | |
| 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 37 | structure Latex: LATEX = | 
| 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 38 | struct | 
| 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 39 | |
| 67194 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 wenzelm parents: 
67189diff
changeset | 40 | (* text with positions *) | 
| 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 wenzelm parents: 
67189diff
changeset | 41 | |
| 73780 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 wenzelm parents: 
73779diff
changeset | 42 | type text = XML.body; | 
| 73754 | 43 | |
| 74779 | 44 | fun text (s, pos) = | 
| 45 | if s = "" then [] | |
| 46 | else if pos = Position.none then [XML.Text s] | |
| 80875 | 47 | else [XML.Elem (Position.markup_properties pos Markup.document_latex, [XML.Text s])]; | 
| 67194 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 wenzelm parents: 
67189diff
changeset | 48 | |
| 73780 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 wenzelm parents: 
73779diff
changeset | 49 | fun string s = text (s, Position.none); | 
| 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 wenzelm parents: 
73779diff
changeset | 50 | |
| 
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
 wenzelm parents: 
73779diff
changeset | 51 | fun block body = XML.Elem (Markup.document_latex, body); | 
| 67195 | 52 | |
| 74784 
d2522bb4db1b
symbolic latex_output via XML, interpreted in Isabelle/Scala;
 wenzelm parents: 
74781diff
changeset | 53 | fun output body = [XML.Elem (Markup.latex_output, body)]; | 
| 
d2522bb4db1b
symbolic latex_output via XML, interpreted in Isabelle/Scala;
 wenzelm parents: 
74781diff
changeset | 54 | |
| 74790 | 55 | fun macro0 name = [XML.Elem (Markup.latex_macro0 name, [])]; | 
| 56 | fun macro name body = [XML.Elem (Markup.latex_macro name, body)]; | |
| 57 | fun environment name body = [XML.Elem (Markup.latex_environment name, body)]; | |
| 58 | ||
| 67194 
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
 wenzelm parents: 
67189diff
changeset | 59 | |
| 67145 | 60 | (* output name for LaTeX macros *) | 
| 61 | ||
| 62 | val output_name = | |
| 63 | translate_string | |
| 64 | (fn "_" => "UNDERSCORE" | |
| 65 | | "'" => "PRIME" | |
| 66 | | "0" => "ZERO" | |
| 67 | | "1" => "ONE" | |
| 68 | | "2" => "TWO" | |
| 69 | | "3" => "THREE" | |
| 70 | | "4" => "FOUR" | |
| 71 | | "5" => "FIVE" | |
| 72 | | "6" => "SIX" | |
| 73 | | "7" => "SEVEN" | |
| 74 | | "8" => "EIGHT" | |
| 75 | | "9" => "NINE" | |
| 76 | | s => s); | |
| 77 | ||
| 78 | fun enclose_name bg en = enclose bg en o output_name; | |
| 79 | ||
| 80 | ||
| 61455 | 81 | (* output verbatim ASCII *) | 
| 58716 
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
 wenzelm parents: 
55828diff
changeset | 82 | |
| 
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
 wenzelm parents: 
55828diff
changeset | 83 | val output_ascii = | 
| 
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
 wenzelm parents: 
55828diff
changeset | 84 | translate_string | 
| 
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
 wenzelm parents: 
55828diff
changeset | 85 | (fn " " => "\\ " | 
| 
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
 wenzelm parents: 
55828diff
changeset | 86 | | "\t" => "\\ " | 
| 
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
 wenzelm parents: 
55828diff
changeset | 87 | | "\n" => "\\isanewline\n" | 
| 
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
 wenzelm parents: 
55828diff
changeset | 88 | | s => | 
| 72315 
8162ca81ea8a
suppress ligatures more robustly, notably for lualatex;
 wenzelm parents: 
71899diff
changeset | 89 | s | 
| 77851 | 90 |           |> member_string "\"#$%&',-<>\\^_`{}~" s ? enclose "{\\char`\\" "}"
 | 
| 72315 
8162ca81ea8a
suppress ligatures more robustly, notably for lualatex;
 wenzelm parents: 
71899diff
changeset | 91 |           |> suffix "{\\kern0pt}");
 | 
| 58716 
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
 wenzelm parents: 
55828diff
changeset | 92 | |
| 71899 | 93 | fun output_ascii_breakable sep = | 
| 94 | space_explode sep | |
| 95 | #> map output_ascii | |
| 96 |   #> space_implode (output_ascii sep ^ "\\discretionary{}{}{}");
 | |
| 97 | ||
| 58716 
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
 wenzelm parents: 
55828diff
changeset | 98 | |
| 61455 | 99 | (* output symbols *) | 
| 7726 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 100 | |
| 7900 | 101 | local | 
| 102 | ||
| 40402 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 103 | val char_table = | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 104 | Symtab.make | 
| 63590 
4854f7ee0987
proper latex rendering of abbrevs templates (e.g. src/HOL/Nonstandard_Analysis/HLim.thy);
 wenzelm parents: 
61595diff
changeset | 105 |    [("\007", "{\\isacharbell}"),
 | 
| 
4854f7ee0987
proper latex rendering of abbrevs templates (e.g. src/HOL/Nonstandard_Analysis/HLim.thy);
 wenzelm parents: 
61595diff
changeset | 106 |     ("!", "{\\isacharbang}"),
 | 
| 40402 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 107 |     ("\"", "{\\isachardoublequote}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 108 |     ("#", "{\\isacharhash}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 109 |     ("$", "{\\isachardollar}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 110 |     ("%", "{\\isacharpercent}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 111 |     ("&", "{\\isacharampersand}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 112 |     ("'", "{\\isacharprime}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 113 |     ("(", "{\\isacharparenleft}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 114 |     (")", "{\\isacharparenright}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 115 |     ("*", "{\\isacharasterisk}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 116 |     ("+", "{\\isacharplus}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 117 |     (",", "{\\isacharcomma}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 118 |     ("-", "{\\isacharminus}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 119 |     (".", "{\\isachardot}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 120 |     ("/", "{\\isacharslash}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 121 |     (":", "{\\isacharcolon}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 122 |     (";", "{\\isacharsemicolon}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 123 |     ("<", "{\\isacharless}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 124 |     ("=", "{\\isacharequal}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 125 |     (">", "{\\isachargreater}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 126 |     ("?", "{\\isacharquery}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 127 |     ("@", "{\\isacharat}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 128 |     ("[", "{\\isacharbrackleft}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 129 |     ("\\", "{\\isacharbackslash}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 130 |     ("]", "{\\isacharbrackright}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 131 |     ("^", "{\\isacharcircum}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 132 |     ("_", "{\\isacharunderscore}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 133 |     ("`", "{\\isacharbackquote}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 134 |     ("{", "{\\isacharbraceleft}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 135 |     ("|", "{\\isacharbar}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 136 |     ("}", "{\\isacharbraceright}"),
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 137 |     ("~", "{\\isachartilde}")];
 | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 138 | |
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 139 | fun output_chr " " = "\\ " | 
| 43709 
717e96cf9527
discontinued special treatment of hard tabulators;
 wenzelm parents: 
43485diff
changeset | 140 | | output_chr "\t" = "\\ " | 
| 40402 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 141 | | output_chr "\n" = "\\isanewline\n" | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 142 | | output_chr c = | 
| 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 143 | (case Symtab.lookup char_table c of | 
| 72315 
8162ca81ea8a
suppress ligatures more robustly, notably for lualatex;
 wenzelm parents: 
71899diff
changeset | 144 |         SOME s => s ^ "{\\kern0pt}"
 | 
| 40402 
b646316f8b3c
basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
 wenzelm parents: 
39666diff
changeset | 145 |       | 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 | 146 | |
| 67263 | 147 | fun output_sym sym = | 
| 14874 | 148 | (case Symbol.decode sym of | 
| 149 | Symbol.Char s => output_chr s | |
| 37533 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36959diff
changeset | 150 | | Symbol.UTF8 s => s | 
| 67263 | 151 |   | Symbol.Sym s => enclose_name "{\\isasym" "}" s
 | 
| 152 | | Symbol.Control s => enclose_name "\\isactrl" " " s | |
| 43485 | 153 | | Symbol.Malformed s => error (Symbol.malformed_msg s) | 
| 154 | | Symbol.EOF => error "Bad EOF symbol"); | |
| 7900 | 155 | |
| 67428 | 156 | open Basic_Symbol_Pos; | 
| 157 | ||
| 64526 
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
 wenzelm parents: 
63936diff
changeset | 158 | val scan_latex_length = | 
| 67428 | 159 | 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: 
63936diff
changeset | 160 | >> (Symbol.length o map Symbol_Pos.symbol) || | 
| 67428 | 161 | $$ 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: 
63936diff
changeset | 162 | |
| 67263 | 163 | val scan_latex = | 
| 67428 | 164 | $$ Symbol.latex |-- Symbol_Pos.scan_cartouche_content "Embedded LaTeX: " | 
| 165 | >> (implode o map Symbol_Pos.symbol) || | |
| 67263 | 166 | 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: 
63590diff
changeset | 167 | |
| 64526 
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
 wenzelm parents: 
63936diff
changeset | 168 | fun read scan syms = | 
| 
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
 wenzelm parents: 
63936diff
changeset | 169 | 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: 
63590diff
changeset | 170 | |
| 7900 | 171 | in | 
| 172 | ||
| 81263 | 173 | val length_symbols = Integer.sum o these o read scan_latex_length; | 
| 64526 
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
 wenzelm parents: 
63936diff
changeset | 174 | |
| 67263 | 175 | fun output_symbols syms = | 
| 67428 | 176 | if member (op =) syms Symbol.latex then | 
| 67263 | 177 | (case read scan_latex syms of | 
| 64526 
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
 wenzelm parents: 
63936diff
changeset | 178 | SOME ss => implode ss | 
| 
01920e390645
embedded latex has 0 length -- imitating \<^raw> before aa1fe1103ab8;
 wenzelm parents: 
63936diff
changeset | 179 |     | NONE => error ("Malformed embedded LaTeX: " ^ quote (Symbol.beginning 10 syms)))
 | 
| 67263 | 180 | else implode (map output_sym syms); | 
| 63935 
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
 wenzelm parents: 
63590diff
changeset | 181 | |
| 8192 | 182 | val output_syms = output_symbols o Symbol.explode; | 
| 7900 | 183 | |
| 184 | end; | |
| 7726 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 185 | |
| 67461 | 186 | fun symbols syms = text (Symbol_Pos.content syms, #1 (Symbol_Pos.range syms)); | 
| 187 | fun symbols_output syms = | |
| 188 | text (output_symbols (map Symbol_Pos.symbol syms), #1 (Symbol_Pos.range syms)); | |
| 189 | ||
| 7726 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 190 | |
| 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 191 | (* theory presentation *) | 
| 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 192 | |
| 67263 | 193 | fun isabelle_body name = | 
| 74881 | 194 | XML.enclose | 
| 67263 | 195 |    ("%\n\\begin{isabellebody}%\n\\setisabellecontext{" ^ output_syms name ^ "}%\n")
 | 
| 196 |    "%\n\\end{isabellebody}%\n";
 | |
| 7726 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 197 | |
| 9038 
63d20536971f
session.tex: nsert blank lines in order to guarantee new paragraphs
 wenzelm parents: 
8965diff
changeset | 198 | fun theory_entry name = "\\input{" ^ name ^ ".tex}\n\n";
 | 
| 7726 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 199 | |
| 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 200 | |
| 76955 | 201 | (* cite: references to bibliography *) | 
| 202 | ||
| 203 | fun cite {kind, location, citations} =
 | |
| 204 | let | |
| 205 | val _ = | |
| 206 | citations |> List.app (fn (s, pos) => | |
| 77851 | 207 | if member_string s "," | 
| 76955 | 208 |         then error ("Single citation expected, without commas" ^ Position.here pos)
 | 
| 209 | else ()); | |
| 76957 
deb7dffb3340
avoid confusion of markup element vs. property names;
 wenzelm parents: 
76956diff
changeset | 210 | val citations' = space_implode "," (map #1 citations); | 
| 
deb7dffb3340
avoid confusion of markup element vs. property names;
 wenzelm parents: 
76956diff
changeset | 211 |     val markup = Markup.latex_cite {kind = kind, citations = citations'};
 | 
| 76956 
e47fb5cfef41
clarified Latex markup: optional cite "location" consists of nested document text;
 wenzelm parents: 
76955diff
changeset | 212 | in [XML.Elem (markup, location)] end; | 
| 76955 | 213 | |
| 214 | ||
| 73754 | 215 | (* index entries *) | 
| 216 | ||
| 217 | type index_item = {text: text, like: string};
 | |
| 218 | type index_entry = {items: index_item list, def: bool};
 | |
| 219 | ||
| 220 | fun index_item (item: index_item) = | |
| 74786 | 221 | XML.wrap_elem ((Markup.latex_index_item, #text item), XML.string (#like item)); | 
| 73754 | 222 | |
| 223 | fun index_entry (entry: index_entry) = | |
| 74786 | 224 | [XML.Elem (Markup.latex_index_entry (if #def entry then "isaindexdef" else "isaindexref"), | 
| 225 | map index_item (#items entry))]; | |
| 73754 | 226 | |
| 73763 
eccc4a13216d
clarified index antiquotation for ML: more ambitious type-setting, more accurate syntax;
 wenzelm parents: 
73754diff
changeset | 227 | fun index_binding NONE = I | 
| 
eccc4a13216d
clarified index antiquotation for ML: more ambitious type-setting, more accurate syntax;
 wenzelm parents: 
73754diff
changeset | 228 | | 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: 
73754diff
changeset | 229 | |
| 
eccc4a13216d
clarified index antiquotation for ML: more ambitious type-setting, more accurate syntax;
 wenzelm parents: 
73754diff
changeset | 230 | fun index_variants setup binding = | 
| 
eccc4a13216d
clarified index antiquotation for ML: more ambitious type-setting, more accurate syntax;
 wenzelm parents: 
73754diff
changeset | 231 | 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: 
73754diff
changeset | 232 | |
| 
eccc4a13216d
clarified index antiquotation for ML: more ambitious type-setting, more accurate syntax;
 wenzelm parents: 
73754diff
changeset | 233 | |
| 80846 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 234 | (* markup and formatting *) | 
| 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 235 | |
| 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 236 | val output_ = output_symbols o Symbol.explode; | 
| 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 237 | |
| 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 238 | fun output_width str = | 
| 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 239 | let val syms = Symbol.explode str | 
| 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 240 | in (output_symbols syms, length_symbols syms) end; | 
| 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 241 | |
| 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 242 | val escape = enclose (Symbol.latex ^ Symbol.open_) Symbol.close; | 
| 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 243 | |
| 74884 
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
 wenzelm parents: 
74883diff
changeset | 244 | local | 
| 
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
 wenzelm parents: 
74883diff
changeset | 245 | |
| 81568 | 246 | val markup_macro = YXML.output_markup o Markup.latex_macro; | 
| 81683 | 247 | |
| 81568 | 248 | val markup_latex = | 
| 249 | Symtab.make | |
| 81628 
e5be995d21f0
clarified LaTeX presentation: more specific keywords;
 wenzelm parents: 
81587diff
changeset | 250 | [(Markup.commandN, markup_macro "isakeywordONE"), | 
| 
e5be995d21f0
clarified LaTeX presentation: more specific keywords;
 wenzelm parents: 
81587diff
changeset | 251 | (Markup.keyword1N, markup_macro "isakeywordONE"), | 
| 
e5be995d21f0
clarified LaTeX presentation: more specific keywords;
 wenzelm parents: 
81587diff
changeset | 252 | (Markup.keyword2N, markup_macro "isakeywordTWO"), | 
| 
e5be995d21f0
clarified LaTeX presentation: more specific keywords;
 wenzelm parents: 
81587diff
changeset | 253 | (Markup.keyword3N, markup_macro "isakeywordTHREE"), | 
| 81587 | 254 | (Markup.tclassN, markup_macro "isatclass"), | 
| 255 | (Markup.tconstN, markup_macro "isatconst"), | |
| 256 | (Markup.tfreeN, markup_macro "isatfree"), | |
| 257 | (Markup.tvarN, markup_macro "isatvar"), | |
| 258 | (Markup.constN, markup_macro "isaconst"), | |
| 259 | (Markup.freeN, markup_macro "isafree"), | |
| 260 | (Markup.skolemN, markup_macro "isaskolem"), | |
| 261 | (Markup.boundN, markup_macro "isabound"), | |
| 262 | (Markup.varN, markup_macro "isavar")]; | |
| 80839 | 263 | |
| 81568 | 264 | fun latex_markup (a, props) = | 
| 265 | (if Markup.has_syntax props then NONE else Symtab.lookup markup_latex a) | |
| 266 | |> the_default Markup.no_output; | |
| 10955 | 267 | |
| 80839 | 268 | fun latex_markup_output (bg, en) = | 
| 269 | (case try YXML.parse (bg ^ en) of | |
| 270 | SOME (XML.Elem (m, _)) => latex_markup m | |
| 271 | | _ => Markup.no_output); | |
| 272 | ||
| 273 | in | |
| 80789 
bcecb69f72fa
more scalable pretty printing: avoid exception String.Size at command "value" (line 33 of "$AFP/Iptables_Semantics/Examples/SQRL_Shorewall/Analyze_SQRL_Shorewall.thy") in AFP/c69af9cd3390;
 wenzelm parents: 
79503diff
changeset | 274 | |
| 80846 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 275 | fun output_ops opt_margin : Pretty.output_ops = | 
| 80855 
301612847ea3
further clarification of print_mode: PIDE markup depends on "isabelle_process" alone, Latex is stateless;
 wenzelm parents: 
80846diff
changeset | 276 |  {symbolic = false,
 | 
| 
301612847ea3
further clarification of print_mode: PIDE markup depends on "isabelle_process" alone, Latex is stateless;
 wenzelm parents: 
80846diff
changeset | 277 | output = output_width, | 
| 80846 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 278 | markup = latex_markup_output, | 
| 81683 | 279 | indent_markup = markup_macro "isaindent", | 
| 80846 
9ed32b8a03a9
clarified print mode "latex": no longer impact Output/Markup/Pretty operations;
 wenzelm parents: 
80839diff
changeset | 280 | margin = ML_Pretty.get_margin opt_margin}; | 
| 8460 | 281 | |
| 7726 
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
 wenzelm parents: diff
changeset | 282 | end; | 
| 74884 
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
 wenzelm parents: 
74883diff
changeset | 283 | |
| 
229d7ea628c2
more symbolic latex_output via XML (using YXML within text);
 wenzelm parents: 
74883diff
changeset | 284 | end; |