src/Pure/Thy/latex.ML
author wenzelm
Wed, 06 Oct 1999 00:35:05 +0200
changeset 7752 7ee322caf59c
parent 7745 131005d3a62d
child 7756 f9f8660de23f
permissions -rw-r--r--
accomodate markup commands;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
7752
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    10
  val token_source: (OuterLex.token * string option) list -> string
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    11
  val theory_entry: string -> string
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    12
end;
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    13
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    14
structure Latex: LATEX =
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    15
struct
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
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    18
(* symbol output *)
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
val output_chr = fn
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
  "\n" => "\\isanewline\n" |
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    23
  "$" => "\\$" |
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
  "{" => "{\\textbraceleft}" |
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    29
  "}" => "{\\textbraceright}" |
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    30
  "~" => "{\\textasciitilde}" |
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    31
  "^" => "{\\textasciicircum}" |
7752
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    32
  "\"" => "{\"}" |
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    33
(*  "\\" => "{\\textbackslash}" |  FIXME *)
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    34
  "\\" => "\\verb,\\," |
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    35
  "|" => "{|}" |
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    36
  "<" => "{<}" |
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    37
  ">" => "{>}" |
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    38
  c => c;
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
(* FIXME replace \<forall> etc. *)
7752
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    42
val output_sym = implode o map output_chr o explode;
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    43
val output_symbols = map output_sym;
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    44
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    45
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    46
(* token output *)
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    47
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    48
structure T = OuterLex;
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    49
7752
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    50
fun output_tok (tok, Some s) = "\\isamarkup" ^ T.val_of tok ^ "{" ^ s ^ "}"
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    51
  | output_tok (tok, None) =
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    52
      let val s = T.val_of tok in
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    53
        if T.is_kind T.Command tok then "\\isacommand{" ^ output_sym s ^ "}"
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    54
        else if T.is_kind T.Keyword tok then "\\isakeyword{" ^ output_sym s ^ "}"
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    55
        else if T.is_kind T.String tok then output_sym (quote s)
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    56
        else if T.is_kind T.Verbatim tok then output_sym (enclose "{*" "*}" s)
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    57
        else output_sym s
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    58
      end;
7745
131005d3a62d strip_blanks;
wenzelm
parents: 7726
diff changeset
    59
7752
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    60
val output_tokens = map output_tok;
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    61
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    62
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    63
(* theory presentation *)
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    64
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    65
fun token_source toks =
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    66
  "\\begin{isabellesimple}\n" ^ implode (output_tokens toks) ^ "\\end{isabellesimple}\n";
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    67
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    68
fun theory_entry name = "\\input{" ^ name ^ ".tex}\n";
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    69
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    70
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    71
end;