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>⁡, etc so standard function names are supported.
This commit is contained in:
parent
81a8e25eaa
commit
c60fa06a6a
@ -28,6 +28,7 @@ let rec html_render_flat ctx = function
|
||||
TEX_LITERAL (HTMLABLE (ft,_,sh))::r -> (html_liberal (); (font_render sh (ctx,ft))^html_render_flat ctx r)
|
||||
| TEX_LITERAL (HTMLABLEC(ft,_,sh))::r -> (font_render sh (ctx,ft))^html_render_flat ctx r
|
||||
| TEX_LITERAL (MHTMLABLEC(ft,_,sh,_,_))::r -> (font_render sh (ctx,ft))^html_render_flat ctx r
|
||||
| TEX_LITERAL (MHTMLABLEFC(ft,_,sh,_,_,_))::r -> (font_render sh (ctx,ft))^html_render_flat ctx r
|
||||
| TEX_LITERAL (HTMLABLEM(ft,_,sh))::r -> (html_moderate(); (font_render sh (ctx,ft))^html_render_flat ctx r)
|
||||
| TEX_LITERAL (HTMLABLE_BIG (_,sh))::r -> (html_liberal (); sh^html_render_flat ctx r)
|
||||
| TEX_FUN1hl (_,(f1,f2),a)::r -> f1^(html_render_flat ctx [a])^f2^html_render_flat ctx r
|
||||
@ -75,6 +76,7 @@ let rec html_render_deep ctx = function
|
||||
| TEX_LITERAL (HTMLABLEM(ft,_,sh))::r -> (html_moderate(); ("",(font_render sh (ctx,ft)),"")::html_render_deep ctx r)
|
||||
| TEX_LITERAL (HTMLABLEC(ft,_,sh))::r -> ("",(font_render sh (ctx,ft)),"")::html_render_deep ctx r
|
||||
| TEX_LITERAL (MHTMLABLEC(ft,_,sh,_,_))::r -> ("",(font_render sh (ctx,ft)),"")::html_render_deep ctx r
|
||||
| TEX_LITERAL (MHTMLABLEFC(ft,_,sh,_,_,_))::r -> ("",(font_render sh (ctx,ft)),"")::html_render_deep ctx r
|
||||
| TEX_LITERAL (HTMLABLE_BIG (_,sh))::r -> (html_liberal (); ("",sh,"")::html_render_deep ctx r)
|
||||
| TEX_FUN2h (_,f,a,b)::r -> (html_liberal (); (f a b)::html_render_deep ctx r)
|
||||
| TEX_INFIXh (_,f,a,b)::r -> (html_liberal (); (f a b)::html_render_deep ctx r)
|
||||
|
@ -6,9 +6,9 @@
|
||||
let space = [' ' '\t' '\n' '\r']
|
||||
let alpha = ['a'-'z' 'A'-'Z']
|
||||
let literal_id = ['a'-'z' 'A'-'Z']
|
||||
let literal_mn = ['0'-'9']
|
||||
let literal_mn = ['0'-'9' '.']
|
||||
let literal_uf_lt = [',' ':' ';' '?' '!' '\'']
|
||||
let delimiter_uf_lt = ['(' ')' '.']
|
||||
let delimiter_uf_lt = ['(' ')']
|
||||
let literal_uf_op = ['+' '-' '*' '=']
|
||||
let delimiter_uf_op = ['/' '|']
|
||||
let boxchars = ['0'-'9' 'a'-'z' 'A'-'Z' '+' '-' '*' ',' '=' '(' ')' ':' '/' ';' '?' '.' '!' '\'' '`' ' ' '\128'-'\255']
|
||||
@ -52,7 +52,7 @@ rule token = parse
|
||||
| literal_id { let str = Lexing.lexeme lexbuf in LITERAL (MHTMLABLEC (FONT_IT, str,str,MI,str)) }
|
||||
| literal_mn { let str = Lexing.lexeme lexbuf in LITERAL (MHTMLABLEC (FONT_RM, str,str,MN,str)) }
|
||||
| literal_uf_lt { let str = Lexing.lexeme lexbuf in LITERAL (HTMLABLEC (FONT_UFH, str,str)) }
|
||||
| delimiter_uf_lt { let str = Lexing.lexeme lexbuf in DELIMITER (HTMLABLEC (FONT_UFH, str,str)) }
|
||||
| delimiter_uf_lt { let str = Lexing.lexeme lexbuf in DELIMITER (MHTMLABLEC (FONT_UFH, str,str,MO,str)) }
|
||||
| "-" { 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)) }
|
||||
@ -60,20 +60,31 @@ 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 ^ " "))) }
|
||||
| "\\" (latex_function_names as name) space * "("
|
||||
{ LITERAL (MHTMLABLEFC(FONT_UFH,"\\" ^ name ^ "(", name ^ "(", MF, name, "(")) }
|
||||
| "\\" (latex_function_names as name) space * "["
|
||||
{ LITERAL (MHTMLABLEFC(FONT_UFH,"\\" ^ name ^ "[", name ^ "[", MF, name, "[")) }
|
||||
| "\\" (latex_function_names as name) space * "\\{"
|
||||
{ LITERAL (MHTMLABLEFC(FONT_UFH, "\\" ^ name ^ "\\{", name ^ "{", MF, name, "{")) }
|
||||
| "\\" (latex_function_names as name) space *
|
||||
{ LITERAL (MHTMLABLEC(FONT_UFH,"\\" ^ name, name ^ " ", MF, name)) }
|
||||
| "\\" (mediawiki_function_names as name) space * "("
|
||||
{ (Texutil.tex_use_ams(); LITERAL (MHTMLABLEFC(FONT_UFH,
|
||||
"\\operatorname{" ^ name ^ "}(", name ^ "(", MF, name, "("))) }
|
||||
| "\\" (mediawiki_function_names as name) space * "["
|
||||
{ (Texutil.tex_use_ams(); LITERAL (MHTMLABLEFC(FONT_UFH,
|
||||
"\\operatorname{" ^ name ^ "}[", name ^ "[", MF, name, "["))) }
|
||||
| "\\" (mediawiki_function_names as name) space * "\\{"
|
||||
{ (Texutil.tex_use_ams(); LITERAL (MHTMLABLEFC(FONT_UFH,
|
||||
"\\operatorname{" ^ name ^ "}\\{", name ^ "{", MF, name, "{"))) }
|
||||
| "\\" (mediawiki_function_names as name) space *
|
||||
{ (Texutil.tex_use_ams(); LITERAL (MHTMLABLEC(FONT_UFH,"\\operatorname{" ^ name ^ "}", name ^ " ", MF, name))) }
|
||||
| "\\," { LITERAL (HTMLABLE (FONT_UF, "\\,"," ")) }
|
||||
| "\\ " { LITERAL (HTMLABLE (FONT_UF, "\\ "," ")) }
|
||||
| "\\;" { LITERAL (HTMLABLE (FONT_UF, "\\;"," ")) }
|
||||
| "\\!" { LITERAL (TEX_ONLY "\\!") }
|
||||
| "\\{" { DELIMITER (HTMLABLEC(FONT_UFH,"\\{","{")) }
|
||||
| "\\}" { DELIMITER (HTMLABLEC(FONT_UFH,"\\}","}")) }
|
||||
| "\\{" { DELIMITER (MHTMLABLEC(FONT_UFH,"\\{","{",MO,"{")) }
|
||||
| "\\}" { DELIMITER (MHTMLABLEC(FONT_UFH,"\\}","}",MO,"}")) }
|
||||
| "\\|" { DELIMITER (HTMLABLE (FONT_UFH,"\\|","||")) }
|
||||
| "\\_" { LITERAL (HTMLABLEC(FONT_UFH,"\\_","_")) }
|
||||
| "\\#" { LITERAL (HTMLABLE (FONT_UFH,"\\#","#")) }
|
||||
@ -109,7 +120,7 @@ rule token = parse
|
||||
| '%' { LITERAL (HTMLABLEC(FONT_UFH,"\\%","%")) }
|
||||
| '$' { LITERAL (HTMLABLEC(FONT_UFH,"\\$","$")) }
|
||||
| '~' { LITERAL (HTMLABLE (FONT_UF, "~"," ")) }
|
||||
| '[' { DELIMITER (HTMLABLEC(FONT_UFH,"[","[")) }
|
||||
| '[' { DELIMITER (MHTMLABLEC(FONT_UFH,"[","[",MO,"[")) }
|
||||
| ']' { SQ_CLOSE }
|
||||
| '{' { CURLY_OPEN }
|
||||
| '}' { CURLY_CLOSE }
|
||||
|
@ -1,13 +1,15 @@
|
||||
open Tex
|
||||
open Render_info
|
||||
|
||||
type t = TREE_MN of string | TREE_MO of string | TREE_MI of string
|
||||
type t = TREE_MN of string | TREE_MO of string | TREE_MI of string | TREE_MF of string | TREE_MFB of string * string
|
||||
|
||||
let rec make_mathml_tree = function
|
||||
TREE_MN a::otr,TEX_LITERAL(MHTMLABLEC(_,_,_,MN,b))::itr -> make_mathml_tree(TREE_MN (a^b)::otr,itr)
|
||||
| otr,TEX_LITERAL(MHTMLABLEC(_,_,_,MN,a))::itr -> make_mathml_tree(TREE_MN a::otr,itr)
|
||||
| otr,TEX_LITERAL(MHTMLABLEC(_,_,_,MO,a))::itr -> make_mathml_tree(TREE_MO a::otr,itr)
|
||||
| otr,TEX_LITERAL(MHTMLABLEC(_,_,_,MI,a))::itr -> make_mathml_tree(TREE_MI a::otr,itr)
|
||||
| otr,TEX_LITERAL(MHTMLABLEC(_,_,_,MF,a))::itr -> make_mathml_tree(TREE_MF a::otr,itr)
|
||||
| otr,TEX_LITERAL(MHTMLABLEFC(_,_,_,MF,a,b))::itr -> make_mathml_tree(TREE_MFB (a,b)::otr,itr)
|
||||
| otr,TEX_CURLY(crl)::itr -> make_mathml_tree(otr,crl@itr)
|
||||
| otr,[] -> List.rev otr
|
||||
| _ -> failwith "failed to render mathml"
|
||||
@ -16,5 +18,7 @@ let render_mathml_tree = function
|
||||
TREE_MN s -> "<mn>"^s^"</mn>"
|
||||
| TREE_MI s -> "<mi>"^s^"</mi>"
|
||||
| TREE_MO s -> "<mo>"^s^"</mo>"
|
||||
| TREE_MF s -> "<mi>"^s^"</mi><mo>⁡</mo>"
|
||||
| TREE_MFB (s,b) -> "<mi>"^s^"</mi><mo>⁡</mo>"^"<mo>"^b^"</mo>"
|
||||
|
||||
let render tree = try Some (Util.mapjoin render_mathml_tree (make_mathml_tree ([],tree))) with _ -> None
|
||||
|
@ -2,7 +2,7 @@
|
||||
open Tex
|
||||
open Render_info
|
||||
|
||||
let sq_close_ri = HTMLABLEC(FONT_UFH,"]", "]")
|
||||
let sq_close_ri = MHTMLABLEC(FONT_UFH,"]", "]",MO,"]")
|
||||
%}
|
||||
%token <Render_info.t> LITERAL DELIMITER
|
||||
%token <string> FUN_AR2 FUN_INFIX FUN_AR1 DECL FUN_AR1opt BIG FUN_AR2nb
|
||||
|
@ -11,10 +11,13 @@ type math_class =
|
||||
MN
|
||||
| MI
|
||||
| MO
|
||||
| MF
|
||||
|
||||
type t =
|
||||
HTMLABLEC of font_class * string * string
|
||||
| HTMLABLEM of font_class * string * string
|
||||
| HTMLABLE of font_class * string * string
|
||||
| MHTMLABLEC of font_class * string * string * math_class * string
|
||||
| MHTMLABLEFC of font_class * string * string * math_class * string * string
|
||||
| HTMLABLE_BIG of string * string
|
||||
| TEX_ONLY of string
|
||||
|
@ -9,6 +9,7 @@ let tex_part = function
|
||||
| HTMLABLEM (_,t,_) -> t
|
||||
| HTMLABLEC (_,t,_) -> t
|
||||
| MHTMLABLEC (_,t,_,_,_) -> t
|
||||
| MHTMLABLEFC (_,t,_,_,_,_) -> t
|
||||
| HTMLABLE_BIG (t,_) -> t
|
||||
| TEX_ONLY t -> t
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user