src/Pure/Thy/latex.ML
author wenzelm
Fri, 04 Feb 2000 21:44:38 +0100
changeset 8192 45a7027136e3
parent 8117 0a6173c9b2d0
child 8460 274426d1adbc
permissions -rw-r--r--
added old_symbol_source; tuned;
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
8192
45a7027136e3 added old_symbol_source;
wenzelm
parents: 8117
diff changeset
    11
  val old_symbol_source: Symbol.symbol list -> string
7756
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    12
  val token_source: token list -> string
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    13
  val theory_entry: string -> string
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    14
end;
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    15
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    16
structure Latex: LATEX =
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    17
struct
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
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    20
(* symbol output *)
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    21
7900
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    22
local
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    23
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    24
val output_chr = fn
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
  "\n" => "\\isanewline\n" |
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
  "%" => "\\%" |
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    30
  "#" => "\\#" |
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    31
  "_" => "\\_" |
7800
8ee919e42174 improved presentation;
wenzelm
parents: 7789
diff changeset
    32
  "{" => "{\\isabraceleft}" |
8ee919e42174 improved presentation;
wenzelm
parents: 7789
diff changeset
    33
  "}" => "{\\isabraceright}" |
8ee919e42174 improved presentation;
wenzelm
parents: 7789
diff changeset
    34
  "~" => "{\\isatilde}" |
8ee919e42174 improved presentation;
wenzelm
parents: 7789
diff changeset
    35
  "^" => "{\\isacircum}" |
7752
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    36
  "\"" => "{\"}" |
7800
8ee919e42174 improved presentation;
wenzelm
parents: 7789
diff changeset
    37
  "\\" => "{\\isabackslash}" |
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
7900
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    40
fun output_sym s =
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    41
  if size s = 1 then output_chr s
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    42
  else
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    43
    (case explode s of
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    44
      cs as "\\" :: "<" :: "^" :: _ => implode (map output_chr cs)
7973
0d801c6e4dc0 \isasymbol renamed to \isasym;
wenzelm
parents: 7900
diff changeset
    45
    | "\\" :: "<" :: cs => "{\\isasym" ^ implode (#1 (Library.split_last cs)) ^ "}"
7900
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    46
    | _ => sys_error "output_sym");
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    47
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    48
in
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    49
8192
45a7027136e3 added old_symbol_source;
wenzelm
parents: 8117
diff changeset
    50
val output_symbols = implode o map output_sym;
45a7027136e3 added old_symbol_source;
wenzelm
parents: 8117
diff changeset
    51
val output_syms = output_symbols o Symbol.explode;
7900
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    52
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    53
end;
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    54
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    55
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    56
(* token output *)
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    57
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    58
structure T = OuterLex;
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    59
7789
57d20133224e verbatim markup tokens;
wenzelm
parents: 7756
diff changeset
    60
datatype token = Basic of T.token | Markup of string * string | Verbatim of string;
7756
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    61
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    62
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    63
val invisible_token = T.keyword_with (equal ";") orf T.is_kind T.Comment;
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    64
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    65
fun strip_blanks s =
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    66
  implode (#1 (Library.take_suffix Symbol.is_blank
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    67
    (#2 (Library.take_prefix Symbol.is_blank (explode s)))));
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    68
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    69
fun output_tok (Basic tok) =
7752
7ee322caf59c accomodate markup commands;
wenzelm
parents: 7745
diff changeset
    70
      let val s = T.val_of tok in
7756
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    71
        if invisible_token tok then ""
7800
8ee919e42174 improved presentation;
wenzelm
parents: 7789
diff changeset
    72
        else if T.is_kind T.Command tok then
8ee919e42174 improved presentation;
wenzelm
parents: 7789
diff changeset
    73
          if s = "{{" then "{\\isabeginblock}"
8ee919e42174 improved presentation;
wenzelm
parents: 7789
diff changeset
    74
          else if s = "}}" then "{\\isaendblock}"
7900
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    75
          else "\\isacommand{" ^ output_syms s ^ "}"
7800
8ee919e42174 improved presentation;
wenzelm
parents: 7789
diff changeset
    76
        else if T.is_kind T.Keyword tok andalso Syntax.is_identifier s then
7900
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    77
          "\\isakeyword{" ^ output_syms s ^ "}"
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    78
        else if T.is_kind T.String tok then output_syms (quote s)
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    79
        else if T.is_kind T.Verbatim tok then output_syms (enclose "{*" "*}" s)
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    80
        else output_syms s
7756
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    81
      end
7852
d28dff7ac48d markup / varbatim: comment out (%) newline char;
wenzelm
parents: 7800
diff changeset
    82
  | output_tok (Markup (cmd, txt)) = "%\n\\isamarkup" ^ cmd ^ "{" ^ strip_blanks txt ^ "}\n"
d28dff7ac48d markup / varbatim: comment out (%) newline char;
wenzelm
parents: 7800
diff changeset
    83
  | output_tok (Verbatim txt) = "%\n" ^ strip_blanks txt ^ "\n";
7745
131005d3a62d strip_blanks;
wenzelm
parents: 7726
diff changeset
    84
7756
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    85
f9f8660de23f improved presentation;
wenzelm
parents: 7752
diff changeset
    86
val output_tokens = implode o map output_tok;
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    87
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    88
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    89
(* theory presentation *)
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    90
8192
45a7027136e3 added old_symbol_source;
wenzelm
parents: 8117
diff changeset
    91
val isabelle_simple = enclose "\\begin{isabellesimple}%\n" "\\end{isabellesimple}%\n";
45a7027136e3 added old_symbol_source;
wenzelm
parents: 8117
diff changeset
    92
45a7027136e3 added old_symbol_source;
wenzelm
parents: 8117
diff changeset
    93
val old_symbol_source = isabelle_simple o output_symbols;
45a7027136e3 added old_symbol_source;
wenzelm
parents: 8117
diff changeset
    94
val token_source = isabelle_simple o output_tokens;
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    95
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    96
fun theory_entry name = "\\input{" ^ name ^ ".tex}\n";
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    97
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    98
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    99
end;