From dbe0a339de744ee55981de937a0d28bf10e4a369 Mon Sep 17 00:00:00 2001 From: Nicholas Longo Date: Tue, 26 Apr 2011 18:17:23 +0000 Subject: [PATCH] The following changes enhance the way texvc handles space around mathematical function names when translating to HTML; adds support for the sen, the Spanish name for sin; and corrects a bug that eliminates spacing around \operatorname{...} in the resulting png. More specifically, texvc now dectect whether or not a standard function such as is followed by a delimitier such as (, {, [ etc. and adds a space or not as appropriate. This issue The code has been reorganized to include a list of standard LaTeX commands whose spacing rules are the same, and treates them all on an equal footing. It similarly treats functions defined for mediawiki in the same way it treats standard latex functions. One addition function is added, \sen, and others can be added easily if necessary. Finally LaTeX generated by texvc contained to many braces which altered the spacing created by the command \operatorname, this has now been corrected. These last two changes address the issues raised in bug 18912 and the chaning in translation to HTML address most, but not all, of the issues raised in bug 6722 . --- math/lexer.mll | 10 ++++++++++ math/texutil.ml | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/math/lexer.mll b/math/lexer.mll index 1702084c5..cc035d706 100644 --- a/math/lexer.mll +++ b/math/lexer.mll @@ -13,6 +13,8 @@ let literal_uf_op = ['+' '-' '*' '='] let delimiter_uf_op = ['/' '|'] let boxchars = ['0'-'9' 'a'-'z' 'A'-'Z' '+' '-' '*' ',' '=' '(' ')' ':' '/' ';' '?' '.' '!' ' ' '\128'-'\255'] let aboxchars = ['0'-'9' 'a'-'z' 'A'-'Z' '+' '-' '*' ',' '=' '(' ')' ':' '/' ';' '?' '.' '!' ' '] +let latex_function_names = "arccos"| "arcsin" | "arctan" | "arg" | "cos" | "cosh" | "cot" | "coth" | "csc"| "deg" | "det" | "dim" | "exp" | "gcd" | "hom" | "inf" | "ker" | "lg" | "lim" | "liminf" | "limsup" | "ln" | "log" | "max" | "min" | "Pr" | "sec" | "sin" | "sinh" | "sup" | "tan" | "tanh" +let mediawiki_function_names = "arccot" | "arcsec" | "arccsc" | "sgn" | "sen" rule token = parse space + { token lexbuf } @@ -58,6 +60,14 @@ rule token = parse | "\\sqrt" space * "[" { FUN_AR1opt "\\sqrt" } | "\\xleftarrow" space * "[" { Texutil.tex_use_ams(); FUN_AR1opt "\\xleftarrow" } | "\\xrightarrow" space * "[" { Texutil.tex_use_ams(); FUN_AR1opt "\\xrightarrow" } + | "\\" (latex_function_names as name) space * "(" { LITERAL (HTMLABLEC(FONT_UFH,"\\" ^ name ^ "(", name ^ "(")) } + | "\\" (latex_function_names as name) space * "[" { LITERAL (HTMLABLEC(FONT_UFH,"\\" ^ name ^ "[", name ^ "[")) } + | "\\" (latex_function_names as name) space * "\\{" { LITERAL (HTMLABLEC(FONT_UFH,"\\" ^ name ^ "\\{", name ^ "{")) } + | "\\" (latex_function_names as name) space * { LITERAL (HTMLABLEC(FONT_UFH,"\\" ^ name, name ^ " ")) } + | "\\" (mediawiki_function_names as name) space * "(" { (Texutil.tex_use_ams(); LITERAL (HTMLABLEC(FONT_UFH,"\\operatorname{" ^ name ^ "}(", name^ "("))) } + | "\\" (mediawiki_function_names as name) space * "[" { (Texutil.tex_use_ams(); LITERAL (HTMLABLEC(FONT_UFH,"\\operatorname{" ^ name ^ "}[", name^ "["))) } + | "\\" (mediawiki_function_names as name) space * "\\{" { (Texutil.tex_use_ams(); LITERAL (HTMLABLEC(FONT_UFH,"\\operatorname{" ^ name ^ "}\\{", name^ "{"))) } + | "\\" (mediawiki_function_names as name) space * { (Texutil.tex_use_ams(); LITERAL (HTMLABLEC(FONT_UFH,"\\operatorname{" ^ name ^ "}", name ^ " "))) } | "\\," { LITERAL (HTMLABLE (FONT_UF, "\\,"," ")) } | "\\ " { LITERAL (HTMLABLE (FONT_UF, "\\ "," ")) } | "\\;" { LITERAL (HTMLABLE (FONT_UF, "\\;"," ")) } diff --git a/math/texutil.ml b/math/texutil.ml index cc7f48faa..1ed4aca04 100644 --- a/math/texutil.ml +++ b/math/texutil.ml @@ -20,7 +20,7 @@ let rec render_tex = function | TEX_DQN (a) -> "_{" ^ (render_tex a) ^ "}" | TEX_UQN (a) -> "^{" ^ (render_tex a) ^ "}" | TEX_LITERAL s -> tex_part s - | TEX_FUN1 (f,a) -> "{" ^ f ^ " " ^ (render_tex a) ^ "}" + | TEX_FUN1 (f,a) -> f ^ " " ^ (render_tex a) | TEX_FUN1hl (f,_,a) -> "{" ^ f ^ " " ^ (render_tex a) ^ "}" | TEX_FUN1hf (f,_,a) -> "{" ^ f ^ " " ^ (render_tex a) ^ "}" | TEX_DECLh (f,_,a) -> "{" ^ f ^ "{" ^ (mapjoin render_tex a) ^ "}}"