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