src/Pure/Thy/latex.ML
changeset 67145 e77c5bfca9aa
parent 66021 08ab52fb9db5
child 67173 e746db6db903
--- a/src/Pure/Thy/latex.ML	Wed Dec 06 09:11:27 2017 +0100
+++ b/src/Pure/Thy/latex.ML	Wed Dec 06 14:19:36 2017 +0100
@@ -6,6 +6,7 @@
 
 signature LATEX =
 sig
+  val output_name: string -> string
   val output_ascii: string -> string
   val latex_control: Symbol.symbol
   val is_latex_control: Symbol.symbol -> bool
@@ -13,6 +14,7 @@
   val output_known_symbols: (string -> bool) * (string -> bool) ->
     Symbol.symbol list -> string
   val output_symbols: Symbol.symbol list -> string
+  val output_syms: string -> string
   val output_token: Token.T -> string
   val begin_delim: string -> string
   val end_delim: string -> string
@@ -30,6 +32,27 @@
 structure Latex: LATEX =
 struct
 
+(* output name for LaTeX macros *)
+
+val output_name =
+  translate_string
+    (fn "_" => "UNDERSCORE"
+      | "'" => "PRIME"
+      | "0" => "ZERO"
+      | "1" => "ONE"
+      | "2" => "TWO"
+      | "3" => "THREE"
+      | "4" => "FOUR"
+      | "5" => "FIVE"
+      | "6" => "SIX"
+      | "7" => "SEVEN"
+      | "8" => "EIGHT"
+      | "9" => "NINE"
+      | s => s);
+
+fun enclose_name bg en = enclose bg en o output_name;
+
+
 (* output verbatim ASCII *)
 
 val output_ascii =
@@ -101,8 +124,8 @@
   (case Symbol.decode sym of
     Symbol.Char s => output_chr s
   | Symbol.UTF8 s => s
-  | Symbol.Sym s => if known_sym s then enclose "{\\isasym" "}" s else output_chrs sym
-  | Symbol.Control s => if known_ctrl s then enclose "\\isactrl" " " s else output_chrs sym
+  | Symbol.Sym s => if known_sym s then enclose_name "{\\isasym" "}" s else output_chrs sym
+  | Symbol.Control s => if known_ctrl s then enclose_name "\\isactrl" " " s else output_chrs sym
   | Symbol.Malformed s => error (Symbol.malformed_msg s)
   | Symbol.EOF => error "Bad EOF symbol");
 
@@ -173,16 +196,16 @@
 
 (* tags *)
 
-val begin_delim = enclose "%\n\\isadelim" "\n";
-val end_delim = enclose "%\n\\endisadelim" "\n";
-val begin_tag = enclose "%\n\\isatag" "\n";
-fun end_tag tg = enclose "%\n\\endisatag" "\n" tg ^ enclose "{\\isafold" "}%\n" tg;
+val begin_delim = enclose_name "%\n\\isadelim" "\n";
+val end_delim = enclose_name "%\n\\endisadelim" "\n";
+val begin_tag = enclose_name "%\n\\isatag" "\n";
+fun end_tag tg = enclose_name "%\n\\endisatag" "\n" tg ^ enclose "{\\isafold" "}%\n" tg;
 
 
 (* theory presentation *)
 
 fun environment name =
-  enclose ("%\n\\begin{" ^ name ^ "}%\n") ("%\n\\end{" ^ name ^ "}");
+  enclose ("%\n\\begin{" ^ output_name name ^ "}%\n") ("%\n\\end{" ^ output_name name ^ "}");
 
 val tex_trailer =
   "%%% Local Variables:\n\