author | wenzelm |
Sat, 12 Jun 2004 22:45:46 +0200 | |
changeset 14924 | 2be4cbe27a27 |
parent 14879 | 8989eedf72a1 |
child 14973 | 0613f64653b7 |
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 |
ID: $Id$ |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
3 |
Author: Markus Wenzel, TU Muenchen |
8808 | 4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
5 |
|
8460 | 6 |
LaTeX presentation primitives (based on outer lexical syntax). |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
7 |
*) |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
8 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
9 |
signature LATEX = |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
10 |
sig |
14924 | 11 |
val output_known_symbols: (string -> bool) * (string -> bool) -> |
12 |
Symbol.symbol list -> string |
|
11719 | 13 |
val output_symbols: Symbol.symbol list -> string |
9135 | 14 |
datatype token = Basic of OuterLex.token | Markup of string | MarkupEnv of string | Verbatim |
15 |
val output_tokens: (token * string) list -> string |
|
11860 | 16 |
val flag_markup: bool -> string |
9707 | 17 |
val tex_trailer: string |
9916 | 18 |
val isabelle_file: string -> string -> string |
14924 | 19 |
val symbol_source: (string -> bool) * (string -> bool) -> |
20 |
string -> Symbol.symbol list -> string |
|
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
21 |
val theory_entry: string -> string |
9135 | 22 |
val modes: string list |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
23 |
end; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
24 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
25 |
structure Latex: LATEX = |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
26 |
struct |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
27 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
28 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
29 |
(* symbol output *) |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
30 |
|
7900 | 31 |
local |
32 |
||
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
33 |
val output_chr = fn |
9505 | 34 |
" " => "\\ " | |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
35 |
"\n" => "\\isanewline\n" | |
9668 | 36 |
"!" => "{\\isacharbang}" | |
37 |
"\"" => "{\\isachardoublequote}" | |
|
9663 | 38 |
"#" => "{\\isacharhash}" | |
39 |
"$" => "{\\isachardollar}" | |
|
40 |
"%" => "{\\isacharpercent}" | |
|
41 |
"&" => "{\\isacharampersand}" | |
|
42 |
"'" => "{\\isacharprime}" | |
|
43 |
"(" => "{\\isacharparenleft}" | |
|
44 |
")" => "{\\isacharparenright}" | |
|
45 |
"*" => "{\\isacharasterisk}" | |
|
9668 | 46 |
"+" => "{\\isacharplus}" | |
47 |
"," => "{\\isacharcomma}" | |
|
9663 | 48 |
"-" => "{\\isacharminus}" | |
9668 | 49 |
"." => "{\\isachardot}" | |
50 |
"/" => "{\\isacharslash}" | |
|
51 |
":" => "{\\isacharcolon}" | |
|
52 |
";" => "{\\isacharsemicolon}" | |
|
9663 | 53 |
"<" => "{\\isacharless}" | |
9668 | 54 |
"=" => "{\\isacharequal}" | |
9663 | 55 |
">" => "{\\isachargreater}" | |
9668 | 56 |
"?" => "{\\isacharquery}" | |
57 |
"@" => "{\\isacharat}" | |
|
9663 | 58 |
"[" => "{\\isacharbrackleft}" | |
59 |
"\\" => "{\\isacharbackslash}" | |
|
60 |
"]" => "{\\isacharbrackright}" | |
|
61 |
"^" => "{\\isacharcircum}" | |
|
62 |
"_" => "{\\isacharunderscore}" | |
|
9668 | 63 |
"`" => "{\\isacharbackquote}" | |
9663 | 64 |
"{" => "{\\isacharbraceleft}" | |
65 |
"|" => "{\\isacharbar}" | |
|
66 |
"}" => "{\\isacharbraceright}" | |
|
67 |
"~" => "{\\isachartilde}" | |
|
10184 | 68 |
c => if Symbol.is_digit c then enclose "{\\isadigit{" "}}" c else c; |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
69 |
|
14924 | 70 |
val output_chrs = translate_string output_chr; |
71 |
||
72 |
fun output_known_sym (known_sym, known_ctrl) sym = |
|
14874 | 73 |
(case Symbol.decode sym of |
74 |
Symbol.Char s => output_chr s |
|
14924 | 75 |
| Symbol.Sym s => if known_sym s then enclose "{\\isasym" "}" s else output_chrs sym |
76 |
| Symbol.Ctrl s => if known_ctrl s then enclose "\\isactrl" " " s else output_chrs sym |
|
14874 | 77 |
| Symbol.Raw s => s); |
7900 | 78 |
|
79 |
in |
|
80 |
||
14924 | 81 |
val output_known_symbols = implode oo (map o output_known_sym); |
82 |
val output_symbols = output_known_symbols (K true, K true); |
|
8192 | 83 |
val output_syms = output_symbols o Symbol.explode; |
7900 | 84 |
|
85 |
end; |
|
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
86 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
87 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
88 |
(* token output *) |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
89 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
90 |
structure T = OuterLex; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
91 |
|
8660 | 92 |
datatype token = |
93 |
Basic of T.token | |
|
9135 | 94 |
Markup of string | |
95 |
MarkupEnv of string | |
|
96 |
Verbatim; |
|
7756 | 97 |
|
98 |
||
99 |
val invisible_token = T.keyword_with (equal ";") orf T.is_kind T.Comment; |
|
100 |
||
9135 | 101 |
fun output_tok (Basic tok, _) = |
7752 | 102 |
let val s = T.val_of tok in |
7756 | 103 |
if invisible_token tok then "" |
7800 | 104 |
else if T.is_kind T.Command tok then |
9668 | 105 |
"\\isacommand{" ^ output_syms s ^ "}" |
14680 | 106 |
else if T.is_kind T.Keyword tok andalso Syntax.is_ascii_identifier s then |
7900 | 107 |
"\\isakeyword{" ^ output_syms s ^ "}" |
14598
7009f59711e3
Replaced quote by Library.quote, since quote now refers to Symbol.quote
berghofe
parents:
14561
diff
changeset
|
108 |
else if T.is_kind T.String tok then output_syms (Library.quote s) |
7900 | 109 |
else if T.is_kind T.Verbatim tok then output_syms (enclose "{*" "*}" s) |
110 |
else output_syms s |
|
7756 | 111 |
end |
11012 | 112 |
| output_tok (Markup cmd, txt) = |
113 |
"%\n\\isamarkup" ^ cmd ^ "{" ^ Symbol.strip_blanks txt ^ "%\n}\n" |
|
9135 | 114 |
| output_tok (MarkupEnv cmd, txt) = "%\n\\begin{isamarkup" ^ cmd ^ "}%\n" ^ |
11012 | 115 |
Symbol.strip_blanks txt ^ "%\n\\end{isamarkup" ^ cmd ^ "}%\n" |
116 |
| output_tok (Verbatim, txt) = "%\n" ^ Symbol.strip_blanks txt ^ "\n"; |
|
7745 | 117 |
|
7756 | 118 |
|
119 |
val output_tokens = implode o map output_tok; |
|
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
120 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
121 |
|
11860 | 122 |
fun flag_markup true = "\\isamarkuptrue%\n" |
123 |
| flag_markup false = "\\isamarkupfalse%\n"; |
|
124 |
||
125 |
||
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
126 |
(* theory presentation *) |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
127 |
|
9707 | 128 |
val tex_trailer = |
129 |
"%%% Local Variables:\n\ |
|
9135 | 130 |
\%%% mode: latex\n\ |
131 |
\%%% TeX-master: \"root\"\n\ |
|
9144 | 132 |
\%%% End:\n"; |
8192 | 133 |
|
9916 | 134 |
fun isabelle_file name txt = |
135 |
"%\n\\begin{isabellebody}%\n\ |
|
10247 | 136 |
\\\def\\isabellecontext{" ^ output_syms name ^ "}%\n" ^ txt ^ |
9916 | 137 |
"\\end{isabellebody}%\n" ^ tex_trailer; |
9707 | 138 |
|
14924 | 139 |
fun symbol_source known name syms = isabelle_file name |
140 |
("\\isamarkupheader{" ^ output_known_symbols known (Symbol.explode name) ^ "}%\n" ^ |
|
141 |
output_known_symbols known syms); |
|
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
142 |
|
9038
63d20536971f
session.tex: nsert blank lines in order to guarantee new paragraphs
wenzelm
parents:
8965
diff
changeset
|
143 |
fun theory_entry name = "\\input{" ^ name ^ ".tex}\n\n"; |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
144 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
145 |
|
8460 | 146 |
(* print mode *) |
147 |
||
8965 | 148 |
val latexN = "latex"; |
9135 | 149 |
val modes = [latexN, Symbol.xsymbolsN, Symbol.symbolsN]; |
8965 | 150 |
|
8460 | 151 |
fun latex_output str = |
152 |
let val syms = Symbol.explode str |
|
153 |
in (output_symbols syms, real (Symbol.length syms)) end; |
|
154 |
||
10955 | 155 |
fun latex_indent "" = "" |
156 |
| latex_indent s = enclose "\\isaindent{" "}" s; |
|
157 |
||
14840 | 158 |
val _ = Output.add_mode latexN (latex_output, latex_indent o #1, Symbol.default_raw); |
8460 | 159 |
|
160 |
||
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
161 |
end; |