ProgTutorial/output_tutorial.ML
author Christian Urban <urbanc@in.tum.de>
Fri, 05 Feb 2010 15:49:03 +0100
changeset 416 c6b5d1e25cdd
parent 373 28a49fe024c9
child 438 d9a223c023f6
permissions -rw-r--r--
updated to new Isabelle
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
     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
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
(* rebuilding the output function from ThyOutput in order to *)
316
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
     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
328
c0cae24b9d46 updated to new Isabelle; more work on the data section
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
     8
val gray = Unsynchronized.ref false
c0cae24b9d46 updated to new Isabelle; more work on the data section
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
     9
val linenos = Unsynchronized.ref 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
311
ee864694315b polished
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    11
255
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
fun output txt =
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
let
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  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
    15
in   
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  prts
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  |> (if ! ThyOutput.quotes then map Pretty.quote else I)
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  |> (if ! ThyOutput.display then
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
    map (Output.output o Pretty.string_of o Pretty.indent (! ThyOutput.indent))
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
    #> space_implode "\\isasep\\isanewline%\n"
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
    #> (if ! linenos then (enclose "\\begin{linenos}%\n" "%\n\\end{linenos}") else I) 
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
    #> (if ! gray then (enclose "\\begin{graybox}%\n" "%\n\\end{graybox}") else I) 
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
    #> 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
    24
  else
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
    map (Output.output o (if ! ThyOutput.break then Pretty.string_of else Pretty.str_of))
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
    #> space_implode "\\isasep\\isanewline%\n"
256
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    27
    #> 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
    28
end
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
316
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    30
datatype indstring =
258
03145998190b slightly modified index generation
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    31
  NoString
302
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    32
| Plain   of string
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
    33
| Code    of string
316
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    34
| Struct  of string
256
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    35
316
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    36
fun translate_string f = Symbol.explode #> map f #> implode;
256
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    37
316
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    38
val clean_string = translate_string
256
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    39
  (fn "_" => "\\_"
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    40
    | "#" => "\\#"
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    41
    | "<" => "\\isacharless"
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    42
    | ">" => "\\isachargreater"
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    43
    | "{" => "\\{"
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    44
    | "|" => "\\isacharbar"
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    45
    | "}" => "\\}"
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    46
    | "$" => "\\isachardollar"
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    47
    | "!" => "\\isacharbang"
261
358f325f4db6 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    48
    | "\<dash>" => "-"
316
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    49
    | c => c)
256
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    50
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    51
fun get_word str =
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    52
let 
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    53
  fun only_letters [] = true
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    54
    | only_letters (x::xs) = 
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    55
        if (Symbol.is_ascii_blank x) then false else only_letters xs
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    56
in
316
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    57
  if only_letters (Symbol.explode str) 
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    58
  then clean_string str
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    59
  else error ("Only single word allowed! Error with " ^ quote str)
256
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    60
end  
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    61
316
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    62
fun get_indstring NoString = ""
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    63
  | get_indstring (Plain s) = get_word s
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    64
  | get_indstring (Code s) = let val w = get_word s in implode[w, "@{\\tt\\slshape{}", w, "}"] end
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    65
  | get_indstring (Struct s) =  implode ["in {\\tt\\slshape{}", get_word s, "}"]
256
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    66
316
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    67
fun get_index {main = m, minor = n} = 
258
03145998190b slightly modified index generation
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    68
 (if n = NoString
316
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    69
  then implode ["\\index{", get_indstring m, "}"]  
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    70
  else implode ["\\index{", get_indstring m, " (", get_indstring n, ")}"])  
256
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    71
    
373
28a49fe024c9 added structure index
Christian Urban <urbanc@in.tum.de>
parents: 351
diff changeset
    72
fun get_str_index {main = m, minor = n} = 
28a49fe024c9 added structure index
Christian Urban <urbanc@in.tum.de>
parents: 351
diff changeset
    73
 (case n of
28a49fe024c9 added structure index
Christian Urban <urbanc@in.tum.de>
parents: 351
diff changeset
    74
   Struct s => implode ["\\index[str]{{\\tt\\slshape{}", get_word s, "}!", get_indstring m, "}"]
28a49fe024c9 added structure index
Christian Urban <urbanc@in.tum.de>
parents: 351
diff changeset
    75
  | _ => "")
28a49fe024c9 added structure index
Christian Urban <urbanc@in.tum.de>
parents: 351
diff changeset
    76
316
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    77
fun output_indexed ind txt =
256
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
    78
 txt |> output
316
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
    79
     |> prefix (get_index ind)
373
28a49fe024c9 added structure index
Christian Urban <urbanc@in.tum.de>
parents: 351
diff changeset
    80
     |> prefix (get_str_index ind)
255
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
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
    83
  | 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
    84
  | 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
    85
  | 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
    86
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
val _ = ThyOutput.add_options
351
f118240ab44a updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 328
diff changeset
    88
 [("gray", Library.setmp_CRITICAL gray o boolean),
f118240ab44a updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 328
diff changeset
    89
  ("linenos", Library.setmp_CRITICAL 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
    90
ef1da1abee46 added infrastructure for index; antiquotations have now the options [index] and [indexc]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
end