PR#5497: better handling of special characters in printed code
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12177 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
f824b6a46c
commit
fd515e3a16
|
@ -86,77 +86,87 @@ class text =
|
|||
"\\"^sec^"{"^s^"}\n"
|
||||
with Not_found -> s
|
||||
|
||||
(** Associations of strings to subsitute in latex code. *)
|
||||
val mutable subst_strings = [
|
||||
("MAXENCE"^"ZZZ", "\\$");
|
||||
("MAXENCE"^"YYY", "\\&");
|
||||
("MAXENCE"^"XXX", "{\\textbackslash}") ;
|
||||
("à", "\\`a") ;
|
||||
("â", "\\^a") ;
|
||||
("é", "\\'e") ;
|
||||
("è", "\\`e") ;
|
||||
("ê", "\\^e") ;
|
||||
("ë", "\\\"e") ;
|
||||
("ç", "\\c{c}") ;
|
||||
("ô", "\\^o") ;
|
||||
("ö", "\\\"o") ;
|
||||
("î", "\\^i") ;
|
||||
("ï", "\\\"i") ;
|
||||
("ù", "\\`u") ;
|
||||
("û", "\\^u") ;
|
||||
("%", "\\%") ;
|
||||
("_", "\\_");
|
||||
("\\.\\.\\.", "$\\ldots$");
|
||||
("~", "\\~{}");
|
||||
("#", "\\verb`#`");
|
||||
("}", "\\}");
|
||||
("{", "\\{");
|
||||
("&", "\\&");
|
||||
(">", "$>$");
|
||||
("<", "$<$");
|
||||
("=", "$=$");
|
||||
(">=", "$\\geq$");
|
||||
("<=", "$\\leq$");
|
||||
("->", "$\\rightarrow$") ;
|
||||
("<-", "$\\leftarrow$");
|
||||
("|", "\\textbar ");
|
||||
("\\^", "\\textasciicircum ") ;
|
||||
("\\.\\.\\.", "$\\ldots$");
|
||||
("\\\\", "MAXENCE"^"XXX") ;
|
||||
("&", "MAXENCE"^"YYY") ;
|
||||
("\\$", "MAXENCE"^"ZZZ");
|
||||
]
|
||||
|
||||
val mutable subst_strings_simple =
|
||||
(** Associations of strings to substitute in latex code. *)
|
||||
val subst_strings = List.map (fun (x, y) -> (Str.regexp x, y))
|
||||
[
|
||||
("MAXENCE"^"XXX", "{\\textbackslash}") ;
|
||||
"}", "\\}" ;
|
||||
"{", "\\{" ;
|
||||
("\\\\", "MAXENCE"^"XXX") ;
|
||||
"\001", "\001\002";
|
||||
"\\\\", "\001b";
|
||||
|
||||
"{", "\\\\{";
|
||||
"}", "\\\\}";
|
||||
"\\$", "\\\\$";
|
||||
"\\^", "{\\\\textasciicircum}";
|
||||
"à", "\\\\`a";
|
||||
"â", "\\\\^a";
|
||||
"é", "\\\\'e";
|
||||
"è", "\\\\`e";
|
||||
"ê", "\\\\^e";
|
||||
"ë", "\\\\\"e";
|
||||
"ç", "\\\\c{c}";
|
||||
"ô", "\\\\^o";
|
||||
"ö", "\\\\\"o";
|
||||
"î", "\\\\^i";
|
||||
"ï", "\\\\\"i";
|
||||
"ù", "\\\\`u";
|
||||
"û", "\\\\^u";
|
||||
"%", "\\\\%";
|
||||
"_", "\\\\_";
|
||||
"~", "\\\\~{}";
|
||||
"#", "{\\char35}";
|
||||
"->", "$\\\\rightarrow$";
|
||||
"<-", "$\\\\leftarrow$";
|
||||
">=", "$\\\\geq$";
|
||||
"<=", "$\\\\leq$";
|
||||
">", "$>$";
|
||||
"<", "$<$";
|
||||
"=", "$=$";
|
||||
"|", "{\\\\textbar}";
|
||||
"\\.\\.\\.", "$\\\\ldots$";
|
||||
"&", "\\\\&";
|
||||
|
||||
"\001b", "{\\\\char92}";
|
||||
"\001\002", "\001";
|
||||
]
|
||||
|
||||
val mutable subst_strings_code = [
|
||||
("MAXENCE"^"ZZZ", "\\$");
|
||||
("MAXENCE"^"YYY", "\\&");
|
||||
("MAXENCE"^"XXX", "{\\textbackslash}") ;
|
||||
("%", "\\%") ;
|
||||
("_", "\\_");
|
||||
("~", "\\~{}");
|
||||
("#", "\\verb`#`");
|
||||
("}", "\\}");
|
||||
("{", "\\{");
|
||||
("&", "\\&");
|
||||
("\\^", "\\textasciicircum ") ;
|
||||
("&", "MAXENCE"^"YYY") ;
|
||||
("\\$", "MAXENCE"^"ZZZ") ;
|
||||
("\\\\", "MAXENCE"^"XXX") ;
|
||||
]
|
||||
val subst_strings_simple = List.map (fun (x, y) -> (Str.regexp x, y))
|
||||
[
|
||||
"\001", "\001\002";
|
||||
"\\\\", "\001b";
|
||||
"{", "\001l";
|
||||
|
||||
"}", "{\\\\char125}";
|
||||
"'", "{\\\\textquotesingle}";
|
||||
"`", "{\\\\textasciigrave}";
|
||||
|
||||
"\001b", "{\\\\char92}";
|
||||
"\001l", "{\\\\char123}";
|
||||
"\001\002", "\001";
|
||||
]
|
||||
|
||||
val subst_strings_code = List.map (fun (x, y) -> (Str.regexp x, y))
|
||||
[
|
||||
"\001", "\001\002";
|
||||
"\\\\", "\001b";
|
||||
"{", "\001l";
|
||||
|
||||
"}", "{\\\\char125}";
|
||||
"'", "{\\\\textquotesingle}";
|
||||
"`", "{\\\\textasciigrave}";
|
||||
"%", "\\\\%";
|
||||
"_", "\\\\_";
|
||||
"~", "{\\\\char126}";
|
||||
"#", "{\\\\char35}";
|
||||
"&", "\\\\&";
|
||||
"\\$", "\\\\$";
|
||||
"\\^", "{\\\\char94}";
|
||||
|
||||
"\001b", "{\\\\char92}";
|
||||
"\001l", "{\\\\char123}";
|
||||
"\001\002", "\001";
|
||||
]
|
||||
|
||||
method subst l s =
|
||||
List.fold_right
|
||||
(fun (s, s2) -> fun acc -> Str.global_replace (Str.regexp s) s2 acc)
|
||||
l
|
||||
s
|
||||
List.fold_left (fun acc (re, st) -> Str.global_replace re st acc) s l
|
||||
|
||||
(** Escape the strings which would clash with LaTeX syntax. *)
|
||||
method escape s = self#subst subst_strings s
|
||||
|
@ -1112,6 +1122,7 @@ class latex =
|
|||
ps fmt "\\documentclass[11pt]{article} \n";
|
||||
ps fmt "\\usepackage[latin1]{inputenc} \n";
|
||||
ps fmt "\\usepackage[T1]{fontenc} \n";
|
||||
ps fmt "\\usepackage{textcomp}\n";
|
||||
ps fmt "\\usepackage{fullpage} \n";
|
||||
ps fmt "\\usepackage{url} \n";
|
||||
ps fmt "\\usepackage{ocamldoc}\n";
|
||||
|
|
Loading…
Reference in New Issue