r86962 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86961‎ | r86962 | r86963 >
Date:18:17, 26 April 2011
Author:thenub314
Status:resolved (Comments)
Tags:brion, math, needs-parsertests 
Comment:
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 .
Modified paths:
  • /trunk/extensions/Math/math/lexer.mll (modified) (history)
  • /trunk/extensions/Math/math/texutil.ml (modified) (history)

Diff [purge]

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 }
@@ -58,6 +60,14 @@
5961 | "\\sqrt" space * "[" { FUN_AR1opt "\\sqrt" }
6062 | "\\xleftarrow" space * "[" { Texutil.tex_use_ams(); FUN_AR1opt "\\xleftarrow" }
6163 | "\\xrightarrow" space * "[" { Texutil.tex_use_ams(); FUN_AR1opt "\\xrightarrow" }
 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 ^ "{")) }
 67+ | "\\" (latex_function_names as name) space * { LITERAL (HTMLABLEC(FONT_UFH,"\\" ^ 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^ "{"))) }
 71+ | "\\" (mediawiki_function_names as name) space * { (Texutil.tex_use_ams(); LITERAL (HTMLABLEC(FONT_UFH,"\\operatorname{" ^ name ^ "}", name ^ " "))) }
6272 | "\\," { LITERAL (HTMLABLE (FONT_UF, "\\,"," ")) }
6373 | "\\ " { LITERAL (HTMLABLE (FONT_UF, "\\ "," ")) }
6474 | "\\;" { LITERAL (HTMLABLE (FONT_UF, "\\;"," ")) }
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) ^ "}}"

Sign-offs

UserFlagDate
Thelema314inspected14:13, 29 August 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r96990Revert changes to texvc that provide no test cases or examples of what they'r...brion19:00, 13 September 2011
r96993MFT r96990: provisional revert of texvc changes that don't come with any test...brion19:07, 13 September 2011
r97034* (bug 6722) Spacing fixes for math functions with/without parens...brion00:49, 14 September 2011

Comments

#Comment by Thenub314 (talk | contribs)   19:43, 2 May 2011

Revision r87117 corrects a small bug introduced in this change. which results to not inserting a space after the function name when no braces are used. That is if the input was the the code sent to LaTeX was \sinx.

#Comment by Thelema314 (talk | contribs)   14:13, 29 August 2011

This looks like a good refactoring of many \foo commands into a smaller set of code. I'm surprised about extra { } in latex producing misrendering, but guess it's possible.

#Comment by Brion VIBBER (talk | contribs)   18:47, 13 September 2011

Needs parser tests to confirm the change and prevent regressions.

#Comment by Brion VIBBER (talk | contribs)   19:03, 13 September 2011

Provisionally reverted in r96990 pending test cases.

#Comment by Brion VIBBER (talk | contribs)   22:52, 13 September 2011

This seems to stop things in the pattern \sin{x} from working; I see \sin{...}, \cos{...}, and \tan{...} in 583 equations on en.wikipedia.org, such as on w:en:Anomalous Diffraction Theory

#Comment by Brion VIBBER (talk | contribs)   00:50, 14 September 2011

Reapplied in r97034 along with test cases & some friends; a couple more revs that hadn't been obviously connected resolve this issue.

Status & tagging log