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