r87934 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87933‎ | r87934 | r87935 >
Date:21:46, 12 May 2011
Author:thenub314
Status:reverted (Comments)
Tags:brion, math 
Comment:
This updates improves the MathML support of texvc. New new tags have
been added, but the parser now recognizes numbers containing decimal
points as being renderable using <mn>. The delimiters (,[,{ now render
using <mo> tags, this allows for equations such as "y=f(x)" to be
rendered to MathML. Finally for standard functions such as \sin, now
render as <mi>\sin</mi>&ApplyFunction;, etc so standard function names
are supported.
Modified paths:
  • /trunk/extensions/Math/math/html.ml (modified) (history)
  • /trunk/extensions/Math/math/lexer.mll (modified) (history)
  • /trunk/extensions/Math/math/mathml.ml (modified) (history)
  • /trunk/extensions/Math/math/parser.mly (modified) (history)
  • /trunk/extensions/Math/math/render_info.mli (modified) (history)
  • /trunk/extensions/Math/math/texutil.ml (modified) (history)

Diff [purge]

Index: trunk/extensions/Math/math/mathml.ml
@@ -1,13 +1,15 @@
22 open Tex
33 open Render_info
44
5 -type t = TREE_MN of string | TREE_MO of string | TREE_MI of string
 5+type t = TREE_MN of string | TREE_MO of string | TREE_MI of string | TREE_MF of string | TREE_MFB of string * string
66
77 let rec make_mathml_tree = function
88 TREE_MN a::otr,TEX_LITERAL(MHTMLABLEC(_,_,_,MN,b))::itr -> make_mathml_tree(TREE_MN (a^b)::otr,itr)
99 | otr,TEX_LITERAL(MHTMLABLEC(_,_,_,MN,a))::itr -> make_mathml_tree(TREE_MN a::otr,itr)
1010 | otr,TEX_LITERAL(MHTMLABLEC(_,_,_,MO,a))::itr -> make_mathml_tree(TREE_MO a::otr,itr)
1111 | otr,TEX_LITERAL(MHTMLABLEC(_,_,_,MI,a))::itr -> make_mathml_tree(TREE_MI a::otr,itr)
 12+ | otr,TEX_LITERAL(MHTMLABLEC(_,_,_,MF,a))::itr -> make_mathml_tree(TREE_MF a::otr,itr)
 13+ | otr,TEX_LITERAL(MHTMLABLEFC(_,_,_,MF,a,b))::itr -> make_mathml_tree(TREE_MFB (a,b)::otr,itr)
1214 | otr,TEX_CURLY(crl)::itr -> make_mathml_tree(otr,crl@itr)
1315 | otr,[] -> List.rev otr
1416 | _ -> failwith "failed to render mathml"
@@ -16,5 +18,7 @@
1719 TREE_MN s -> "<mn>"^s^"</mn>"
1820 | TREE_MI s -> "<mi>"^s^"</mi>"
1921 | TREE_MO s -> "<mo>"^s^"</mo>"
 22+ | TREE_MF s -> "<mi>"^s^"</mi><mo>&ApplyFunction;</mo>"
 23+ | TREE_MFB (s,b) -> "<mi>"^s^"</mi><mo>&ApplyFunction;</mo>"^"<mo>"^b^"</mo>"
2024
2125 let render tree = try Some (Util.mapjoin render_mathml_tree (make_mathml_tree ([],tree))) with _ -> None
Index: trunk/extensions/Math/math/parser.mly
@@ -2,7 +2,7 @@
33 open Tex
44 open Render_info
55
6 - let sq_close_ri = HTMLABLEC(FONT_UFH,"]", "]")
 6+ let sq_close_ri = MHTMLABLEC(FONT_UFH,"]", "]",MO,"]")
77 %}
88 %token <Render_info.t> LITERAL DELIMITER
99 %token <string> FUN_AR2 FUN_INFIX FUN_AR1 DECL FUN_AR1opt BIG FUN_AR2nb
Index: trunk/extensions/Math/math/lexer.mll
@@ -6,9 +6,9 @@
77 let space = [' ' '\t' '\n' '\r']
88 let alpha = ['a'-'z' 'A'-'Z']
99 let literal_id = ['a'-'z' 'A'-'Z']
10 -let literal_mn = ['0'-'9']
 10+let literal_mn = ['0'-'9' '.']
1111 let literal_uf_lt = [',' ':' ';' '?' '!' '\'']
12 -let delimiter_uf_lt = ['(' ')' '.']
 12+let delimiter_uf_lt = ['(' ')']
1313 let literal_uf_op = ['+' '-' '*' '=']
1414 let delimiter_uf_op = ['/' '|']
1515 let boxchars = ['0'-'9' 'a'-'z' 'A'-'Z' '+' '-' '*' ',' '=' '(' ')' ':' '/' ';' '?' '.' '!' '\'' '`' ' ' '\128'-'\255']
@@ -52,7 +52,7 @@
5353 | literal_id { let str = Lexing.lexeme lexbuf in LITERAL (MHTMLABLEC (FONT_IT, str,str,MI,str)) }
5454 | literal_mn { let str = Lexing.lexeme lexbuf in LITERAL (MHTMLABLEC (FONT_RM, str,str,MN,str)) }
5555 | literal_uf_lt { let str = Lexing.lexeme lexbuf in LITERAL (HTMLABLEC (FONT_UFH, str,str)) }
56 - | delimiter_uf_lt { let str = Lexing.lexeme lexbuf in DELIMITER (HTMLABLEC (FONT_UFH, str,str)) }
 56+ | delimiter_uf_lt { let str = Lexing.lexeme lexbuf in DELIMITER (MHTMLABLEC (FONT_UFH, str,str,MO,str)) }
5757 | "-" { let str = Lexing.lexeme lexbuf in LITERAL (MHTMLABLEC (FONT_UFH,"-"," &minus; ",MO,str))}
5858 | literal_uf_op { let str = Lexing.lexeme lexbuf in LITERAL (MHTMLABLEC (FONT_UFH, str," "^str^" ",MO,str)) }
5959 | delimiter_uf_op { let str = Lexing.lexeme lexbuf in DELIMITER (MHTMLABLEC (FONT_UFH, str," "^str^" ",MO,str)) }
@@ -60,20 +60,31 @@
6161 | "\\sqrt" space * "[" { FUN_AR1opt "\\sqrt" }
6262 | "\\xleftarrow" space * "[" { Texutil.tex_use_ams(); FUN_AR1opt "\\xleftarrow" }
6363 | "\\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 ^ "&nbsp;")) }
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 ^ "&nbsp;"))) }
 64+ | "\\" (latex_function_names as name) space * "("
 65+ { LITERAL (MHTMLABLEFC(FONT_UFH,"\\" ^ name ^ "(", name ^ "(", MF, name, "(")) }
 66+ | "\\" (latex_function_names as name) space * "["
 67+ { LITERAL (MHTMLABLEFC(FONT_UFH,"\\" ^ name ^ "[", name ^ "[", MF, name, "[")) }
 68+ | "\\" (latex_function_names as name) space * "\\{"
 69+ { LITERAL (MHTMLABLEFC(FONT_UFH, "\\" ^ name ^ "\\{", name ^ "{", MF, name, "{")) }
 70+ | "\\" (latex_function_names as name) space *
 71+ { LITERAL (MHTMLABLEC(FONT_UFH,"\\" ^ name, name ^ "&nbsp;", MF, name)) }
 72+ | "\\" (mediawiki_function_names as name) space * "("
 73+ { (Texutil.tex_use_ams(); LITERAL (MHTMLABLEFC(FONT_UFH,
 74+ "\\operatorname{" ^ name ^ "}(", name ^ "(", MF, name, "("))) }
 75+ | "\\" (mediawiki_function_names as name) space * "["
 76+ { (Texutil.tex_use_ams(); LITERAL (MHTMLABLEFC(FONT_UFH,
 77+ "\\operatorname{" ^ name ^ "}[", name ^ "[", MF, name, "["))) }
 78+ | "\\" (mediawiki_function_names as name) space * "\\{"
 79+ { (Texutil.tex_use_ams(); LITERAL (MHTMLABLEFC(FONT_UFH,
 80+ "\\operatorname{" ^ name ^ "}\\{", name ^ "{", MF, name, "{"))) }
 81+ | "\\" (mediawiki_function_names as name) space *
 82+ { (Texutil.tex_use_ams(); LITERAL (MHTMLABLEC(FONT_UFH,"\\operatorname{" ^ name ^ "}", name ^ "&nbsp;", MF, name))) }
7283 | "\\," { LITERAL (HTMLABLE (FONT_UF, "\\,","&nbsp;")) }
7384 | "\\ " { LITERAL (HTMLABLE (FONT_UF, "\\ ","&nbsp;")) }
7485 | "\\;" { LITERAL (HTMLABLE (FONT_UF, "\\;","&nbsp;")) }
7586 | "\\!" { LITERAL (TEX_ONLY "\\!") }
76 - | "\\{" { DELIMITER (HTMLABLEC(FONT_UFH,"\\{","{")) }
77 - | "\\}" { DELIMITER (HTMLABLEC(FONT_UFH,"\\}","}")) }
 87+ | "\\{" { DELIMITER (MHTMLABLEC(FONT_UFH,"\\{","{",MO,"{")) }
 88+ | "\\}" { DELIMITER (MHTMLABLEC(FONT_UFH,"\\}","}",MO,"}")) }
7889 | "\\|" { DELIMITER (HTMLABLE (FONT_UFH,"\\|","||")) }
7990 | "\\_" { LITERAL (HTMLABLEC(FONT_UFH,"\\_","_")) }
8091 | "\\#" { LITERAL (HTMLABLE (FONT_UFH,"\\#","#")) }
@@ -109,7 +120,7 @@
110121 | '%' { LITERAL (HTMLABLEC(FONT_UFH,"\\%","%")) }
111122 | '$' { LITERAL (HTMLABLEC(FONT_UFH,"\\$","$")) }
112123 | '~' { LITERAL (HTMLABLE (FONT_UF, "~","&nbsp;")) }
113 - | '[' { DELIMITER (HTMLABLEC(FONT_UFH,"[","[")) }
 124+ | '[' { DELIMITER (MHTMLABLEC(FONT_UFH,"[","[",MO,"[")) }
114125 | ']' { SQ_CLOSE }
115126 | '{' { CURLY_OPEN }
116127 | '}' { CURLY_CLOSE }
Index: trunk/extensions/Math/math/texutil.ml
@@ -9,6 +9,7 @@
1010 | HTMLABLEM (_,t,_) -> t
1111 | HTMLABLEC (_,t,_) -> t
1212 | MHTMLABLEC (_,t,_,_,_) -> t
 13+ | MHTMLABLEFC (_,t,_,_,_,_) -> t
1314 | HTMLABLE_BIG (t,_) -> t
1415 | TEX_ONLY t -> t
1516
Index: trunk/extensions/Math/math/render_info.mli
@@ -11,10 +11,13 @@
1212 MN
1313 | MI
1414 | MO
 15+ | MF
 16+
1517 type t =
1618 HTMLABLEC of font_class * string * string
1719 | HTMLABLEM of font_class * string * string
1820 | HTMLABLE of font_class * string * string
1921 | MHTMLABLEC of font_class * string * string * math_class * string
 22+ | MHTMLABLEFC of font_class * string * string * math_class * string * string
2023 | HTMLABLE_BIG of string * string
2124 | TEX_ONLY of string
Index: trunk/extensions/Math/math/html.ml
@@ -28,6 +28,7 @@
2929 TEX_LITERAL (HTMLABLE (ft,_,sh))::r -> (html_liberal (); (font_render sh (ctx,ft))^html_render_flat ctx r)
3030 | TEX_LITERAL (HTMLABLEC(ft,_,sh))::r -> (font_render sh (ctx,ft))^html_render_flat ctx r
3131 | TEX_LITERAL (MHTMLABLEC(ft,_,sh,_,_))::r -> (font_render sh (ctx,ft))^html_render_flat ctx r
 32+ | TEX_LITERAL (MHTMLABLEFC(ft,_,sh,_,_,_))::r -> (font_render sh (ctx,ft))^html_render_flat ctx r
3233 | TEX_LITERAL (HTMLABLEM(ft,_,sh))::r -> (html_moderate(); (font_render sh (ctx,ft))^html_render_flat ctx r)
3334 | TEX_LITERAL (HTMLABLE_BIG (_,sh))::r -> (html_liberal (); sh^html_render_flat ctx r)
3435 | TEX_FUN1hl (_,(f1,f2),a)::r -> f1^(html_render_flat ctx [a])^f2^html_render_flat ctx r
@@ -75,6 +76,7 @@
7677 | TEX_LITERAL (HTMLABLEM(ft,_,sh))::r -> (html_moderate(); ("",(font_render sh (ctx,ft)),"")::html_render_deep ctx r)
7778 | TEX_LITERAL (HTMLABLEC(ft,_,sh))::r -> ("",(font_render sh (ctx,ft)),"")::html_render_deep ctx r
7879 | TEX_LITERAL (MHTMLABLEC(ft,_,sh,_,_))::r -> ("",(font_render sh (ctx,ft)),"")::html_render_deep ctx r
 80+ | TEX_LITERAL (MHTMLABLEFC(ft,_,sh,_,_,_))::r -> ("",(font_render sh (ctx,ft)),"")::html_render_deep ctx r
7981 | TEX_LITERAL (HTMLABLE_BIG (_,sh))::r -> (html_liberal (); ("",sh,"")::html_render_deep ctx r)
8082 | TEX_FUN2h (_,f,a,b)::r -> (html_liberal (); (f a b)::html_render_deep ctx r)
8183 | TEX_INFIXh (_,f,a,b)::r -> (html_liberal (); (f a b)::html_render_deep ctx r)

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

Comments

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

As far as I can see from the diff, this is a well written change that does what it says. If it actually works when tested, keep the change.

#Comment by Brion VIBBER (talk | contribs)   00:41, 8 September 2011

What on earth do the parameters on these MHTMLABLE, MHTMLABLEFC, HTMLABLEM, etc mean? When a new one's added in like on MHTMLABLEFC, what does it mean? How can we tell whether parameter values are correct in future during maintenance?

#Comment by Brion VIBBER (talk | contribs)   01:07, 8 September 2011

Ok I think this is starting to make sense to me, but I'll want to add some doc comments for next time. :D

#Comment by Thelema314 (talk | contribs)   01:28, 8 September 2011

As far as I can tell, these parameters get used for each different things scattered around the code. I totally agree that this code should could be better commented with explanation of what's going on. If the values should be labeled, ocaml provides records, which work like the tuples being used but have named access to fields (instead of positional access). The first step to making this change would be to replace

+ | MHTMLABLEFC of font_class * string * string * math_class * string * string

with

type mhtmlablefc_t = { font_class: font_class;

                    string1: string;
                    string2: string;
                    math_class: math_class;
                    string3: string;
                    string4: string; }

... + | MHTMLABLEFC of mhtmlablefc_t

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

Note that MathML rendering will be removed since it's so poor that it's useless. Probably no point to committing and testing this.

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

Provisionally reverted in r96990 pending test cases.

Status & tagging log