src/Pure/Thy/latex.ML
author wenzelm
Thu, 07 Oct 1999 17:20:58 +0200
changeset 7789 57d20133224e
parent 7756 f9f8660de23f
child 7800 8ee919e42174
permissions -rw-r--r--
verbatim markup tokens;
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
7789
57d20133224e verbatim markup tokens;
wenzelm
parents: 7756
diff changeset
    10
  datatype token = Basic of OuterLex.token | Markup of string * string | Verbatim of string
7756
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    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
  "_" => "\\_" |
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    29
  "{" => "{\\textbraceleft}" |
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    30
  "}" => "{\\textbraceright}" |
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    31
  "~" => "{\\textasciitilde}" |
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    32
  "^" => "{\\textasciicircum}" |
7752
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    33
  "\"" => "{\"}" |
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    34
  "\\" => "\\verb,\\," |
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
7756
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    37
val output_chr' = fn
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    38
  "\\" => "{\\textbackslash}" |
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    39
  "|" => "{\\textbar}" |
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    40
  "<" => "{\\textless}" |
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    41
  ">" => "{\\textgreater}" |
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    42
  c => output_chr c;
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    43
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
(* FIXME replace \<forall> etc. *)
7752
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    46
val output_sym = implode o map output_chr o explode;
7756
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    47
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
    48
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    49
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    50
(* token output *)
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    51
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    52
structure T = OuterLex;
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    53
7789
57d20133224e verbatim markup tokens;
wenzelm
parents: 7756
diff changeset
    54
datatype token = Basic of T.token | Markup of string * string | Verbatim of string;
7756
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    55
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    56
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    57
val invisible_token = T.keyword_with (equal ";") orf T.is_kind T.Comment;
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    58
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    59
fun strip_blanks s =
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    60
  implode (#1 (Library.take_suffix Symbol.is_blank
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    61
    (#2 (Library.take_prefix Symbol.is_blank (explode s)))));
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    62
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    63
fun output_tok (Basic tok) =
7752
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    64
      let val s = T.val_of tok in
7756
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    65
        if invisible_token tok then ""
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    66
        else if T.is_kind T.Command tok then "\\isacommand{" ^ output_sym' s ^ "}"
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    67
        else if T.is_kind T.Keyword tok then "\\isakeyword{" ^ output_sym' s ^ "}"
7752
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    68
        else if T.is_kind T.String tok then output_sym (quote s)
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    69
        else if T.is_kind T.Verbatim tok then output_sym (enclose "{*" "*}" s)
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    70
        else output_sym s
7756
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    71
      end
7789
57d20133224e verbatim markup tokens;
wenzelm
parents: 7756
diff changeset
    72
  | output_tok (Markup (cmd, arg)) = "\n\\isamarkup" ^ cmd ^ "{" ^ strip_blanks arg ^ "}\n"
57d20133224e verbatim markup tokens;
wenzelm
parents: 7756
diff changeset
    73
  | output_tok (Verbatim txt) = "\n" ^ txt ^ "\n";
7745
131005d3a62d strip_blanks;
wenzelm
parents: 7726
diff changeset
    74
7756
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    75
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    76
val output_tokens = implode o map output_tok;
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    77
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
(* theory presentation *)
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
fun token_source toks =
7756
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    82
  "\\begin{isabellesimple}\n" ^ output_tokens toks ^ "\\end{isabellesimple}\n";
7726
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
fun theory_entry name = "\\input{" ^ name ^ ".tex}\n";
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    85
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    86
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    87
end;