* (bug 6722) Spacing fixes for math functions with/without parens

* (bug 18912) Add math support for \sen Spanish variant of \sin
* (bug 18912) Fix spacing for \operatorname in math

Reapplies r86962, r87117, r87936, r87941 plus some parser tests.

Note that further batch testing to identify any other potential problems due to the spacing tweaks is a good idea!
This commit is contained in:
Brion Vibber 2011-09-14 00:49:16 +00:00
parent d2cf3c244b
commit 77bbd35329
3 changed files with 61 additions and 38 deletions

View File

@ -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 }
@ -54,10 +56,18 @@ rule token = parse
| "-" { let str = Lexing.lexeme lexbuf in LITERAL (MHTMLABLEC (FONT_UFH,"-"," − ",MO,str))}
| literal_uf_op { let str = Lexing.lexeme lexbuf in LITERAL (MHTMLABLEC (FONT_UFH, str," "^str^" ",MO,str)) }
| delimiter_uf_op { let str = Lexing.lexeme lexbuf in DELIMITER (MHTMLABLEC (FONT_UFH, str," "^str^" ",MO,str)) }
| "\\" alpha + { Texutil.find (Lexing.lexeme lexbuf) }
| "\\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 ^ " "))) }
| "\\" alpha + { Texutil.find (Lexing.lexeme lexbuf) }
| "\\," { LITERAL (HTMLABLE (FONT_UF, "\\,"," ")) }
| "\\ " { LITERAL (HTMLABLE (FONT_UF, "\\ "," ")) }
| "\\;" { LITERAL (HTMLABLE (FONT_UF, "\\;"," ")) }

View File

@ -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) ^ "}}"
@ -248,16 +248,6 @@ let find = function
| "\\triangleleft" -> LITERAL (TEX_ONLY "\\triangleleft ")
| "\\triangleright" -> LITERAL (TEX_ONLY "\\triangleright ")
| "\\textvisiblespace" -> LITERAL (TEX_ONLY "\\textvisiblespace ")
| "\\ker" -> LITERAL (HTMLABLEC(FONT_UFH,"\\ker ","ker"))
| "\\lim" -> LITERAL (TEX_ONLY "\\lim ")
| "\\limsup" -> LITERAL (TEX_ONLY "\\limsup ")
| "\\liminf" -> LITERAL (TEX_ONLY "\\liminf ")
| "\\sup" -> LITERAL (TEX_ONLY "\\sup ")
| "\\Pr" -> LITERAL (TEX_ONLY "\\Pr ")
| "\\hom" -> LITERAL (HTMLABLEC(FONT_UFH,"\\hom ","hom"))
| "\\arg" -> LITERAL (HTMLABLEC(FONT_UFH,"\\arg ","arg"))
| "\\dim" -> LITERAL (HTMLABLEC(FONT_UFH,"\\dim ","dim"))
| "\\inf" -> LITERAL (TEX_ONLY "\\inf ")
| "\\circ" -> LITERAL (TEX_ONLY "\\circ ")
| "\\hbar" -> LITERAL (TEX_ONLY "\\hbar ")
| "\\imath" -> LITERAL (TEX_ONLY "\\imath ")
@ -278,32 +268,6 @@ let find = function
| "\\limits" -> LITERAL (TEX_ONLY "\\limits ")
| "\\nolimits" -> LITERAL (TEX_ONLY "\\nolimits ")
| "\\top" -> LITERAL (TEX_ONLY "\\top ")
| "\\sin" -> LITERAL (HTMLABLEC(FONT_UFH,"\\sin ","sin"))
| "\\cos" -> LITERAL (HTMLABLEC(FONT_UFH,"\\cos ","cos"))
| "\\sinh" -> LITERAL (HTMLABLEC(FONT_UFH,"\\sinh ","sinh"))
| "\\cosh" -> LITERAL (HTMLABLEC(FONT_UFH,"\\cosh ","cosh"))
| "\\tan" -> LITERAL (HTMLABLEC(FONT_UFH,"\\tan ","tan"))
| "\\tanh" -> LITERAL (HTMLABLEC(FONT_UFH,"\\tanh ","tanh"))
| "\\sec" -> LITERAL (HTMLABLEC(FONT_UFH,"\\sec ","sec"))
| "\\csc" -> LITERAL (HTMLABLEC(FONT_UFH,"\\csc ","csc"))
| "\\arcsin" -> LITERAL (HTMLABLEC(FONT_UFH,"\\arcsin ","arcsin"))
| "\\arctan" -> LITERAL (HTMLABLEC(FONT_UFH,"\\arctan ","arctan"))
| "\\arccos" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{arccos}}","arccos")))
| "\\arccot" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{arccot}}","arccot")))
| "\\arcsec" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{arcsec}}","arcsec")))
| "\\arccsc" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{arccsc}}","arccsc")))
| "\\sgn" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{sgn}}","sgn")))
| "\\cot" -> LITERAL (HTMLABLEC(FONT_UFH,"\\cot ","cot"))
| "\\coth" -> LITERAL (HTMLABLEC(FONT_UFH,"\\coth ","coth"))
| "\\log" -> LITERAL (HTMLABLEC(FONT_UFH,"\\log ", "log"))
| "\\lg" -> LITERAL (HTMLABLEC(FONT_UFH,"\\lg ", "lg"))
| "\\ln" -> LITERAL (HTMLABLEC(FONT_UFH,"\\ln ", "ln"))
| "\\exp" -> LITERAL (HTMLABLEC(FONT_UFH,"\\exp ", "exp"))
| "\\min" -> LITERAL (HTMLABLEC(FONT_UFH,"\\min ", "min"))
| "\\max" -> LITERAL (HTMLABLEC(FONT_UFH,"\\max ", "max"))
| "\\gcd" -> LITERAL (HTMLABLEC(FONT_UFH,"\\gcd ", "gcd"))
| "\\deg" -> LITERAL (HTMLABLEC(FONT_UFH,"\\deg ", "deg"))
| "\\det" -> LITERAL (HTMLABLEC(FONT_UFH,"\\det ", "det"))
| "\\bullet" -> LITERAL (HTMLABLE (FONT_UFH, "\\bullet ", "•"))
| "\\bull" -> LITERAL (HTMLABLE (FONT_UFH, "\\bullet ", "•"))
| "\\angle" -> (tex_use_ams (); LITERAL (HTMLABLE (FONT_UF, "\\angle ", "∠")))

View File

@ -98,3 +98,52 @@ BUG 19547: Apostrophe / single quotes in math \text{...}
<span class="texhtml" dir="ltr">`next' year</span>
</p>
!! end
!! test
BUG 6722: Spacing fix for functions in math HTML output
!! input
<math>\sin x</math>
<math>\sin(x)</math>
<math>\sin{x}</math>
<math>\sin x \,</math>
<math>\sin(x) \,</math>
<math>\sin{x} \,</math>
!!result
<p><span class="texhtml" dir="ltr">sin&#160;<i>x</i></span>
<span class="texhtml" dir="ltr">sin(<i>x</i>)</span>
<span class="texhtml" dir="ltr">sin&#160;<i>x</i></span>
</p><p><img class="tex" alt="\sin x \," src="/images/math/7/6/a/76a8e1a01bd233c1e4e16d63b2bbf939.png" />
<img class="tex" alt="\sin(x) \," src="/images/math/1/6/c/16c69b0a3658d3b398f72c518d869a03.png" />
<img class="tex" alt="\sin{x} \," src="/images/math/8/3/9/839639707da39f691e702c2399cbf943.png" />
</p>
!! end
!! test
BUG 18912: Add \sen function for Spanish sin to math
!! input
<math>\sen x</math>
<math>\sen(x)</math>
<math>\sen{x}</math>
<math>\sen x \,</math>
<math>\sen(x) \,</math>
<math>\sen{x} \,</math>
!! result
<p><span class="texhtml" dir="ltr">sen&#160;<i>x</i></span>
<span class="texhtml" dir="ltr">sen(<i>x</i>)</span>
<span class="texhtml" dir="ltr">sen&#160;<i>x</i></span>
</p><p><img class="tex" alt="\sen x \," src="/images/math/0/a/c/0ac592b8f31b4698766c50c532f446a7.png" />
<img class="tex" alt="\sen(x) \," src="/images/math/b/b/5/bb5469d24fcdd52aa60cb9ee90ba697d.png" />
<img class="tex" alt="\sen{x} \," src="/images/math/d/4/8/d4882a4bcf5db1da3e30d905da8b394e.png" />
</p>
!! end
!! test
BUG 18912: \operatorname{sen} x gets wrong spacing in math
!! input
<math>\operatorname{sen}</math>
!! result
<p><img class="tex" alt="\operatorname{sen}" src="/images/math/3/e/7/3e71e75d9aac1bf5107271ad89ca7c3b.png" />
</p>
!! end