@@ -2115,6 +2115,55 @@ def apply_mathml(self, expr, evaluation) -> Expression:
21152115 return Expression ("RowBox" , Expression (SymbolList , String (mathml )))
21162116
21172117
2118+ class HTMLForm (Builtin ):
2119+ """
2120+ <dl>
2121+ <dt>'HTMLForm[$expr$]'
2122+ <dd>displays $expr$ as a HTML expression.
2123+ </dl>
2124+
2125+ >> HTMLForm[HoldForm[Sqrt[a^3]]]
2126+ = ...
2127+
2128+ ## Test cases for Unicode - redo please as a real test
2129+ >> MathMLForm[\\ [Mu]]
2130+ = ...
2131+
2132+ # This can causes the TeX to fail
2133+ # >> MathMLForm[Graphics[Text["\u03bc "]]]
2134+ # = ...
2135+
2136+ ## The <mo> should contain U+2062 INVISIBLE TIMES
2137+ ## MathMLForm[MatrixForm[{{2*a, 0},{0,0}}]]
2138+ = ...
2139+ """
2140+
2141+ def apply_hml (self , expr , evaluation ) -> Expression :
2142+ "MakeBoxes[expr_, HTMLForm]"
2143+
2144+ boxes = MakeBoxes (expr ).evaluate (evaluation )
2145+ try :
2146+ xml = boxes .boxes_to_mathml (evaluation = evaluation )
2147+ except BoxError :
2148+ evaluation .message (
2149+ "General" ,
2150+ "notboxes" ,
2151+ Expression ("FullForm" , boxes ).evaluate (evaluation ),
2152+ )
2153+ xml = ""
2154+ is_a_picture = xml [:6 ] == "<mtext"
2155+
2156+ # mathml = '<math><mstyle displaystyle="true">%s</mstyle></math>' % xml
2157+ # #convert_box(boxes)
2158+ query = evaluation .parse ("System`$UseSansSerif" )
2159+ usesansserif = query .evaluate (evaluation ).to_python ()
2160+ if not is_a_picture :
2161+ if usesansserif :
2162+ xml = '<mstyle mathvariant="sans-serif">%s</mstyle>' % xml
2163+
2164+ mathml = '<math display="block">%s</math>' % xml # convert_box(boxes)
2165+ return Expression ("RowBox" , Expression (SymbolList , String (mathml )))
2166+
21182167class PythonForm (Builtin ):
21192168 """
21202169 <dl>
0 commit comments