author | wenzelm |
Sun, 21 May 2000 14:33:46 +0200 | |
changeset 8896 | c80aba8c1d5e |
parent 8808 | 204f4ebbba64 |
child 8965 | d46b36785c70 |
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 |
8660 | 11 |
datatype token = Basic of OuterLex.token | Markup of string * string | |
12 |
MarkupEnv of string * string | Verbatim of string |
|
8499 | 13 |
val old_symbol_source: string -> Symbol.symbol list -> string |
7756 | 14 |
val token_source: token list -> string |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
15 |
val theory_entry: string -> string |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
16 |
end; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
17 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
18 |
structure Latex: LATEX = |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
19 |
struct |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
20 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
21 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
22 |
(* symbol output *) |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
23 |
|
7900 | 24 |
local |
25 |
||
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
26 |
val output_chr = fn |
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 |
"\n" => "\\isanewline\n" | |
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 |
"&" => "\\&" | |
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 |
"_" => "\\_" | |
7800 | 34 |
"{" => "{\\isabraceleft}" | |
35 |
"}" => "{\\isabraceright}" | |
|
36 |
"~" => "{\\isatilde}" | |
|
37 |
"^" => "{\\isacircum}" | |
|
7752 | 38 |
"\"" => "{\"}" | |
7800 | 39 |
"\\" => "{\\isabackslash}" | |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
40 |
c => c; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
41 |
|
7900 | 42 |
fun output_sym s = |
43 |
if size s = 1 then output_chr s |
|
44 |
else |
|
45 |
(case explode s of |
|
46 |
cs as "\\" :: "<" :: "^" :: _ => implode (map output_chr cs) |
|
7973 | 47 |
| "\\" :: "<" :: cs => "{\\isasym" ^ implode (#1 (Library.split_last cs)) ^ "}" |
7900 | 48 |
| _ => sys_error "output_sym"); |
49 |
||
50 |
in |
|
51 |
||
8192 | 52 |
val output_symbols = implode o map output_sym; |
53 |
val output_syms = output_symbols o Symbol.explode; |
|
7900 | 54 |
|
55 |
end; |
|
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
56 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
57 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
58 |
(* token output *) |
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 |
structure T = OuterLex; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
61 |
|
8660 | 62 |
datatype token = |
63 |
Basic of T.token | |
|
64 |
Markup of string * string | |
|
65 |
MarkupEnv of string * string | |
|
66 |
Verbatim of string; |
|
7756 | 67 |
|
68 |
||
69 |
val invisible_token = T.keyword_with (equal ";") orf T.is_kind T.Comment; |
|
70 |
||
71 |
fun strip_blanks s = |
|
72 |
implode (#1 (Library.take_suffix Symbol.is_blank |
|
73 |
(#2 (Library.take_prefix Symbol.is_blank (explode s))))); |
|
74 |
||
75 |
fun output_tok (Basic tok) = |
|
7752 | 76 |
let val s = T.val_of tok in |
7756 | 77 |
if invisible_token tok then "" |
7800 | 78 |
else if T.is_kind T.Command tok then |
8896 | 79 |
if s = "{" then "{\\isabeginblock}" |
80 |
else if s = "}" then "{\\isaendblock}" |
|
7900 | 81 |
else "\\isacommand{" ^ output_syms s ^ "}" |
7800 | 82 |
else if T.is_kind T.Keyword tok andalso Syntax.is_identifier s then |
7900 | 83 |
"\\isakeyword{" ^ output_syms s ^ "}" |
84 |
else if T.is_kind T.String tok then output_syms (quote s) |
|
85 |
else if T.is_kind T.Verbatim tok then output_syms (enclose "{*" "*}" s) |
|
86 |
else output_syms s |
|
7756 | 87 |
end |
7852 | 88 |
| output_tok (Markup (cmd, txt)) = "%\n\\isamarkup" ^ cmd ^ "{" ^ strip_blanks txt ^ "}\n" |
8660 | 89 |
| output_tok (MarkupEnv (cmd, txt)) = "%\n\\begin{isamarkup" ^ cmd ^ "}%\n" ^ |
90 |
strip_blanks txt ^ "%\n\\end{isamarkup" ^ cmd ^ "}%\n" |
|
7852 | 91 |
| output_tok (Verbatim txt) = "%\n" ^ strip_blanks txt ^ "\n"; |
7745 | 92 |
|
7756 | 93 |
|
94 |
val output_tokens = implode o map output_tok; |
|
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
95 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
96 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
97 |
(* theory presentation *) |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
98 |
|
8460 | 99 |
val isabelle_env = enclose "\\begin{isabelle}%\n" "\\end{isabelle}%\n"; |
8192 | 100 |
|
8499 | 101 |
fun old_symbol_source name syms = |
102 |
isabelle_env ("\\isamarkupheader{" ^ output_syms name ^ "}%\n" ^ output_symbols syms); |
|
103 |
||
8460 | 104 |
val token_source = isabelle_env o output_tokens; |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
105 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
106 |
fun theory_entry name = "\\input{" ^ name ^ ".tex}\n"; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
107 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
108 |
|
8460 | 109 |
(* print mode *) |
110 |
||
111 |
fun latex_output str = |
|
112 |
let val syms = Symbol.explode str |
|
113 |
in (output_symbols syms, real (Symbol.length syms)) end; |
|
114 |
||
115 |
val _ = Symbol.add_mode "latex" latex_output; |
|
116 |
||
117 |
||
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
118 |
end; |