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.
This commit is contained in:
Nicholas Longo 2011-10-13 23:04:41 +00:00
parent 2494e28140
commit a2b53e5a36
6 changed files with 26 additions and 3 deletions

View File

@ -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

View File

@ -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" }

View File

@ -5,7 +5,7 @@
let sq_close_ri = HTMLABLEC(FONT_UFH,"]", "]")
%}
%token <Render_info.t> LITERAL DELIMITER
%token <string> FUN_AR2 FUN_INFIX FUN_AR1 DECL FUN_AR1opt BIG FUN_AR2nb
%token <string> FUN_AR2 FUN_INFIX FUN_AR1 DECL FUN_AR1nb FUN_AR1opt BIG FUN_AR2nb
%token <string*string> BOX
%token <string*(string*string)> FUN_AR1hl
%token <string*Render_info.font_force> 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) }

View File

@ -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

View File

@ -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) ^ "}}"

View File

@ -144,6 +144,24 @@ BUG 18912: \operatorname{sen} x gets wrong spacing in math
!! input
<math>\operatorname{sen}</math>
!! result
<p><img class="tex" alt="\operatorname{sen}" src="/images/math/3/e/7/3e71e75d9aac1bf5107271ad89ca7c3b.png" />
<p><img class="tex" alt="\operatorname{sen}" src="/images/math/f/a/9/fa9660c7eb053ca8d3c9a87fa86635d9.png" />
</p>
!! end
!! test
BUG 31442: Multiple math accents without braces fails to parse
!! input
<math>\dot \vec B</math>
!! result
<p><img class="tex" alt="\dot \vec B" src="/images/math/e/6/4/e64939568ecb506a86a392373cec0458.png" />
</p>
!! end
!! test
BUG 31442: Math accents with math font fail to parse if braces not used
!! input
<math>\tilde \mathcal{M}</math>
!! result
<p><img class="tex" alt="\tilde \mathcal{M}" src="/images/math/5/5/0/55072ce6ef8c840c4b7687bd8a028bde.png" />
</p>
!! end