author | wenzelm |
Sun, 23 Jul 2000 12:10:11 +0200 | |
changeset 9416 | 9144976964e7 |
parent 9144 | 20a70ef9c320 |
child 9505 | 09c75c801dde |
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 |
9135 | 11 |
datatype token = Basic of OuterLex.token | Markup of string | MarkupEnv of string | Verbatim |
12 |
val output_tokens: (token * string) list -> string |
|
13 |
val isabelle_file: string -> string |
|
8499 | 14 |
val old_symbol_source: string -> Symbol.symbol list -> string |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
15 |
val theory_entry: string -> string |
9135 | 16 |
val modes: string list |
8965 | 17 |
val setup: (theory -> theory) list |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
18 |
end; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
19 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
20 |
structure Latex: LATEX = |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
21 |
struct |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
22 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
23 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
24 |
(* symbol output *) |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
25 |
|
7900 | 26 |
local |
27 |
||
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
28 |
val output_chr = fn |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
29 |
" " => "~" | |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
30 |
"\n" => "\\isanewline\n" | |
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 |
"&" => "\\&" | |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
33 |
"%" => "\\%" | |
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 |
"_" => "\\_" | |
7800 | 36 |
"{" => "{\\isabraceleft}" | |
37 |
"}" => "{\\isabraceright}" | |
|
38 |
"~" => "{\\isatilde}" | |
|
39 |
"^" => "{\\isacircum}" | |
|
7752 | 40 |
"\"" => "{\"}" | |
7800 | 41 |
"\\" => "{\\isabackslash}" | |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
42 |
c => c; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
43 |
|
7900 | 44 |
fun output_sym s = |
45 |
if size s = 1 then output_chr s |
|
46 |
else |
|
47 |
(case explode s of |
|
48 |
cs as "\\" :: "<" :: "^" :: _ => implode (map output_chr cs) |
|
7973 | 49 |
| "\\" :: "<" :: cs => "{\\isasym" ^ implode (#1 (Library.split_last cs)) ^ "}" |
7900 | 50 |
| _ => sys_error "output_sym"); |
51 |
||
52 |
in |
|
53 |
||
8192 | 54 |
val output_symbols = implode o map output_sym; |
55 |
val output_syms = output_symbols o Symbol.explode; |
|
7900 | 56 |
|
57 |
end; |
|
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
58 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
59 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
60 |
(* token output *) |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
61 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
62 |
structure T = OuterLex; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
63 |
|
8660 | 64 |
datatype token = |
65 |
Basic of T.token | |
|
9135 | 66 |
Markup of string | |
67 |
MarkupEnv of string | |
|
68 |
Verbatim; |
|
7756 | 69 |
|
70 |
||
71 |
val invisible_token = T.keyword_with (equal ";") orf T.is_kind T.Comment; |
|
72 |
||
73 |
fun strip_blanks s = |
|
74 |
implode (#1 (Library.take_suffix Symbol.is_blank |
|
75 |
(#2 (Library.take_prefix Symbol.is_blank (explode s))))); |
|
76 |
||
9135 | 77 |
fun output_tok (Basic tok, _) = |
7752 | 78 |
let val s = T.val_of tok in |
7756 | 79 |
if invisible_token tok then "" |
7800 | 80 |
else if T.is_kind T.Command tok then |
8896 | 81 |
if s = "{" then "{\\isabeginblock}" |
82 |
else if s = "}" then "{\\isaendblock}" |
|
7900 | 83 |
else "\\isacommand{" ^ output_syms s ^ "}" |
7800 | 84 |
else if T.is_kind T.Keyword tok andalso Syntax.is_identifier s then |
7900 | 85 |
"\\isakeyword{" ^ output_syms s ^ "}" |
86 |
else if T.is_kind T.String tok then output_syms (quote s) |
|
87 |
else if T.is_kind T.Verbatim tok then output_syms (enclose "{*" "*}" s) |
|
88 |
else output_syms s |
|
7756 | 89 |
end |
9135 | 90 |
| output_tok (Markup cmd, txt) = "%\n\\isamarkup" ^ cmd ^ "{" ^ strip_blanks txt ^ "}\n" |
91 |
| output_tok (MarkupEnv cmd, txt) = "%\n\\begin{isamarkup" ^ cmd ^ "}%\n" ^ |
|
8660 | 92 |
strip_blanks txt ^ "%\n\\end{isamarkup" ^ cmd ^ "}%\n" |
9135 | 93 |
| output_tok (Verbatim, txt) = "%\n" ^ strip_blanks txt ^ "\n"; |
7745 | 94 |
|
7756 | 95 |
|
96 |
val output_tokens = implode o map output_tok; |
|
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
97 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
98 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
99 |
(* theory presentation *) |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
100 |
|
9135 | 101 |
val isabelle_file = enclose |
102 |
"\\begin{isabelle}%\n" |
|
103 |
"\\end{isabelle}%\n\ |
|
104 |
\%%% Local Variables:\n\ |
|
105 |
\%%% mode: latex\n\ |
|
106 |
\%%% TeX-master: \"root\"\n\ |
|
9144 | 107 |
\%%% End:\n"; |
8192 | 108 |
|
8499 | 109 |
fun old_symbol_source name syms = |
9135 | 110 |
isabelle_file ("\\isamarkupheader{" ^ output_syms name ^ "}%\n" ^ output_symbols syms); |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
111 |
|
9038
63d20536971f
session.tex: nsert blank lines in order to guarantee new paragraphs
wenzelm
parents:
8965
diff
changeset
|
112 |
fun theory_entry name = "\\input{" ^ name ^ ".tex}\n\n"; |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
113 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
114 |
|
8460 | 115 |
(* print mode *) |
116 |
||
8965 | 117 |
val latexN = "latex"; |
9135 | 118 |
val modes = [latexN, Symbol.xsymbolsN, Symbol.symbolsN]; |
8965 | 119 |
|
8460 | 120 |
fun latex_output str = |
121 |
let val syms = Symbol.explode str |
|
122 |
in (output_symbols syms, real (Symbol.length syms)) end; |
|
123 |
||
8965 | 124 |
val token_translation = map (fn s => (latexN, s, latex_output)) Syntax.standard_token_classes; |
125 |
||
126 |
val _ = Symbol.add_mode latexN latex_output; |
|
127 |
val setup = [Theory.add_tokentrfuns token_translation]; |
|
8460 | 128 |
|
129 |
||
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
130 |
end; |