255
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
1 |
|
256
|
2 |
structure OutputTutorial =
|
255
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
struct
|
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
|
438
|
5 |
(* rebuilding the output function from Thy_Output in order to *)
|
316
|
6 |
(* enable the options [gray, linenos] *)
|
255
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
7 |
|
562
|
8 |
val thy_output_linenos = Attrib.setup_config_bool @{binding linenos} (K false)
|
|
9 |
val thy_output_gray = Attrib.setup_config_bool @{binding gray} (K false)
|
255
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
10 |
|
562
|
11 |
fun output_raw ctxt txt =
|
255
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
12 |
let
|
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
13 |
val prts = map Pretty.str txt
|
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
14 |
in
|
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
15 |
prts
|
562
|
16 |
|> (if Config.get ctxt Document_Antiquotation.thy_output_quotes then map Pretty.quote else I)
|
|
17 |
|> (if Config.get ctxt Document_Antiquotation.thy_output_display then
|
|
18 |
map (Output.output o Pretty.string_of o Pretty.indent (Config.get ctxt Document_Antiquotation.thy_output_indent))
|
255
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
19 |
#> space_implode "\\isasep\\isanewline%\n"
|
562
|
20 |
#> (if Config.get ctxt thy_output_linenos then (enclose "\\begin{linenos}%\n" "%\n\\end{linenos}") else I)
|
|
21 |
#> (if Config.get ctxt thy_output_gray then (enclose "\\begin{graybox}%\n" "%\n\\end{graybox}") else I)
|
255
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
22 |
#> enclose "\\begin{isabelle}%\n" "%\n\\end{isabelle}"
|
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
23 |
else
|
562
|
24 |
map (Output.output o (if Config.get ctxt Document_Antiquotation.thy_output_break then Pretty.string_of else Pretty.unformatted_string_of))
|
255
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
25 |
#> space_implode "\\isasep\\isanewline%\n"
|
256
|
26 |
#> enclose "\\isa{" "}")
|
255
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
27 |
end
|
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
28 |
|
562
|
29 |
fun output ctxt txt = Latex.string (output_raw ctxt txt)
|
|
30 |
|
316
|
31 |
datatype indstring =
|
258
|
32 |
NoString
|
302
|
33 |
| Plain of string
|
|
34 |
| Code of string
|
316
|
35 |
| Struct of string
|
256
|
36 |
|
316
|
37 |
fun translate_string f = Symbol.explode #> map f #> implode;
|
256
|
38 |
|
316
|
39 |
val clean_string = translate_string
|
256
|
40 |
(fn "_" => "\\_"
|
|
41 |
| "#" => "\\#"
|
|
42 |
| "<" => "\\isacharless"
|
|
43 |
| ">" => "\\isachargreater"
|
|
44 |
| "{" => "\\{"
|
|
45 |
| "|" => "\\isacharbar"
|
|
46 |
| "}" => "\\}"
|
|
47 |
| "$" => "\\isachardollar"
|
|
48 |
| "!" => "\\isacharbang"
|
261
|
49 |
| "\<dash>" => "-"
|
316
|
50 |
| c => c)
|
256
|
51 |
|
|
52 |
fun get_word str =
|
|
53 |
let
|
|
54 |
fun only_letters [] = true
|
|
55 |
| only_letters (x::xs) =
|
|
56 |
if (Symbol.is_ascii_blank x) then false else only_letters xs
|
|
57 |
in
|
316
|
58 |
if only_letters (Symbol.explode str)
|
|
59 |
then clean_string str
|
|
60 |
else error ("Only single word allowed! Error with " ^ quote str)
|
256
|
61 |
end
|
|
62 |
|
316
|
63 |
fun get_indstring NoString = ""
|
|
64 |
| get_indstring (Plain s) = get_word s
|
|
65 |
| get_indstring (Code s) = let val w = get_word s in implode[w, "@{\\tt\\slshape{}", w, "}"] end
|
|
66 |
| get_indstring (Struct s) = implode ["in {\\tt\\slshape{}", get_word s, "}"]
|
256
|
67 |
|
316
|
68 |
fun get_index {main = m, minor = n} =
|
258
|
69 |
(if n = NoString
|
316
|
70 |
then implode ["\\index{", get_indstring m, "}"]
|
|
71 |
else implode ["\\index{", get_indstring m, " (", get_indstring n, ")}"])
|
256
|
72 |
|
373
|
73 |
fun get_str_index {main = m, minor = n} =
|
|
74 |
(case n of
|
|
75 |
Struct s => implode ["\\index[str]{{\\tt\\slshape{}", get_word s, "}!", get_indstring m, "}"]
|
|
76 |
| _ => "")
|
|
77 |
|
449
|
78 |
fun output_indexed ctxt ind txt =
|
562
|
79 |
txt |> output_raw ctxt
|
316
|
80 |
|> prefix (get_index ind)
|
373
|
81 |
|> prefix (get_str_index ind)
|
562
|
82 |
|> Latex.string
|
255
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
83 |
|
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
84 |
fun boolean "" = true
|
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
85 |
| boolean "true" = true
|
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
86 |
| boolean "false" = false
|
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
87 |
| boolean s = error ("Bad boolean value: " ^ quote s);
|
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
88 |
|
562
|
89 |
val _ = Theory.setup
|
|
90 |
(Document_Antiquotation.setup_option @{binding gray} (Config.put thy_output_gray o boolean) #>
|
|
91 |
Document_Antiquotation.setup_option @{binding linenos} (Config.put thy_output_linenos o boolean) );
|
255
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
92 |
|
471
|
93 |
|
255
ef1da1abee46
added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
94 |
end |