Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using tex4ht to translate LaTeX to (X)HTML. Tex4ht automatically generates images of equations it could not translate directly into text.

Problem: the filename of the image generated, as well as the corresponding 'alt' text is meaningless.

Want: A way to embed in the LaTeX code the filename of image generated, as well as the 'alt' text.

Partial solution: I managed to define the filename by using the command? \NextPictureFile{NameToBeUsed} just before an equation. But I'm unable to specify the 'alt' text. Any suggestions?

Of course, an option is to edit the generated HTML pages by hand to specify the 'alt' text. But since this is to be done on a large number of LaTeX files, which can be updated, this would mean having to specify all 'alt' again, even for minor updates on the original files.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

Tex4ht uses command \Picture ... \EndPicture to convert enclosed text to images. Command of the form

\Picture*[alt text]{align="center}
some text

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

\Picture*[\HCode{\the\eqtoks}]{ align="middle"}$#1$\EndPicture$}  

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:

\def\MyDisplay{\leavevmode\EndP\HCode{<!--l. \the\inputlineno-->\Hnewline}\IgnorePar\Tg<div class="math-display">}
\def\EndMyDisplay{\HCode{<!--l. \the\inputlineno-->\Hnewline}\Tg</div>}
margin: 5px;

then myalt.sty containing macro, which sets the alt text and filename:


Now you can use

Hello world
\mymathinfo{hello}{hello world}
 \forall x \in X, \quad \exists y \leq \epsilon

compile with

htlatex myfile "myalt"

resulting in:

<!--l. 8--><p class="noindent" >Hello world
</p><!--l. 10--> 
<div class="math-display">
src="hello.png" alt="hello world"  />
<!--l. 10--> 
<!--l. 12--> 
<div class="math-display">
src="world.png" alt="cool"  />
<!--l. 14--> 
share|improve this answer
That worked just fine (and improved a lot my understanding of tex4ht)! :) Only one last question. Some of the LaTeX files are generated by Scientific Workplace (a frontend for LaTeX. Some contributors of the LaTeX files use it) which uses "\[ ... \]" for equations instead of "$$..$$". How can I modify the code above to deal with the later case? I tried some variants (replacing "$$" with "\[" and "\]") without success. –  Daniel Feb 10 '12 at 15:50
I edited my answer to work with [ .. ] –  michal.h21 Feb 10 '12 at 18:10
That was just perfect! :) –  Daniel Feb 10 '12 at 20:04
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.