author | wenzelm |
Fri, 08 Oct 1999 15:09:14 +0200 | |
changeset 7800 | 8ee919e42174 |
parent 7789 | 57d20133224e |
child 7852 | d28dff7ac48d |
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 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
5 |
Simple LaTeX presentation primitives (based on outer lexical syntax). |
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 |
7789 | 10 |
datatype token = Basic of OuterLex.token | Markup of string * string | Verbatim of string |
7756 | 11 |
val token_source: token list -> string |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
12 |
val theory_entry: string -> string |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
13 |
end; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
14 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
15 |
structure Latex: LATEX = |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
16 |
struct |
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 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
19 |
(* symbol output *) |
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 |
val output_chr = fn |
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 |
"\n" => "\\isanewline\n" | |
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 |
"&" => "\\&" | |
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 |
"#" => "\\#" | |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
28 |
"_" => "\\_" | |
7800 | 29 |
"{" => "{\\isabraceleft}" | |
30 |
"}" => "{\\isabraceright}" | |
|
31 |
"~" => "{\\isatilde}" | |
|
32 |
"^" => "{\\isacircum}" | |
|
7752 | 33 |
"\"" => "{\"}" | |
7800 | 34 |
"\\" => "{\\isabackslash}" | |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
35 |
c => c; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
36 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
37 |
(* FIXME replace \<forall> etc. *) |
7752 | 38 |
val output_sym = implode o map output_chr o explode; |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
39 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
40 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
41 |
(* token output *) |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
42 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
43 |
structure T = OuterLex; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
44 |
|
7789 | 45 |
datatype token = Basic of T.token | Markup of string * string | Verbatim of string; |
7756 | 46 |
|
47 |
||
48 |
val invisible_token = T.keyword_with (equal ";") orf T.is_kind T.Comment; |
|
49 |
||
50 |
fun strip_blanks s = |
|
51 |
implode (#1 (Library.take_suffix Symbol.is_blank |
|
52 |
(#2 (Library.take_prefix Symbol.is_blank (explode s))))); |
|
53 |
||
54 |
fun output_tok (Basic tok) = |
|
7752 | 55 |
let val s = T.val_of tok in |
7756 | 56 |
if invisible_token tok then "" |
7800 | 57 |
else if T.is_kind T.Command tok then |
58 |
if s = "{{" then "{\\isabeginblock}" |
|
59 |
else if s = "}}" then "{\\isaendblock}" |
|
60 |
else "\\isacommand{" ^ output_sym s ^ "}" |
|
61 |
else if T.is_kind T.Keyword tok andalso Syntax.is_identifier s then |
|
62 |
"\\isakeyword{" ^ output_sym s ^ "}" |
|
7752 | 63 |
else if T.is_kind T.String tok then output_sym (quote s) |
64 |
else if T.is_kind T.Verbatim tok then output_sym (enclose "{*" "*}" s) |
|
65 |
else output_sym s |
|
7756 | 66 |
end |
7800 | 67 |
| output_tok (Markup (cmd, txt)) = "\n\\isamarkup" ^ cmd ^ "{" ^ strip_blanks txt ^ "}\n" |
68 |
| output_tok (Verbatim txt) = "\n" ^ strip_blanks txt ^ "\n"; |
|
7745 | 69 |
|
7756 | 70 |
|
71 |
val output_tokens = implode o map output_tok; |
|
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
72 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
73 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
74 |
(* theory presentation *) |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
75 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
76 |
fun token_source toks = |
7756 | 77 |
"\\begin{isabellesimple}\n" ^ output_tokens toks ^ "\\end{isabellesimple}\n"; |
7726
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
78 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
79 |
fun theory_entry name = "\\input{" ^ name ^ ".tex}\n"; |
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
80 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
81 |
|
2c7fc0ba1e12
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff
changeset
|
82 |
end; |