r97034 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97033‎ | r97034 | r97035 >
Date:00:49, 14 September 2011
Author:brion
Status:ok (Comments)
Tags:math 
Comment:
* (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!
Modified paths:
  • /trunk/extensions/Math/math/lexer.mll (modified) (history)
  • /trunk/extensions/Math/math/texutil.ml (modified) (history)
  • /trunk/extensions/Math/mathParserTests.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/Math/mathParserTests.txt
@@ -98,3 +98,52 @@
9999 <span class="texhtml" dir="ltr">`next' year</span>
100100 </p>
101101 !! end
 102+
 103+!! test
 104+BUG 6722: Spacing fix for functions in math HTML output
 105+!! input
 106+<math>\sin x</math>
 107+<math>\sin(x)</math>
 108+<math>\sin{x}</math>
 109+
 110+<math>\sin x \,</math>
 111+<math>\sin(x) \,</math>
 112+<math>\sin{x} \,</math>
 113+!!result
 114+<p><span class="texhtml" dir="ltr">sin&#160;<i>x</i></span>
 115+<span class="texhtml" dir="ltr">sin(<i>x</i>)</span>
 116+<span class="texhtml" dir="ltr">sin&#160;<i>x</i></span>
 117+</p><p><img class="tex" alt="\sin x \," src="/images/math/7/6/a/76a8e1a01bd233c1e4e16d63b2bbf939.png" />
 118+<img class="tex" alt="\sin(x) \," src="/images/math/1/6/c/16c69b0a3658d3b398f72c518d869a03.png" />
 119+<img class="tex" alt="\sin{x} \," src="/images/math/8/3/9/839639707da39f691e702c2399cbf943.png" />
 120+</p>
 121+!! end
 122+
 123+!! test
 124+BUG 18912: Add \sen function for Spanish sin to math
 125+!! input
 126+<math>\sen x</math>
 127+<math>\sen(x)</math>
 128+<math>\sen{x}</math>
 129+
 130+<math>\sen x \,</math>
 131+<math>\sen(x) \,</math>
 132+<math>\sen{x} \,</math>
 133+!! result
 134+<p><span class="texhtml" dir="ltr">sen&#160;<i>x</i></span>
 135+<span class="texhtml" dir="ltr">sen(<i>x</i>)</span>
 136+<span class="texhtml" dir="ltr">sen&#160;<i>x</i></span>
 137+</p><p><img class="tex" alt="\sen x \," src="/images/math/0/a/c/0ac592b8f31b4698766c50c532f446a7.png" />
 138+<img class="tex" alt="\sen(x) \," src="/images/math/b/b/5/bb5469d24fcdd52aa60cb9ee90ba697d.png" />
 139+<img class="tex" alt="\sen{x} \," src="/images/math/d/4/8/d4882a4bcf5db1da3e30d905da8b394e.png" />
 140+</p>
 141+!! end
 142+
 143+!! test
 144+BUG 18912: \operatorname{sen} x gets wrong spacing in math
 145+!! input
 146+<math>\operatorname{sen}</math>
 147+!! result
 148+<p><img class="tex" alt="\operatorname{sen}" src="/images/math/3/e/7/3e71e75d9aac1bf5107271ad89ca7c3b.png" />
 149+</p>
 150+!! end
Index: trunk/extensions/Math/math/lexer.mll
@@ -13,6 +13,8 @@
1414 let delimiter_uf_op = ['/' '|']
1515 let boxchars = ['0'-'9' 'a'-'z' 'A'-'Z' '+' '-' '*' ',' '=' '(' ')' ':' '/' ';' '?' '.' '!' '\'' '`' ' ' '\128'-'\255']
1616 let aboxchars = ['0'-'9' 'a'-'z' 'A'-'Z' '+' '-' '*' ',' '=' '(' ')' ':' '/' ';' '?' '.' '!' '\'' '`' ' ']
 17+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"
 18+let mediawiki_function_names = "arccot" | "arcsec" | "arccsc" | "sgn" | "sen"
1719
1820 rule token = parse
1921 space + { token lexbuf }
@@ -54,10 +56,18 @@
5557 | "-" { let str = Lexing.lexeme lexbuf in LITERAL (MHTMLABLEC (FONT_UFH,"-"," &minus; ",MO,str))}
5658 | literal_uf_op { let str = Lexing.lexeme lexbuf in LITERAL (MHTMLABLEC (FONT_UFH, str," "^str^" ",MO,str)) }
5759 | delimiter_uf_op { let str = Lexing.lexeme lexbuf in DELIMITER (MHTMLABLEC (FONT_UFH, str," "^str^" ",MO,str)) }
58 - | "\\" alpha + { Texutil.find (Lexing.lexeme lexbuf) }
5960 | "\\sqrt" space * "[" { FUN_AR1opt "\\sqrt" }
6061 | "\\xleftarrow" space * "[" { Texutil.tex_use_ams(); FUN_AR1opt "\\xleftarrow" }
6162 | "\\xrightarrow" space * "[" { Texutil.tex_use_ams(); FUN_AR1opt "\\xrightarrow" }
 63+ | "\\" (latex_function_names as name) space * "(" { LITERAL (HTMLABLEC(FONT_UFH,"\\" ^ name ^ "(", name ^ "(")) }
 64+ | "\\" (latex_function_names as name) space * "[" { LITERAL (HTMLABLEC(FONT_UFH,"\\" ^ name ^ "[", name ^ "[")) }
 65+ | "\\" (latex_function_names as name) space * "\\{" { LITERAL (HTMLABLEC(FONT_UFH,"\\" ^ name ^ "\\{", name ^ "{")) }
 66+ | "\\" (latex_function_names as name) space * { LITERAL (HTMLABLEC(FONT_UFH,"\\" ^ name ^ " ", name ^ "&nbsp;")) }
 67+ | "\\" (mediawiki_function_names as name) space * "(" { (Texutil.tex_use_ams(); LITERAL (HTMLABLEC(FONT_UFH,"\\operatorname{" ^ name ^ "}(", name^ "("))) }
 68+ | "\\" (mediawiki_function_names as name) space * "[" { (Texutil.tex_use_ams(); LITERAL (HTMLABLEC(FONT_UFH,"\\operatorname{" ^ name ^ "}[", name^ "["))) }
 69+ | "\\" (mediawiki_function_names as name) space * "\\{" { (Texutil.tex_use_ams(); LITERAL (HTMLABLEC(FONT_UFH,"\\operatorname{" ^ name ^ "}\\{", name^ "{"))) }
 70+ | "\\" (mediawiki_function_names as name) space * { (Texutil.tex_use_ams(); LITERAL (HTMLABLEC(FONT_UFH,"\\operatorname{" ^ name ^ "} ", name ^ "&nbsp;"))) }
 71+ | "\\" alpha + { Texutil.find (Lexing.lexeme lexbuf) }
6272 | "\\," { LITERAL (HTMLABLE (FONT_UF, "\\,","&nbsp;")) }
6373 | "\\ " { LITERAL (HTMLABLE (FONT_UF, "\\ ","&nbsp;")) }
6474 | "\\;" { LITERAL (HTMLABLE (FONT_UF, "\\;","&nbsp;")) }
Index: trunk/extensions/Math/math/texutil.ml
@@ -20,7 +20,7 @@
2121 | TEX_DQN (a) -> "_{" ^ (render_tex a) ^ "}"
2222 | TEX_UQN (a) -> "^{" ^ (render_tex a) ^ "}"
2323 | TEX_LITERAL s -> tex_part s
24 - | TEX_FUN1 (f,a) -> "{" ^ f ^ " " ^ (render_tex a) ^ "}"
 24+ | TEX_FUN1 (f,a) -> f ^ " " ^ (render_tex a)
2525 | TEX_FUN1hl (f,_,a) -> "{" ^ f ^ " " ^ (render_tex a) ^ "}"
2626 | TEX_FUN1hf (f,_,a) -> "{" ^ f ^ " " ^ (render_tex a) ^ "}"
2727 | TEX_DECLh (f,_,a) -> "{" ^ f ^ "{" ^ (mapjoin render_tex a) ^ "}}"
@@ -248,16 +248,6 @@
249249 | "\\triangleleft" -> LITERAL (TEX_ONLY "\\triangleleft ")
250250 | "\\triangleright" -> LITERAL (TEX_ONLY "\\triangleright ")
251251 | "\\textvisiblespace" -> LITERAL (TEX_ONLY "\\textvisiblespace ")
252 - | "\\ker" -> LITERAL (HTMLABLEC(FONT_UFH,"\\ker ","ker"))
253 - | "\\lim" -> LITERAL (TEX_ONLY "\\lim ")
254 - | "\\limsup" -> LITERAL (TEX_ONLY "\\limsup ")
255 - | "\\liminf" -> LITERAL (TEX_ONLY "\\liminf ")
256 - | "\\sup" -> LITERAL (TEX_ONLY "\\sup ")
257 - | "\\Pr" -> LITERAL (TEX_ONLY "\\Pr ")
258 - | "\\hom" -> LITERAL (HTMLABLEC(FONT_UFH,"\\hom ","hom"))
259 - | "\\arg" -> LITERAL (HTMLABLEC(FONT_UFH,"\\arg ","arg"))
260 - | "\\dim" -> LITERAL (HTMLABLEC(FONT_UFH,"\\dim ","dim"))
261 - | "\\inf" -> LITERAL (TEX_ONLY "\\inf ")
262252 | "\\circ" -> LITERAL (TEX_ONLY "\\circ ")
263253 | "\\hbar" -> LITERAL (TEX_ONLY "\\hbar ")
264254 | "\\imath" -> LITERAL (TEX_ONLY "\\imath ")
@@ -278,32 +268,6 @@
279269 | "\\limits" -> LITERAL (TEX_ONLY "\\limits ")
280270 | "\\nolimits" -> LITERAL (TEX_ONLY "\\nolimits ")
281271 | "\\top" -> LITERAL (TEX_ONLY "\\top ")
282 - | "\\sin" -> LITERAL (HTMLABLEC(FONT_UFH,"\\sin ","sin"))
283 - | "\\cos" -> LITERAL (HTMLABLEC(FONT_UFH,"\\cos ","cos"))
284 - | "\\sinh" -> LITERAL (HTMLABLEC(FONT_UFH,"\\sinh ","sinh"))
285 - | "\\cosh" -> LITERAL (HTMLABLEC(FONT_UFH,"\\cosh ","cosh"))
286 - | "\\tan" -> LITERAL (HTMLABLEC(FONT_UFH,"\\tan ","tan"))
287 - | "\\tanh" -> LITERAL (HTMLABLEC(FONT_UFH,"\\tanh ","tanh"))
288 - | "\\sec" -> LITERAL (HTMLABLEC(FONT_UFH,"\\sec ","sec"))
289 - | "\\csc" -> LITERAL (HTMLABLEC(FONT_UFH,"\\csc ","csc"))
290 - | "\\arcsin" -> LITERAL (HTMLABLEC(FONT_UFH,"\\arcsin ","arcsin"))
291 - | "\\arctan" -> LITERAL (HTMLABLEC(FONT_UFH,"\\arctan ","arctan"))
292 - | "\\arccos" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{arccos}}","arccos")))
293 - | "\\arccot" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{arccot}}","arccot")))
294 - | "\\arcsec" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{arcsec}}","arcsec")))
295 - | "\\arccsc" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{arccsc}}","arccsc")))
296 - | "\\sgn" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{sgn}}","sgn")))
297 - | "\\cot" -> LITERAL (HTMLABLEC(FONT_UFH,"\\cot ","cot"))
298 - | "\\coth" -> LITERAL (HTMLABLEC(FONT_UFH,"\\coth ","coth"))
299 - | "\\log" -> LITERAL (HTMLABLEC(FONT_UFH,"\\log ", "log"))
300 - | "\\lg" -> LITERAL (HTMLABLEC(FONT_UFH,"\\lg ", "lg"))
301 - | "\\ln" -> LITERAL (HTMLABLEC(FONT_UFH,"\\ln ", "ln"))
302 - | "\\exp" -> LITERAL (HTMLABLEC(FONT_UFH,"\\exp ", "exp"))
303 - | "\\min" -> LITERAL (HTMLABLEC(FONT_UFH,"\\min ", "min"))
304 - | "\\max" -> LITERAL (HTMLABLEC(FONT_UFH,"\\max ", "max"))
305 - | "\\gcd" -> LITERAL (HTMLABLEC(FONT_UFH,"\\gcd ", "gcd"))
306 - | "\\deg" -> LITERAL (HTMLABLEC(FONT_UFH,"\\deg ", "deg"))
307 - | "\\det" -> LITERAL (HTMLABLEC(FONT_UFH,"\\det ", "det"))
308272 | "\\bullet" -> LITERAL (HTMLABLE (FONT_UFH, "\\bullet ", "&bull;"))
309273 | "\\bull" -> LITERAL (HTMLABLE (FONT_UFH, "\\bullet ", "&bull;"))
310274 | "\\angle" -> (tex_use_ams (); LITERAL (HTMLABLE (FONT_UF, "\\angle ", "&ang;")))

Sign-offs

UserFlagDate
Thelema314inspected13:28, 16 September 2011
😂inspected15:22, 16 September 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r97259REL1_18 MFT r97001, r97002, r97007, r97014, r97018, r97034reedy13:06, 16 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86962The following changes enhance the way texvc handles space around...thenub31418:17, 26 April 2011
r87117This update removes unneeded code from texutil.ml and corrects the way...thenub31406:08, 29 April 2011
r87936Corrects a small bug causing <math>\sin</math> to return an unknown...thenub31422:29, 12 May 2011
r87941A change to fix a bug in LaTeX rendering of function names. An...thenub31400:01, 13 May 2011

Comments

#Comment by Thelema314 (talk | contribs)   13:28, 16 September 2011

This patch looks like it puts together a bunch of pieces from previous patches. I assume they're all there. They look correctly applied.

I'm a bit surprised at the removal of braces around TEX_FUN1, but if it works, I guess it's okay.

Status & tagging log