From 77bbd35329df99f1abafb610d8d0fa58d5fc71fd Mon Sep 17 00:00:00 2001
From: Brion Vibber
Date: Wed, 14 Sep 2011 00:49:16 +0000
Subject: [PATCH] * (bug 6722) Spacing fixes for math functions with/without
parens * (bug 18912) Add math support for \sen Spanish variant of \sin * (bug
18912) Fix spacing for \operatorname in math
Reapplies r86962, r87117, r87936, r87941 plus some parser tests.
Note that further batch testing to identify any other potential problems due to the spacing tweaks is a good idea!
---
math/lexer.mll | 12 ++++++++++-
math/texutil.ml | 38 +----------------------------------
mathParserTests.txt | 49 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+), 38 deletions(-)
diff --git a/math/lexer.mll b/math/lexer.mll
index 9b2053ec2..ca4dfc7bc 100644
--- a/math/lexer.mll
+++ b/math/lexer.mll
@@ -13,6 +13,8 @@ let literal_uf_op = ['+' '-' '*' '=']
let delimiter_uf_op = ['/' '|']
let boxchars = ['0'-'9' 'a'-'z' 'A'-'Z' '+' '-' '*' ',' '=' '(' ')' ':' '/' ';' '?' '.' '!' '\'' '`' ' ' '\128'-'\255']
let aboxchars = ['0'-'9' 'a'-'z' 'A'-'Z' '+' '-' '*' ',' '=' '(' ')' ':' '/' ';' '?' '.' '!' '\'' '`' ' ']
+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"
+let mediawiki_function_names = "arccot" | "arcsec" | "arccsc" | "sgn" | "sen"
rule token = parse
space + { token lexbuf }
@@ -54,10 +56,18 @@ 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)) }
- | "\\" alpha + { Texutil.find (Lexing.lexeme lexbuf) }
| "\\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 ^ " "))) }
+ | "\\" alpha + { Texutil.find (Lexing.lexeme lexbuf) }
| "\\," { LITERAL (HTMLABLE (FONT_UF, "\\,"," ")) }
| "\\ " { LITERAL (HTMLABLE (FONT_UF, "\\ "," ")) }
| "\\;" { LITERAL (HTMLABLE (FONT_UF, "\\;"," ")) }
diff --git a/math/texutil.ml b/math/texutil.ml
index 2e3401233..963e15e04 100644
--- a/math/texutil.ml
+++ b/math/texutil.ml
@@ -20,7 +20,7 @@ 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_FUN1hl (f,_,a) -> "{" ^ f ^ " " ^ (render_tex a) ^ "}"
| TEX_FUN1hf (f,_,a) -> "{" ^ f ^ " " ^ (render_tex a) ^ "}"
| TEX_DECLh (f,_,a) -> "{" ^ f ^ "{" ^ (mapjoin render_tex a) ^ "}}"
@@ -248,16 +248,6 @@ let find = function
| "\\triangleleft" -> LITERAL (TEX_ONLY "\\triangleleft ")
| "\\triangleright" -> LITERAL (TEX_ONLY "\\triangleright ")
| "\\textvisiblespace" -> LITERAL (TEX_ONLY "\\textvisiblespace ")
- | "\\ker" -> LITERAL (HTMLABLEC(FONT_UFH,"\\ker ","ker"))
- | "\\lim" -> LITERAL (TEX_ONLY "\\lim ")
- | "\\limsup" -> LITERAL (TEX_ONLY "\\limsup ")
- | "\\liminf" -> LITERAL (TEX_ONLY "\\liminf ")
- | "\\sup" -> LITERAL (TEX_ONLY "\\sup ")
- | "\\Pr" -> LITERAL (TEX_ONLY "\\Pr ")
- | "\\hom" -> LITERAL (HTMLABLEC(FONT_UFH,"\\hom ","hom"))
- | "\\arg" -> LITERAL (HTMLABLEC(FONT_UFH,"\\arg ","arg"))
- | "\\dim" -> LITERAL (HTMLABLEC(FONT_UFH,"\\dim ","dim"))
- | "\\inf" -> LITERAL (TEX_ONLY "\\inf ")
| "\\circ" -> LITERAL (TEX_ONLY "\\circ ")
| "\\hbar" -> LITERAL (TEX_ONLY "\\hbar ")
| "\\imath" -> LITERAL (TEX_ONLY "\\imath ")
@@ -278,32 +268,6 @@ let find = function
| "\\limits" -> LITERAL (TEX_ONLY "\\limits ")
| "\\nolimits" -> LITERAL (TEX_ONLY "\\nolimits ")
| "\\top" -> LITERAL (TEX_ONLY "\\top ")
- | "\\sin" -> LITERAL (HTMLABLEC(FONT_UFH,"\\sin ","sin"))
- | "\\cos" -> LITERAL (HTMLABLEC(FONT_UFH,"\\cos ","cos"))
- | "\\sinh" -> LITERAL (HTMLABLEC(FONT_UFH,"\\sinh ","sinh"))
- | "\\cosh" -> LITERAL (HTMLABLEC(FONT_UFH,"\\cosh ","cosh"))
- | "\\tan" -> LITERAL (HTMLABLEC(FONT_UFH,"\\tan ","tan"))
- | "\\tanh" -> LITERAL (HTMLABLEC(FONT_UFH,"\\tanh ","tanh"))
- | "\\sec" -> LITERAL (HTMLABLEC(FONT_UFH,"\\sec ","sec"))
- | "\\csc" -> LITERAL (HTMLABLEC(FONT_UFH,"\\csc ","csc"))
- | "\\arcsin" -> LITERAL (HTMLABLEC(FONT_UFH,"\\arcsin ","arcsin"))
- | "\\arctan" -> LITERAL (HTMLABLEC(FONT_UFH,"\\arctan ","arctan"))
- | "\\arccos" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{arccos}}","arccos")))
- | "\\arccot" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{arccot}}","arccot")))
- | "\\arcsec" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{arcsec}}","arcsec")))
- | "\\arccsc" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{arccsc}}","arccsc")))
- | "\\sgn" -> (tex_use_ams (); LITERAL (HTMLABLEC(FONT_UFH,"\\mathop{\\mathrm{sgn}}","sgn")))
- | "\\cot" -> LITERAL (HTMLABLEC(FONT_UFH,"\\cot ","cot"))
- | "\\coth" -> LITERAL (HTMLABLEC(FONT_UFH,"\\coth ","coth"))
- | "\\log" -> LITERAL (HTMLABLEC(FONT_UFH,"\\log ", "log"))
- | "\\lg" -> LITERAL (HTMLABLEC(FONT_UFH,"\\lg ", "lg"))
- | "\\ln" -> LITERAL (HTMLABLEC(FONT_UFH,"\\ln ", "ln"))
- | "\\exp" -> LITERAL (HTMLABLEC(FONT_UFH,"\\exp ", "exp"))
- | "\\min" -> LITERAL (HTMLABLEC(FONT_UFH,"\\min ", "min"))
- | "\\max" -> LITERAL (HTMLABLEC(FONT_UFH,"\\max ", "max"))
- | "\\gcd" -> LITERAL (HTMLABLEC(FONT_UFH,"\\gcd ", "gcd"))
- | "\\deg" -> LITERAL (HTMLABLEC(FONT_UFH,"\\deg ", "deg"))
- | "\\det" -> LITERAL (HTMLABLEC(FONT_UFH,"\\det ", "det"))
| "\\bullet" -> LITERAL (HTMLABLE (FONT_UFH, "\\bullet ", "•"))
| "\\bull" -> LITERAL (HTMLABLE (FONT_UFH, "\\bullet ", "•"))
| "\\angle" -> (tex_use_ams (); LITERAL (HTMLABLE (FONT_UF, "\\angle ", "∠")))
diff --git a/mathParserTests.txt b/mathParserTests.txt
index 0b5adee3e..d80f99d25 100644
--- a/mathParserTests.txt
+++ b/mathParserTests.txt
@@ -98,3 +98,52 @@ BUG 19547: Apostrophe / single quotes in math \text{...}
`next' year
!! end
+
+!! test
+BUG 6722: Spacing fix for functions in math HTML output
+!! input
+
+
+
+
+
+
+
+!!result
+sin x
+sin(x)
+sin x
+
+
+
+
+!! end
+
+!! test
+BUG 18912: Add \sen function for Spanish sin to math
+!! input
+
+
+
+
+
+
+
+!! result
+sen x
+sen(x)
+sen x
+
+
+
+
+!! end
+
+!! test
+BUG 18912: \operatorname{sen} x gets wrong spacing in math
+!! input
+
+!! result
+
+
+!! end