@@ -45,7 +45,7 @@ function ConvertMathML (_, content)
4545 local script = content .options .mathvariant and b .mathVariantToScriptType (content .options .mathvariant )
4646 local text = content [1 ]
4747 if type (text ) ~= " string" then
48- SU .error (" mi command contains " .. text .. " , which is not text" )
48+ SU .error (" mi command contains content which is not text" )
4949 end
5050 script = script or (luautf8 .len (text ) == 1 and b .scriptType .italic or b .scriptType .upright )
5151 return b .text (" identifier" , {}, script , text )
@@ -67,15 +67,15 @@ function ConvertMathML (_, content)
6767 end
6868 end
6969 if type (text ) ~= " string" then
70- SU .error (" mo command contains " .. text .. " , which is not text" )
70+ SU .error (" mo command contains content which is not text" )
7171 end
7272 return b .text (" operator" , attributes , script , text )
7373 elseif content .command == " mn" then
7474 local script = content .options .mathvariant and b .mathVariantToScriptType (content .options .mathvariant )
7575 or b .scriptType .upright
7676 local text = content [1 ]
7777 if type (text ) ~= " string" then
78- SU .error (" mn command contains " .. text .. " , which is not text" )
78+ SU .error (" mn command contains content which is not text" )
7979 end
8080 if string.sub (text , 1 , 1 ) == " -" then
8181 text = " −" .. string.sub (text , 2 )
@@ -136,6 +136,19 @@ function ConvertMathML (_, content)
136136 return b .mtr (convertChildren (content ))
137137 elseif content .command == " mtd" then
138138 return b .stackbox (" H" , convertChildren (content ))
139+ elseif content .command == " mtext" or content .command == " ms" then
140+ if # content > 1 then
141+ SU .error (" Wrong number of children in " .. content .command .. " : " .. # content )
142+ end
143+ local text = content [1 ] or " " -- empty mtext is allowed, and found in examples...
144+ if type (text ) ~= " string" then
145+ SU .error (content .command .. " command contains content which is not text" )
146+ end
147+ -- MathML Core 3.2.1.1 Layout of <mtext> has some wording about forced line breaks
148+ -- and soft wrap opportunities: ignored here.
149+ -- There's also some explanations about CSS, italic correction etc. which we ignore too.
150+ text = text :gsub (" [\n\r ]" , " " )
151+ return b .text (" string" , {}, b .scriptType .upright , text :gsub (" %s+" , " " ))
139152 else
140153 SU .error (" Unknown math command " .. content .command )
141154 end
0 commit comments