4

\textbf works in tex4ht before the figure environment, but not after:

\documentclass{book}
\usepackage{tikz}

\begin{document}
\textbf{this is bold}

\begin{figure}[h]
  \begin{tikzpicture}
    \draw[thick]  (0,0)   -- ++(4,0);  
  \end{tikzpicture}
\end{figure}

\textbf{this should be bold, but isn't}
\end{document}

I used the command htlatex testfig.tex "xhtml" to compile it.

I hope someone can help!

Nat Kuhn
  • 676
  • 1
    I got bold text after float, but not the image, you need to make special configuration in order to get tikz image included. see http://tex.stackexchange.com/a/158921/2891 – michal.h21 Sep 01 '14 at 06:53
  • Thanks @michal.h21! I do get the image—and this is a simplified version of a more complex image with text nodes that was generated flawlessly. I didn't make any special configuration, so I'm a little mystified as to why that would have worked for me. I do notice that if I take it out of the figure environment, I do not get the image, I get a weird little square with some scroll bars and and error message about an error at "line 5" which doesn't correspond to any line in a file of mine. Since I am getting the image I'm not sure exactly how to proceed? – Nat Kuhn Sep 01 '14 at 11:52
  • I should add that I am getting SVG output, which I think is what I want for an ebook, no? – Nat Kuhn Sep 01 '14 at 12:17
  • 1
    yes, you want svg output, maybe you are getting svg output because of some changes in recent versions of tikz, I will check it later. if tikz contains some configurations for tex4ht, maybe it causes suppression of font conversion – michal.h21 Sep 01 '14 at 12:59
  • Thank you so much! I recently installed MacTex 2014 which as I understand it includes Tex Live 2014. – Nat Kuhn Sep 01 '14 at 17:07
  • 1
    it seems that this is bad behavior of tikz tex4ht driver. font redefinitions are in effect even after the end of tikz picture, so your bold text is enclosed in svg tag for font change – michal.h21 Sep 01 '14 at 18:33

2 Answers2

1

Based on the response from @michal I was able to find a work-around for this. I took the .svg files generated by tex4ht and renamed them. I copied the HTML to insert the SVG from the .html output of tex4ht. I then used a conditional to put the HTML in by hand. (I did round off the dimensions to the nearest pixel, rather than the 4 or so (!) decimal places that tex4ht put in the HTML it wrote.)

\begin{figure}[h]%
  \centering%
  \gpifpdf{
    \begin{tikzpicture}%
      \draw[thick] 
      (0,0) node[above=1pt]{\helv \textbf{Defense (D)}}
      -- ++(4,0) node[above=1pt]{\helv \textbf{Anxiety (A)}}
      -- ++(-120:4) node[below=1pt]{\helv \textbf{Feeling (F)}}
      -- (0,0);
    \end{tikzpicture}%
  }{
    \HCode{
    <object data="figs/toc.svg" width="235" height="181" type="image/svg+xml"><p>SVG-Viewer needed.</p></object>}
  }
  \caption{The Triangle of Conflict}%
  \label{fig:toc}%
\end{figure}%

Where \gpifpdf is defined by:

\newcommand{\gpifpdf}[2]{\ifx\HCode\UnDef#1\else#2\fi}

Would love to know if there is a way to avoid the workaround!

Nat Kuhn
  • 676
  • 1
    for easier workaround (or not workaround at all), see http://tex.stackexchange.com/a/158921/2891 – michal.h21 Sep 08 '14 at 06:28
  • 1
    but we should find a solution for default method as well, the problem is that template for character classes is redefined and the previous template cannot be saved in some simple way, so you can redefine it to some default template, but if some package redefined the default template, you won't be able to get this redefined template back – michal.h21 Sep 08 '14 at 06:37
1

First, I added a caption to the original example:

\begin{figure}[h]
  \begin{tikzpicture}
    \draw[thick]  (0,0)   -- ++(4,0);  
  \end{tikzpicture}
  \caption{Try \textbf{bold} here.}
\end{figure}

Looking at the generated HTML, the font styling changes from span to tspan immediately after the svg dance:

<!--l. 5--><p class="noindent" ><span 
class="cmbx-10">this is bold</span>
<!--l. 7--><p class="indent" >   <hr class="figure"><div class="figure" 
>

<a 
 id="x1-21"></a>

<!--l. 10--><p class="noindent" ><object data="font_issue-1.svg" width="153.81403 " height="2.33333 " type="image/svg+xml"><p>SVG-Viewer needed.</p></object>
<br /> <div class="caption" 
><span class="id">Figure&#x00A0;1: </span><span  
class="content">Try <tspan font-family="cmbx" font-size="10">bold </tspan>here.</span></div><!--tex4ht:label?: x1-21 -->

<!--l. 12--><p class="indent" >   </div><hr class="endfigure">
<!--l. 14--><p class="indent" >   <tspan font-family="cmbx" font-size="10">this should be bold, but isn&#8217;t </tspan> 

Changing the tspan code to the appropriate span code fixes things, but the problem should be fixed at a more fundamental level.