4

I'm seeing some strange output for \emph text using htlatex with the beamer class. Using the following source:

\documentclass{beamer}
\begin{document}
    \begin{frame}{Test}
        \emph{bold text}
        \begin{itemize}
            \item \emph{bold text}
        \end{itemize}
    \end{frame}
\end{document}

and compiling with

pdflatex test.tex
mk4ht htlatex test.tex 'xhtml,html5,charset=utf-8' ' -cunihtf -utf8 -cvalidate'

I see the following HTML output (reformatted for readability, but otherwise unmodified):

<!DOCTYPE html> 
<html lang="en-US" xml:lang="en-US" > 
    <head>
        <title></title> 
        <meta  charset="utf-8" /> 
        <meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
        <meta name="viewport" content="width=device-width,initial-scale=1" />
        <link rel="stylesheet" type="text/css" href="test.css" /> 
        <meta name="src" content="test.tex" /> 
    </head>
    <body>
        <span class="cmss-12x-x-120">Test</span>                                                               
        <!--l. 8--><p class="noindent" >
            <span class="cmssi-10x-x-109">bold text </span>
        </p>
        <ul class="itemize1">
            <li class="itemize">
                <span class="cmssi-10x-x-109">bold</span>
                <span class="cmssi-10x-x-109">text</span>
            </li>
        </ul>
    </body> 
</html>

As you can see, all \emph text is enclosed in <span> tags, and additionally \emph text within the itemize environment is separated into individual words, each in its own span.

No amount of \Configure{emph} in a config file affects this behaviour.

Clearly the output could be made to look right despite this weirdness. However my use case is generating accessible versions of content from presentation slides, so it's important to me to have semantically appropriate tags (e.g. <em>) and contiguous spans.

Is there a simple way to override this behaviour?

1 Answer 1

4

Beamer patches common font commands in order to support overlays. For most of them, it uses the original command definition, so tex4ht configurations still work. But it redefines \emph completely, so the configuration doesn't have any effect. It needs to be inserted again in beamer.4ht:

\let\Hy@EveryPageAnchor\relax
\def\pgf@trimright@final{0pt}
\def\pgf@trimleft@final{0pt}
\let\origEndP\EndP
\AtBeginDocument{\def\EndP{\let\EndP\origEndP}\SaveEndP}

% Beamer redefines \emph, it is necessary to insert hooks again

\pend:defI\emph{\a:emph}%
\append:defI\emph{\b:emph}%

\endinput

The configuration may look like this (this contains also configuration for slide insertion):

\Preamble{xhtml}
\Configure{emph}{\HCode{<em>}\NoFonts}{\EndNoFonts\HCode{</em>}}

\makeatletter
\ConfigureEnv{beamer@frameslide}
   {\ifvmode\IgnorePar\fi\EndP
    \HCode{<section class="slide">}\RecallEndP\par\ShowPar
   }
   {\ifvmode\IgnorePar\fi\EndP \HCode{</section>}}
   {} {}
\makeatother
\Css{section.slide {border:solid black 0.4pt;margin-bottom:1em;}}


\begin{document}
\EndPreamble

And this is the result:

<section class="slide">


<span 
class="cmss-12x-x-120">Test</span>                                                               
<!--l. 8--><p class="noindent" ><em>bold text</em> </p>
    <ul class="itemize1">
    <li class="itemize">
    <em>italic
    text</em></li></ul>


</section>
2
  • Thank you! I'll try this once my toddler is asleep. Is beamer.4ht picked up automatically or do I have to add it to the htlatex arguments somewhere like I would with the config?
    – cooperised
    Jul 27, 2019 at 11:20
  • 1
    It is picked automatically if it is placed in the same directory as the Tex file
    – michal.h21
    Jul 27, 2019 at 13:13

You must log in to answer this question.

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