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