Tex4ht
uses command \Picture
... \EndPicture
to convert enclosed text to images. Command of the form
\Picture*[alt text]{align="center}
some text
\EndPicture
will generate
<img src="myfile01x.png" alt="alt text" align="center />
with myfile01x.png
containing text "some text".
Acording to tex4ht faq, you can use similar code
\newtoks\eqtoks
\def\AltMath#1${\eqtoks{#1}%
\Picture*[\HCode{\the\eqtoks}]{ align="middle"}$#1$\EndPicture$}
\Configure{$}{}{}{\expandafter\AltMath}
to typeset TeX code of the math as alt text. We can modify it to work with display math and to use our own macro containing alt text.
Create file myalt.cfg
:
\Preamble{xhtml}
\begin{document}
\def\MyDisplay{\leavevmode\EndP\HCode{<!--l. \the\inputlineno-->\Hnewline}\IgnorePar\Tg<div class="math-display">}
\def\EndMyDisplay{\HCode{<!--l. \the\inputlineno-->\Hnewline}\Tg</div>}
\def\AltMathII#1{%
\Picture*[\HCode{\the\myalt}]{}$$#1$$\EndPicture$$%
}
\def\AltMath#1$${\AltMathII{#1}}
\def\AltMathI#1\]{\AltMathII{#1}\egroup\EndMyDisplay}
\Configure{$$}{\MyDisplay}{\EndMyDisplay}{\expandafter\AltMath}
\Configure{[]}{\MyDisplay$$\AltMathI}{$$}
\Css{.math-display{
text-align:center;
margin: 5px;
}}
\EndPreamble
then myalt.sty
containing macro, which sets the alt text and filename:
\ProvidesPackage{myalt}
\newtoks\myalt
\newcommand\mymathinfo[2]{%
\NextPictureFile{#1}
\myalt{#2}
}
Now you can use
\documentclass{article}
\usepackage{myalt}
\begin{document}
Hello world
\mymathinfo{hello}{hello world}
$$a=\frac{\sqrt{4b}}{c}$$
\mymathinfo{world}{cool}
$$
\forall x \in X, \quad \exists y \leq \epsilon
$$
\end{document}
compile with
htlatex myfile "myalt"
resulting in:
<!--l. 8--><p class="noindent" >Hello world
</p><!--l. 10-->
<div class="math-display">
<img
src="hello.png" alt="hello world" />
<!--l. 10-->
</div>
<!--l. 12-->
<div class="math-display">
<img
src="world.png" alt="cool" />
<!--l. 14-->
</div>