src/Pure/Thy/latex.ML
author wenzelm
Wed Oct 06 18:12:35 1999 +0200 (1999-10-06)
changeset 7756 f9f8660de23f
parent 7752 7ee322caf59c
child 7789 57d20133224e
permissions -rw-r--r--
improved presentation;
wenzelm@7726
     1
(*  Title:      Pure/Thy/latex.ML
wenzelm@7726
     2
    ID:         $Id$
wenzelm@7726
     3
    Author:     Markus Wenzel, TU Muenchen
wenzelm@7726
     4
wenzelm@7726
     5
Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm@7726
     6
*)
wenzelm@7726
     7
wenzelm@7726
     8
signature LATEX =
wenzelm@7726
     9
sig
wenzelm@7756
    10
  datatype token = Basic of OuterLex.token | Markup of string * string
wenzelm@7756
    11
  val token_source: token list -> string
wenzelm@7726
    12
  val theory_entry: string -> string
wenzelm@7726
    13
end;
wenzelm@7726
    14
wenzelm@7726
    15
structure Latex: LATEX =
wenzelm@7726
    16
struct
wenzelm@7726
    17
wenzelm@7726
    18
wenzelm@7726
    19
(* symbol output *)
wenzelm@7726
    20
wenzelm@7726
    21
val output_chr = fn
wenzelm@7726
    22
  " " => "~" |
wenzelm@7726
    23
  "\n" => "\\isanewline\n" |
wenzelm@7726
    24
  "$" => "\\$" |
wenzelm@7726
    25
  "&" => "\\&" |
wenzelm@7726
    26
  "%" => "\\%" |
wenzelm@7726
    27
  "#" => "\\#" |
wenzelm@7726
    28
  "_" => "\\_" |
wenzelm@7726
    29
  "{" => "{\\textbraceleft}" |
wenzelm@7726
    30
  "}" => "{\\textbraceright}" |
wenzelm@7726
    31
  "~" => "{\\textasciitilde}" |
wenzelm@7726
    32
  "^" => "{\\textasciicircum}" |
wenzelm@7752
    33
  "\"" => "{\"}" |
wenzelm@7752
    34
  "\\" => "\\verb,\\," |
wenzelm@7726
    35
  c => c;
wenzelm@7726
    36
wenzelm@7756
    37
val output_chr' = fn
wenzelm@7756
    38
  "\\" => "{\\textbackslash}" |
wenzelm@7756
    39
  "|" => "{\\textbar}" |
wenzelm@7756
    40
  "<" => "{\\textless}" |
wenzelm@7756
    41
  ">" => "{\\textgreater}" |
wenzelm@7756
    42
  c => output_chr c;
wenzelm@7756
    43
wenzelm@7726
    44
wenzelm@7726
    45
(* FIXME replace \<forall> etc. *)
wenzelm@7752
    46
val output_sym = implode o map output_chr o explode;
wenzelm@7756
    47
val output_sym' = implode o map output_chr' o explode;
wenzelm@7726
    48
wenzelm@7726
    49
wenzelm@7726
    50
(* token output *)
wenzelm@7726
    51
wenzelm@7726
    52
structure T = OuterLex;
wenzelm@7726
    53
wenzelm@7756
    54
datatype token = Basic of T.token | Markup of string * string;
wenzelm@7756
    55
wenzelm@7756
    56
wenzelm@7756
    57
val invisible_token = T.keyword_with (equal ";") orf T.is_kind T.Comment;
wenzelm@7756
    58
wenzelm@7756
    59
fun strip_blanks s =
wenzelm@7756
    60
  implode (#1 (Library.take_suffix Symbol.is_blank
wenzelm@7756
    61
    (#2 (Library.take_prefix Symbol.is_blank (explode s)))));
wenzelm@7756
    62
wenzelm@7756
    63
fun output_tok (Basic tok) =
wenzelm@7752
    64
      let val s = T.val_of tok in
wenzelm@7756
    65
        if invisible_token tok then ""
wenzelm@7756
    66
        else if T.is_kind T.Command tok then "\\isacommand{" ^ output_sym' s ^ "}"
wenzelm@7756
    67
        else if T.is_kind T.Keyword tok then "\\isakeyword{" ^ output_sym' s ^ "}"
wenzelm@7752
    68
        else if T.is_kind T.String tok then output_sym (quote s)
wenzelm@7752
    69
        else if T.is_kind T.Verbatim tok then output_sym (enclose "{*" "*}" s)
wenzelm@7752
    70
        else output_sym s
wenzelm@7756
    71
      end
wenzelm@7756
    72
  | output_tok (Markup (cmd, arg)) = "\n\\isamarkup" ^ cmd ^ "{" ^ strip_blanks arg ^ "}\n";
wenzelm@7745
    73
wenzelm@7756
    74
wenzelm@7756
    75
val output_tokens = implode o map output_tok;
wenzelm@7726
    76
wenzelm@7726
    77
wenzelm@7726
    78
(* theory presentation *)
wenzelm@7726
    79
wenzelm@7726
    80
fun token_source toks =
wenzelm@7756
    81
  "\\begin{isabellesimple}\n" ^ output_tokens toks ^ "\\end{isabellesimple}\n";
wenzelm@7726
    82
wenzelm@7726
    83
fun theory_entry name = "\\input{" ^ name ^ ".tex}\n";
wenzelm@7726
    84
wenzelm@7726
    85
wenzelm@7726
    86
end;