From a2b53e5a36476894be778bd76d652e6a04ca8770 Mon Sep 17 00:00:00 2001 From: Nicholas Longo Date: Thu, 13 Oct 2011 23:04:41 +0000 Subject: [PATCH] The following patches restore how texvc added braces for all commands but \operatorname to fix Bug 31442. More specifically, TEX_FUN1 now adds braces as it did in previous versions. The result is texvc will once again correctly sanitize multiple math accents even when no braces are given (e.g. \dot \vec B) and it will allow math accents to be used with symbols whose font as been changed (e.g. \tilde \mathcal{M}). Parser tests are created to ensure these continue to work. The handling of \operatorname is now handled specially by the function TEX_FUN1nb (nb stands for no braces and the name is taken to be consistent with the existing function TEX_FUN2nb). The addition of braces causes this command to LaTeX incorrectly. The parser test for \operatorname has been updated to reflect the fact the hash of the images involved has changed. --- math/html.ml | 1 + math/lexer.mll | 1 + math/parser.mly | 3 ++- math/tex.mli | 1 + math/texutil.ml | 3 ++- mathParserTests.txt | 20 +++++++++++++++++++- 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/math/html.ml b/math/html.ml index e880f07..fd45027 100644 --- a/math/html.ml +++ b/math/html.ml @@ -56,6 +56,7 @@ let rec html_render_flat ctx = function | TEX_BOX (_,s)::r -> s^html_render_flat ctx r | TEX_LITERAL (TEX_ONLY _)::_ -> raise Too_difficult_for_html | TEX_FUN1 _::_ -> raise Too_difficult_for_html + | TEX_FUN1nb _::_ -> raise Too_difficult_for_html | TEX_FUN2 _::_ -> raise Too_difficult_for_html | TEX_FUN2nb _::_ -> raise Too_difficult_for_html | TEX_FUN2h _::_ -> raise Too_difficult_for_html diff --git a/math/lexer.mll b/math/lexer.mll index ca4dfc7..d321f07 100644 --- a/math/lexer.mll +++ b/math/lexer.mll @@ -56,6 +56,7 @@ 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)) } + | "\\operatorname" { Texutil.tex_use_ams(); FUN_AR1nb "\\operatorname" } | "\\sqrt" space * "[" { FUN_AR1opt "\\sqrt" } | "\\xleftarrow" space * "[" { Texutil.tex_use_ams(); FUN_AR1opt "\\xleftarrow" } | "\\xrightarrow" space * "[" { Texutil.tex_use_ams(); FUN_AR1opt "\\xrightarrow" } diff --git a/math/parser.mly b/math/parser.mly index 29882fb..373d45d 100644 --- a/math/parser.mly +++ b/math/parser.mly @@ -5,7 +5,7 @@ let sq_close_ri = HTMLABLEC(FONT_UFH,"]", "]") %} %token LITERAL DELIMITER -%token FUN_AR2 FUN_INFIX FUN_AR1 DECL FUN_AR1opt BIG FUN_AR2nb +%token FUN_AR2 FUN_INFIX FUN_AR1 DECL FUN_AR1nb FUN_AR1opt BIG FUN_AR2nb %token BOX %token FUN_AR1hl %token FUN_AR1hf DECLh @@ -85,6 +85,7 @@ lit: | BIG SQ_CLOSE { TEX_BIG ($1,sq_close_ri) } | left expr right { TEX_LR ($1,$3,$2) } | FUN_AR1 lit { TEX_FUN1($1,$2) } + | FUN_AR1nb lit { TEX_FUN1nb($1,$2) } | FUN_AR1hl lit { let t,h=$1 in TEX_FUN1hl(t,h,$2) } | FUN_AR1hf lit { let t,h=$1 in TEX_FUN1hf(t,h,$2) } | FUN_AR1opt expr_nosqc SQ_CLOSE lit { TEX_FUN2sq($1,TEX_CURLY $2,$4) } diff --git a/math/tex.mli b/math/tex.mli index f2ed37c..b3b9790 100644 --- a/math/tex.mli +++ b/math/tex.mli @@ -11,6 +11,7 @@ type t = | TEX_BOX of string * string | TEX_BIG of string * Render_info.t | TEX_FUN1 of string * t + | TEX_FUN1nb of string * t | TEX_FUN2 of string * t * t | TEX_FUN2nb of string * t * t | TEX_INFIX of string * t list * t list diff --git a/math/texutil.ml b/math/texutil.ml index 963e15e..a4c40a5 100644 --- a/math/texutil.ml +++ b/math/texutil.ml @@ -20,7 +20,8 @@ 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_FUN1nb (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) ^ "}}" diff --git a/mathParserTests.txt b/mathParserTests.txt index d80f99d..51691d4 100644 --- a/mathParserTests.txt +++ b/mathParserTests.txt @@ -144,6 +144,24 @@ BUG 18912: \operatorname{sen} x gets wrong spacing in math !! input \operatorname{sen} !! result -

\operatorname{sen} +

\operatorname{sen} +

+!! end + +!! test +BUG 31442: Multiple math accents without braces fails to parse +!! input +\dot \vec B +!! result +

\dot \vec B +

+!! end + +!! test +BUG 31442: Math accents with math font fail to parse if braces not used +!! input +\tilde \mathcal{M} +!! result +

\tilde \mathcal{M}

!! end