[tex4ht] Non-tabular plain TeX alignments & indentation in HTML

Michal Hoftich michal.h21 at gmail.com
Tue Feb 6 11:05:19 CET 2024


Hi Richard,

>
> I have a plain TeX application in which I'd like to try converting some
> non-tabular alignments into <pre> elements with text that's (roughly)
> the alt text tex4ht would produce for those alignments in display math
> mode. But I can't figure out how to produce that alt text directly. Any
> advice/pointers/suggestions?


You can use \Picture+{}...\EndPicture command to convert the enclosed
code to pictures. It automatically creates the alternative text too,
based on the contents. See the documentation:
https://www.kodymirus.cz/tex4ht-doc/Configurations.html#low-level-features

To support also the PDF creation, I would create some extra commands
that would do nothing in the PDF mode, but invoke \Picture+ in TeX4ht.
The file mymacros.tex can look like this:

%%%%%%%%%%%%%%%%%%
\def\startalign{}
\def\stopalign{}
% code to be executed with TeX4ht
\ifdefined\HCode
 \csname tex4ht\endcsname % load TeX4ht
 % redefine commands to produce pictures
 \def\startalign{\Picture+{}}
 \def\stopalign{\EndPicture}
\fi
%%%%%%%%%%%%%%%%%%

You can use it in your document in this way:

%%%%%%%%%%%%%%%%%%
\input mymacros
\startalign
\vbox{\+if n$<$r \cleartabs& then n:=n+1\cr
\+&else &begin print\_totals; n:=0;\cr
\+&&end;\cr
\+while p$>$0 do&\cr
\+\quad\cleartabs&begin q:= link(p); free\_node(p); p:=q\cr
\+&end;\cr}
\stopalign
\bye
%%%%%%%%%%%%%%%%%%

Best regards,
Michal


More information about the tex4ht mailing list.