how can I get bold symbols using \boldsymbol and tex4ht with MathML output?
Most straightforward way to get the bold symbols is to redefine \boldsymbols
command to include tags which you want. Put this command to your .cfg file:
\renewcommand\boldsymbol[1]{\HCode{<mi mathvariant="bold-italic">}\PauseMathClass #1\EndPauseMathClass\HCode{</mi>}}
\PauseMathClass
will prevent tex4ht
from including tags based on font, you would get
<mi mathvariant="bold-italic"><mi
>x</mi></mi>
otherwise. The resulting mathml:
<mi mathvariant="bold-italic">a</mi><mo
class="MathClass-punc">,</mo><mi mathvariant="bold-italic">x</mi><mo
class="MathClass-punc">,</mo><mi mathvariant="bold-italic">X</mi><mo
class="MathClass-punc">,</mo><mi mathvariant="bold-italic">α</mi><mo
class="MathClass-punc">,</mo><mi mathvariant="bold-italic">β</mi><mo
class="MathClass-punc">,</mo><mi mathvariant="bold-italic">Θ</mi><mo
class="MathClass-punc">,</mo><mo
class="MathClass-op">…</mo>
The other way is to use bm
package, as Barbara suggested. It seems that it also redefines \boldsymbol
and it is supported by tex4ht
, with one caveat:
<mstyle mathvariant="bold"><mi
>a</mi></mstyle><mo
class="MathClass-punc">,</mo><mstyle mathvariant="bold"><mi
>x</mi></mstyle><mo
class="MathClass-punc">,</mo><mstyle mathvariant="bold"><mi
>X</mi></mstyle><mo
class="MathClass-punc">,</mo><mstyle mathvariant="bold"><mi
>α</mi></mstyle><mo
class="MathClass-punc">,</mo><mstyle mathvariant="bold"><mi
>β</mi></mstyle><mo
class="MathClass-punc">,</mo><mstyle mathvariant="bold"><mi
>Θ</mi></mstyle><mo
class="MathClass-punc">,</mo><mo
class="MathClass-op">…</mo></math>
the problem is that it seems that only bold is selected, not italic style, although there is <mi>
element as <mstyle>
child. I am not sure whether it is only bug in Firefox rendering, but you can easily replace these elements with your desired output using some simple regular expresssion in make4ht
build file:
-- sample.mk4
local filter = require "make4ht-filter"
local htmlmatch = filter {
function(text)
return text:gsub('<mstyle mathvariant="bold">%s*<mi%s*>([^%<]+)</mi></mstyle>', function(symbol)
return string.format('<mi mathvariant="bold-italic">%s</mi>', symbol)
end)
end
}
if mode=="draft" then
Make:htlatex {}
else
Make:htlatex {}
Make:htlatex {}
Make:htlatex {}
end
Make:match("html$", htmlmatch)
The regular expression is included in htmlmatch
function. Compile with:
make4ht -uc bold-math.cfg -e sample.mk4 bold-math.tex
the resulting mathml:
<mi mathvariant="bold-italic">a</mi><mo
class="MathClass-punc">,</mo><mi mathvariant="bold-italic">x</mi><mo
class="MathClass-punc">,</mo><mi mathvariant="bold-italic">X</mi><mo
class="MathClass-punc">,</mo><mi mathvariant="bold-italic">α</mi><mo
class="MathClass-punc">,</mo><mi mathvariant="bold-italic">β</mi><mo
class="MathClass-punc">,</mo><mi mathvariant="bold-italic">Θ</mi><mo
class="MathClass-punc">,</mo><mo
class="MathClass-op">…</mo>
and Firefox rendering: