1

This post describes a way to have make4ht take a LaTeX source file and produce an HTML file which includes alt text for images. Is it possible to use make4ht to produce ODT files containing alt text from LaTeX source files? If so, how?

0

1 Answer 1

1

TeX4ht and the graphicx package now support alt texts out of the box, just use the alt keyval property:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[alt={my alt text}]{example-image.png}

\includegraphics[]{example-image.png}
\end{document}

It is not supported in the ODT format yet, but you can add support using the following config file:

\Preamble{xhtml}
\catcode`\:=11
\makeatletter
\NewConfigure{GraphicsAlt}{1}
\Configure{IMG}
  {% parse the image extension, will be used later
\expandafter\filename@parse\expandafter{\PictureFile}%
\ifx\a:GraphicsAlt\relax%
\Configure{GraphicsAlt}{ALT}%
\fi%
\ifx\Gin@base\@undefined
\let\graphics:filename\PictureFile
\else
\def\graphics:filename{\Gin@base\Gin@ext}
\fi
% \ht:special{t4ht>\PictureFile.4og}%
\ht:special{t4ht>\graphics:filename.4og}%
\ht:special{t4ht*>}%
% \ht:special{t4ht<\PictureFile.4og}%
\ht:special{t4ht<\graphics:filename.4og}%
\OOmanifest{<manifest:file-entry
   manifest:full-path="Pictures/\PictureFile" manifest:media-type="\get:image:mime:type\filename@ext"/>\Hnewline
}%
%
   \ht:special{t4ht=<draw:frame
      draw:name="\PictureFile"
      text:anchor-type="as-char"  % "paragraph"
        % insert image dimension only if they really exist
        \ifx\noBoundingBox\UnDefined
         \ifx\Gin@req@width\undefined\else
         \ifdim\Gin@req@width>0pt
         \string svg:width="\the\Gin@req@width"
          svg:height="\the\Gin@req@height"
        \fi\fi\fi
      draw:z-index="0"
    >%
      <draw:image\Hnewline
         xlink:href="Pictures/}}
  {\ht:special{t4ht=" \Hnewline
         xlink:type="simple"
        xlink:show="embed"
        xlink:actuate="onLoad"
        /><!--draw:name="}}
  {" }
  {\ht:special{t4ht=" }}
  {\ht:special{t4ht=--><svg:title>\a:GraphicsAlt</svg:title></draw:frame>}}
\catcode`\:=12
\makeatother
\begin{document}
\EndPreamble

It reuses the image drawing code from TeX4ht sources, with just few extra lines:

\ifx\a:GraphicsAlt\relax%
\Configure{GraphicsAlt}{ALT}%
\fi%

The alt key defines the \a:GraphicsAlt macro. If the key isn't used in th e \includegraphics command, it defined a default value of ALT.

The alt text itself is included by this code:

  {\ht:special{t4ht=--><svg:title>\a:GraphicsAlt</svg:title></draw:frame>}}

Here are the image properties in LO, with alt text set:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .