src/Pure/Thy/latex.ML
author wenzelm
Sun, 18 Oct 2015 20:48:24 +0200
changeset 61475 5b58a17c440a
parent 61473 34d1913f0b20
child 61505 a4478ca660a5
permissions -rw-r--r--
tuned signature;
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
    Author:     Markus Wenzel, TU Muenchen
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
     3
15801
d2f5ca3c048d superceded by Pure.thy and CPure.thy;
wenzelm
parents: 14992
diff changeset
     4
LaTeX presentation elements -- based on outer lexical syntax.
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
     5
*)
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
signature LATEX =
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
     8
sig
58716
23a380cc45f4 official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents: 55828
diff changeset
     9
  val output_ascii: string -> string
14924
2be4cbe27a27 added output_known_symbols; tuned;
wenzelm
parents: 14879
diff changeset
    10
  val output_known_symbols: (string -> bool) * (string -> bool) ->
2be4cbe27a27 added output_known_symbols; tuned;
wenzelm
parents: 14879
diff changeset
    11
    Symbol.symbol list -> string
11719
49c14348a42b Exported output_symbols.
berghofe
parents: 11012
diff changeset
    12
  val output_symbols: Symbol.symbol list -> string
61404
a433fecc5ce2 allow control symbols within markup body;
wenzelm
parents: 59809
diff changeset
    13
  val output_ctrl_symbols: Symbol.symbol list -> string
61455
0e4c257358cf clarified modules;
wenzelm
parents: 61435
diff changeset
    14
  val output_token: Token.T -> string
17081
e19963723262 eliminated datatype token;
wenzelm
parents: 15801
diff changeset
    15
  val begin_delim: string -> string
e19963723262 eliminated datatype token;
wenzelm
parents: 15801
diff changeset
    16
  val end_delim: string -> string
e19963723262 eliminated datatype token;
wenzelm
parents: 15801
diff changeset
    17
  val begin_tag: string -> string
e19963723262 eliminated datatype token;
wenzelm
parents: 15801
diff changeset
    18
  val end_tag: string -> string
61462
e16649b70107 clarified Latex.environment;
wenzelm
parents: 61455
diff changeset
    19
  val environment: string -> string -> string
9707
067c25edd1bd added tex_trailer;
wenzelm
parents: 9668
diff changeset
    20
  val tex_trailer: string
58870
e2c0d8ef29cb more flexibile \setisabellecontext, independently of header;
wenzelm
parents: 58861
diff changeset
    21
  val isabelle_theory: string -> string -> string
14924
2be4cbe27a27 added output_known_symbols; tuned;
wenzelm
parents: 14879
diff changeset
    22
  val symbol_source: (string -> bool) * (string -> bool) ->
2be4cbe27a27 added output_known_symbols; tuned;
wenzelm
parents: 14879
diff changeset
    23
    string -> Symbol.symbol list -> string
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    24
  val theory_entry: string -> string
9135
3aa95ab3f02d adapted to improved presentation;
wenzelm
parents: 9038
diff changeset
    25
  val modes: string list
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    26
end;
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
structure Latex: LATEX =
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    29
struct
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    30
61455
0e4c257358cf clarified modules;
wenzelm
parents: 61435
diff changeset
    31
(* output verbatim ASCII *)
58716
23a380cc45f4 official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents: 55828
diff changeset
    32
23a380cc45f4 official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents: 55828
diff changeset
    33
val output_ascii =
23a380cc45f4 official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents: 55828
diff changeset
    34
  translate_string
23a380cc45f4 official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents: 55828
diff changeset
    35
    (fn " " => "\\ "
23a380cc45f4 official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents: 55828
diff changeset
    36
      | "\t" => "\\ "
23a380cc45f4 official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents: 55828
diff changeset
    37
      | "\n" => "\\isanewline\n"
23a380cc45f4 official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents: 55828
diff changeset
    38
      | s =>
58727
e3d0a6a012eb avoid odd ligatures;
wenzelm
parents: 58716
diff changeset
    39
          if exists_string (fn s' => s = s') "#$%^&_{}~\\<>"
58716
23a380cc45f4 official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents: 55828
diff changeset
    40
          then enclose "{\\char`\\" "}" s else s);
23a380cc45f4 official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents: 55828
diff changeset
    41
23a380cc45f4 official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents: 55828
diff changeset
    42
61455
0e4c257358cf clarified modules;
wenzelm
parents: 61435
diff changeset
    43
(* output symbols *)
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    44
7900
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    45
local
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
    46
40402
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    47
val char_table =
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    48
  Symtab.make
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    49
   [("!", "{\\isacharbang}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    50
    ("\"", "{\\isachardoublequote}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    51
    ("#", "{\\isacharhash}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    52
    ("$", "{\\isachardollar}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    53
    ("%", "{\\isacharpercent}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    54
    ("&", "{\\isacharampersand}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    55
    ("'", "{\\isacharprime}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    56
    ("(", "{\\isacharparenleft}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    57
    (")", "{\\isacharparenright}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    58
    ("*", "{\\isacharasterisk}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    59
    ("+", "{\\isacharplus}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    60
    (",", "{\\isacharcomma}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    61
    ("-", "{\\isacharminus}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    62
    (".", "{\\isachardot}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    63
    ("/", "{\\isacharslash}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    64
    (":", "{\\isacharcolon}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    65
    (";", "{\\isacharsemicolon}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    66
    ("<", "{\\isacharless}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    67
    ("=", "{\\isacharequal}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    68
    (">", "{\\isachargreater}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    69
    ("?", "{\\isacharquery}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    70
    ("@", "{\\isacharat}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    71
    ("[", "{\\isacharbrackleft}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    72
    ("\\", "{\\isacharbackslash}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    73
    ("]", "{\\isacharbrackright}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    74
    ("^", "{\\isacharcircum}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    75
    ("_", "{\\isacharunderscore}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    76
    ("`", "{\\isacharbackquote}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    77
    ("{", "{\\isacharbraceleft}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    78
    ("|", "{\\isacharbar}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    79
    ("}", "{\\isacharbraceright}"),
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    80
    ("~", "{\\isachartilde}")];
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    81
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    82
fun output_chr " " = "\\ "
43709
717e96cf9527 discontinued special treatment of hard tabulators;
wenzelm
parents: 43485
diff changeset
    83
  | output_chr "\t" = "\\ "
40402
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    84
  | output_chr "\n" = "\\isanewline\n"
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    85
  | output_chr c =
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    86
      (case Symtab.lookup char_table c of
49320
94bd2fb83d11 discontinued experiment with literal replacement text in PDF (cf. b646316f8b3c, 2ff10e613689);
wenzelm
parents: 48628
diff changeset
    87
        SOME s => s
40402
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
    88
      | NONE => if Symbol.is_ascii_digit c then enclose "{\\isadigit{" "}}" c else c);
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
    89
14924
2be4cbe27a27 added output_known_symbols; tuned;
wenzelm
parents: 14879
diff changeset
    90
val output_chrs = translate_string output_chr;
2be4cbe27a27 added output_known_symbols; tuned;
wenzelm
parents: 14879
diff changeset
    91
2be4cbe27a27 added output_known_symbols; tuned;
wenzelm
parents: 14879
diff changeset
    92
fun output_known_sym (known_sym, known_ctrl) sym =
14874
23c73484312f Symbol.decode;
wenzelm
parents: 14840
diff changeset
    93
  (case Symbol.decode sym of
23c73484312f Symbol.decode;
wenzelm
parents: 14840
diff changeset
    94
    Symbol.Char s => output_chr s
37533
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36959
diff changeset
    95
  | Symbol.UTF8 s => s
49320
94bd2fb83d11 discontinued experiment with literal replacement text in PDF (cf. b646316f8b3c, 2ff10e613689);
wenzelm
parents: 48628
diff changeset
    96
  | Symbol.Sym s => if known_sym s then enclose "{\\isasym" "}" s else output_chrs sym
61475
5b58a17c440a tuned signature;
wenzelm
parents: 61473
diff changeset
    97
  | Symbol.Control s => if known_ctrl s then enclose "\\isactrl" " " s else output_chrs sym
40523
1050315f6ee2 simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents: 40402
diff changeset
    98
  | Symbol.Raw s => s
43485
33a24212a72d more tolerant Symbol.decode;
wenzelm
parents: 42290
diff changeset
    99
  | Symbol.Malformed s => error (Symbol.malformed_msg s)
33a24212a72d more tolerant Symbol.decode;
wenzelm
parents: 42290
diff changeset
   100
  | Symbol.EOF => error "Bad EOF symbol");
7900
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
   101
61404
a433fecc5ce2 allow control symbols within markup body;
wenzelm
parents: 59809
diff changeset
   102
fun output_ctrl_sym sym =
a433fecc5ce2 allow control symbols within markup body;
wenzelm
parents: 59809
diff changeset
   103
  (case Symbol.decode sym of
61475
5b58a17c440a tuned signature;
wenzelm
parents: 61473
diff changeset
   104
    Symbol.Control s => enclose "\\isactrl" " " s
61404
a433fecc5ce2 allow control symbols within markup body;
wenzelm
parents: 59809
diff changeset
   105
  | _ => sym);
a433fecc5ce2 allow control symbols within markup body;
wenzelm
parents: 59809
diff changeset
   106
7900
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
   107
in
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
   108
14924
2be4cbe27a27 added output_known_symbols; tuned;
wenzelm
parents: 14879
diff changeset
   109
val output_known_symbols = implode oo (map o output_known_sym);
2be4cbe27a27 added output_known_symbols; tuned;
wenzelm
parents: 14879
diff changeset
   110
val output_symbols = output_known_symbols (K true, K true);
8192
45a7027136e3 added old_symbol_source;
wenzelm
parents: 8117
diff changeset
   111
val output_syms = output_symbols o Symbol.explode;
7900
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
   112
27874
f0364f1c0ecf antiquotes: proper SymbolPos decoding, adapted Antiquote.read/Antiq;
wenzelm
parents: 27809
diff changeset
   113
val output_syms_antiq =
30589
cbe27c4ef417 Antiquote.Text: keep full position information;
wenzelm
parents: 30573
diff changeset
   114
  (fn Antiquote.Text ss => output_symbols (map Symbol_Pos.symbol ss)
61473
34d1913f0b20 clarified control antiquotations: decode control symbol to get name;
wenzelm
parents: 61471
diff changeset
   115
    | Antiquote.Control {name = (name, _), body, ...} =>
34d1913f0b20 clarified control antiquotations: decode control symbol to get name;
wenzelm
parents: 61471
diff changeset
   116
        "\\isaantiqcontrol{" ^ output_symbols (Symbol.explode name) ^ "}" ^
34d1913f0b20 clarified control antiquotations: decode control symbol to get name;
wenzelm
parents: 61471
diff changeset
   117
        output_symbols (map Symbol_Pos.symbol body)
34d1913f0b20 clarified control antiquotations: decode control symbol to get name;
wenzelm
parents: 61471
diff changeset
   118
    | Antiquote.Antiq {body, ...} =>
40402
b646316f8b3c basic setup for literal replacement text in PDF, to support copy/paste of Isabelle symbols;
wenzelm
parents: 39666
diff changeset
   119
        enclose "%\n\\isaantiq\n" "{}%\n\\endisaantiq\n"
61473
34d1913f0b20 clarified control antiquotations: decode control symbol to get name;
wenzelm
parents: 61471
diff changeset
   120
          (output_symbols (map Symbol_Pos.symbol body)));
22648
8c6b4f7548e3 output_basic: added isaantiq markup (only inside verbatim tokens);
wenzelm
parents: 19265
diff changeset
   121
61404
a433fecc5ce2 allow control symbols within markup body;
wenzelm
parents: 59809
diff changeset
   122
val output_ctrl_symbols = implode o map output_ctrl_sym;
a433fecc5ce2 allow control symbols within markup body;
wenzelm
parents: 59809
diff changeset
   123
7900
e62973fccc97 output \isasymbols;
wenzelm
parents: 7852
diff changeset
   124
end;
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
   125
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
   126
61455
0e4c257358cf clarified modules;
wenzelm
parents: 61435
diff changeset
   127
(* output token *)
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
   128
61455
0e4c257358cf clarified modules;
wenzelm
parents: 61435
diff changeset
   129
fun output_token tok =
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 30642
diff changeset
   130
  let val s = Token.content_of tok in
58861
5ff61774df11 command-line terminator ";" is no longer accepted;
wenzelm
parents: 58727
diff changeset
   131
    if Token.is_kind Token.Comment tok then ""
46811
03a2dc9e0624 clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents: 45666
diff changeset
   132
    else if Token.is_command tok then
17081
e19963723262 eliminated datatype token;
wenzelm
parents: 15801
diff changeset
   133
      "\\isacommand{" ^ output_syms s ^ "}"
50238
98d35a7368bd more uniform Symbol.is_ascii_identifier in ML/Scala;
wenzelm
parents: 50201
diff changeset
   134
    else if Token.is_kind Token.Keyword tok andalso Symbol.is_ascii_identifier s then
17081
e19963723262 eliminated datatype token;
wenzelm
parents: 15801
diff changeset
   135
      "\\isakeyword{" ^ output_syms s ^ "}"
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 30642
diff changeset
   136
    else if Token.is_kind Token.String tok then
49320
94bd2fb83d11 discontinued experiment with literal replacement text in PDF (cf. b646316f8b3c, 2ff10e613689);
wenzelm
parents: 48628
diff changeset
   137
      enclose "{\\isachardoublequoteopen}" "{\\isachardoublequoteclose}" (output_syms s)
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59065
diff changeset
   138
    else if Token.is_kind Token.Alt_String tok then
49320
94bd2fb83d11 discontinued experiment with literal replacement text in PDF (cf. b646316f8b3c, 2ff10e613689);
wenzelm
parents: 48628
diff changeset
   139
      enclose "{\\isacharbackquoteopen}" "{\\isacharbackquoteclose}" (output_syms s)
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 30642
diff changeset
   140
    else if Token.is_kind Token.Verbatim tok then
27874
f0364f1c0ecf antiquotes: proper SymbolPos decoding, adapted Antiquote.read/Antiq;
wenzelm
parents: 27809
diff changeset
   141
      let
59809
87641097d0f3 tuned signature;
wenzelm
parents: 59123
diff changeset
   142
        val ants = Antiquote.read (Token.input_of tok);
27874
f0364f1c0ecf antiquotes: proper SymbolPos decoding, adapted Antiquote.read/Antiq;
wenzelm
parents: 27809
diff changeset
   143
        val out = implode (map output_syms_antiq ants);
49320
94bd2fb83d11 discontinued experiment with literal replacement text in PDF (cf. b646316f8b3c, 2ff10e613689);
wenzelm
parents: 48628
diff changeset
   144
      in enclose "{\\isacharverbatimopen}" "{\\isacharverbatimclose}" out end
55033
8e8243975860 support for nested text cartouches;
wenzelm
parents: 53167
diff changeset
   145
    else if Token.is_kind Token.Cartouche tok then
8e8243975860 support for nested text cartouches;
wenzelm
parents: 53167
diff changeset
   146
      enclose "{\\isacartoucheopen}" "{\\isacartoucheclose}" (output_syms s)
17081
e19963723262 eliminated datatype token;
wenzelm
parents: 15801
diff changeset
   147
    else output_syms s
61404
a433fecc5ce2 allow control symbols within markup body;
wenzelm
parents: 59809
diff changeset
   148
  end handle ERROR msg => error (msg ^ Position.here (Token.pos_of tok));
17081
e19963723262 eliminated datatype token;
wenzelm
parents: 15801
diff changeset
   149
61404
a433fecc5ce2 allow control symbols within markup body;
wenzelm
parents: 59809
diff changeset
   150
61455
0e4c257358cf clarified modules;
wenzelm
parents: 61435
diff changeset
   151
(* tags *)
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
   152
17081
e19963723262 eliminated datatype token;
wenzelm
parents: 15801
diff changeset
   153
val begin_delim = enclose "%\n\\isadelim" "\n";
e19963723262 eliminated datatype token;
wenzelm
parents: 15801
diff changeset
   154
val end_delim = enclose "%\n\\endisadelim" "\n";
e19963723262 eliminated datatype token;
wenzelm
parents: 15801
diff changeset
   155
val begin_tag = enclose "%\n\\isatag" "\n";
e19963723262 eliminated datatype token;
wenzelm
parents: 15801
diff changeset
   156
fun end_tag tg = enclose "%\n\\endisatag" "\n" tg ^ enclose "{\\isafold" "}%\n" tg;
11860
36ba0d4a836c flag_markup;
wenzelm
parents: 11719
diff changeset
   157
36ba0d4a836c flag_markup;
wenzelm
parents: 11719
diff changeset
   158
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
   159
(* theory presentation *)
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
   160
61462
e16649b70107 clarified Latex.environment;
wenzelm
parents: 61455
diff changeset
   161
fun environment name =
e16649b70107 clarified Latex.environment;
wenzelm
parents: 61455
diff changeset
   162
  enclose ("%\n\\begin{" ^ name ^ "}%\n") ("%\n\\end{" ^ name ^ "}%\n");
e16649b70107 clarified Latex.environment;
wenzelm
parents: 61455
diff changeset
   163
9707
067c25edd1bd added tex_trailer;
wenzelm
parents: 9668
diff changeset
   164
val tex_trailer =
067c25edd1bd added tex_trailer;
wenzelm
parents: 9668
diff changeset
   165
  "%%% Local Variables:\n\
9135
3aa95ab3f02d adapted to improved presentation;
wenzelm
parents: 9038
diff changeset
   166
  \%%% mode: latex\n\
3aa95ab3f02d adapted to improved presentation;
wenzelm
parents: 9038
diff changeset
   167
  \%%% TeX-master: \"root\"\n\
9144
wenzelm
parents: 9135
diff changeset
   168
  \%%% End:\n";
8192
45a7027136e3 added old_symbol_source;
wenzelm
parents: 8117
diff changeset
   169
58870
e2c0d8ef29cb more flexibile \setisabellecontext, independently of header;
wenzelm
parents: 58861
diff changeset
   170
fun isabelle_theory name txt =
9916
4a703366494b define \isabellecontext;
wenzelm
parents: 9749
diff changeset
   171
  "%\n\\begin{isabellebody}%\n\
58870
e2c0d8ef29cb more flexibile \setisabellecontext, independently of header;
wenzelm
parents: 58861
diff changeset
   172
  \\\setisabellecontext{" ^ output_syms name ^ "}%\n" ^ txt ^
61462
e16649b70107 clarified Latex.environment;
wenzelm
parents: 61455
diff changeset
   173
  "%\n\\end{isabellebody}%\n" ^ tex_trailer;
9707
067c25edd1bd added tex_trailer;
wenzelm
parents: 9668
diff changeset
   174
58870
e2c0d8ef29cb more flexibile \setisabellecontext, independently of header;
wenzelm
parents: 58861
diff changeset
   175
fun symbol_source known name syms =
e2c0d8ef29cb more flexibile \setisabellecontext, independently of header;
wenzelm
parents: 58861
diff changeset
   176
  isabelle_theory name
e2c0d8ef29cb more flexibile \setisabellecontext, independently of header;
wenzelm
parents: 58861
diff changeset
   177
    ("\\isamarkupfile{" ^ output_known_symbols known (Symbol.explode name) ^ "}%\n" ^
e2c0d8ef29cb more flexibile \setisabellecontext, independently of header;
wenzelm
parents: 58861
diff changeset
   178
      output_known_symbols known syms);
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
   179
9038
63d20536971f session.tex: nsert blank lines in order to guarantee new paragraphs
wenzelm
parents: 8965
diff changeset
   180
fun theory_entry name = "\\input{" ^ name ^ ".tex}\n\n";
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
   181
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
   182
8460
274426d1adbc tuned comments;
wenzelm
parents: 8192
diff changeset
   183
(* print mode *)
274426d1adbc tuned comments;
wenzelm
parents: 8192
diff changeset
   184
8965
d46b36785c70 proper token_translation for latex mode;
wenzelm
parents: 8896
diff changeset
   185
val latexN = "latex";
17218
64242b791c19 removed obsolete 'symbols' mode;
wenzelm
parents: 17186
diff changeset
   186
val modes = [latexN, Symbol.xsymbolsN];
8965
d46b36785c70 proper token_translation for latex mode;
wenzelm
parents: 8896
diff changeset
   187
8460
274426d1adbc tuned comments;
wenzelm
parents: 8192
diff changeset
   188
fun latex_output str =
274426d1adbc tuned comments;
wenzelm
parents: 8192
diff changeset
   189
  let val syms = Symbol.explode str
23621
e070a6ab1891 simplified pretty token metric: type int;
wenzelm
parents: 22648
diff changeset
   190
  in (output_symbols syms, Symbol.length syms) end;
19265
cae36e16f3c0 Output.add_mode: keyword component;
wenzelm
parents: 17218
diff changeset
   191
23621
e070a6ab1891 simplified pretty token metric: type int;
wenzelm
parents: 22648
diff changeset
   192
fun latex_markup (s, _) =
59123
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59081
diff changeset
   193
  if s = Markup.commandN orelse s = Markup.keyword1N orelse s = Markup.keyword3N
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59081
diff changeset
   194
  then ("\\isacommand{", "}")
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59081
diff changeset
   195
  else if s = Markup.keyword2N
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59081
diff changeset
   196
  then ("\\isakeyword{", "}")
29325
a205acc94356 Markup.no_output;
wenzelm
parents: 28375
diff changeset
   197
  else Markup.no_output;
10955
36741b4fe109 setuo indent: \isaindent;
wenzelm
parents: 10393
diff changeset
   198
23621
e070a6ab1891 simplified pretty token metric: type int;
wenzelm
parents: 22648
diff changeset
   199
fun latex_indent "" _ = ""
e070a6ab1891 simplified pretty token metric: type int;
wenzelm
parents: 22648
diff changeset
   200
  | latex_indent s _ = enclose "\\isaindent{" "}" s;
e070a6ab1891 simplified pretty token metric: type int;
wenzelm
parents: 22648
diff changeset
   201
e070a6ab1891 simplified pretty token metric: type int;
wenzelm
parents: 22648
diff changeset
   202
val _ = Output.add_mode latexN latex_output Symbol.encode_raw;
23703
1b6a2c119151 Markup.add_mode;
wenzelm
parents: 23621
diff changeset
   203
val _ = Markup.add_mode latexN latex_markup;
1b6a2c119151 Markup.add_mode;
wenzelm
parents: 23621
diff changeset
   204
val _ = Pretty.add_mode latexN latex_indent;
8460
274426d1adbc tuned comments;
wenzelm
parents: 8192
diff changeset
   205
7726
2c7fc0ba1e12 Simple LaTeX presentation primitives (based on outer lexical syntax).
wenzelm
parents:
diff changeset
   206
end;