2

I would like to convert a scientific book with lots of formulas and tables to epub3. So far I have read all the posts that are tagged and related to tex4ebook, tex4ht etc. and I have managed to produce an epub3 version of my book with the formulas looking ok.

So far my command is:

tex4ebook  -f epub3  filename  mathml

Now, suppose that my tex has the following tikzpicture (borrowed from here).

\begin{tikzpicture}
    % Time axis
    \draw (0,0) -- node[below=1cm] {Time $\to$} (6,0);
    % Emotional axis
    \draw (0,0) -- node[left] {\parbox{2cm}{\centering $\uparrow$ \\     Emotional \\ intensity}} (0,4);
    % Time ticks
    \foreach \x [count=\j] in {0.2,3,4.5,6} {
        \draw (\x,0) coordinate (t\j) -- (\x,-0.1cm) node[below] (tt\j)     {Time \j};
    }
    \node[below] at (tt1.south) {(Emotional event)};
    % Curves
    \draw (t1) .. controls +(1,2) .. node[above right] {Experienced} (t2);
    \draw[dashed] (t1) .. controls +(1,4) .. node[above right]    {Predicted} (t4);
\end{tikzpicture} 

I am not able (or I do not understand how to do it), to use tex4ebook to get the epub to contain the above image. What should I add to the previous command for the tikzpicture to show? I have succeeded in completing all the instructions in all the relative tex4ebook StackExchange tags and be able to produce for example a pdf with luatex that contains the above image, but I do not know what to do to make it work with the tex4ebook command.

Can anyone tell me the steps I have to take? Thank you

  • Most likely, externalizing the tikz picture somewhere else and using it in your real document by \includegraphics is a better approach? – user31729 Dec 13 '15 at 9:44
  • @ChristianHupfer it is, see tex.stackexchange.com/a/158921/2891 for example. – michal.h21 Dec 13 '15 at 11:50
  • the svg file is inserted in epub file, but the problem is that it is not valid xml, there is some syntax error. Tikz support for SVG is fragile unfortunately, using externalization is better – michal.h21 Dec 13 '15 at 11:59
  • @Christian + michal, Thank you both for your replies. @michal, thank you for tex4ebook. So do you think externalization should be applied also to figures of this form too?: \begin{figure}[H]\hspace*{\fill}% \begin{game}{2}{2}[$t_1=S$] & $F$ & $NF$\\ $F$ &$1$, -$2$ &$2$, -$1$\\ $NF$ &-$1$, $2$ &$0, 0$ \\ \end{game}\hspace*{10mm}% \begin{game}{2}{2}[$t_1=W$] & $F$ & $NF$\\ $F$ &-$1,1$ &$2$, -$1$ \\ $NF$ &$0, 2$ &$0, 0$\\ \end{game}\hspace*{\fill}% \caption[]{\textit{A game with incomplete information}} \end{figure}%(using sgame package). – pebox11 Dec 13 '15 at 18:50
  • @michal:Does externalization excludes the usage of mathml? If no, how can I use it, cause so far steo 1. is to use pdflatex -shell-escape filename, 2. htlatex filename myconfig (I do not know if running htlatex filename myxonfig xhtml makes any improvements). Btw I think there is a bug in your answer for extarnalization: {; inkscape -z -f "\image.pdf" -l "\image.svg"} should be ; inkscape -z -f "\image.pdf" -l "\image.svg" (just delete the brackets, otherwise the svgs you are producing have an } appended at their end. – pebox11 Dec 13 '15 at 23:31
1

I will post answer to the original question and to the additional question from the comments. I haven't seen these comments when they were posted year ago.

So, to my question, is there a way to combine mathml and externalization?

Externalization doesn't interfere with MathML, it is just \includegraphics from tex4ht point of view. The problem with your code is that sgame package redefines internal LaTeX commands for table handling and it clashes with tex4ht. So we need a proper configuration file to get it to work. As a workaround, it is also possible to convert it to image.

So this is a full example:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{sgame}
\usetikzlibrary{external}

\tikzset{
 external/system call/.add={}                                                
      ; inkscape -z -f "\image.pdf" -l "\image.svg"     
}
\makeatletter
\@ifpackageloaded{tex4ht}{
    \tikzexternalize[mode=only graphics]
}{
    \tikzexternalize
}
\makeatother

\begin{document}
\begin{tikzpicture}
    % Time axis
    \draw (0,0) -- node[below=1cm] {Time $\to$} (6,0);
    % Emotional axis
    \draw (0,0) -- node[left] {\parbox{2cm}{\centering $\uparrow$ \\     Emotional \\ intensity}} (0,4);
    % Time ticks
    \foreach \x [count=\j] in {0.2,3,4.5,6} {
        \draw (\x,0) coordinate (t\j) -- (\x,-0.1cm) node[below] (tt\j)     {Time \j};
    }
    \node[below] at (tt1.south) {(Emotional event)};
    % Curves
    \draw (t1) .. controls +(1,2) .. node[above right] {Experienced} (t2);
    \draw[dashed] (t1) .. controls +(1,4) .. node[above right]    {Predicted} (t4);
\end{tikzpicture} 

Some equation:

\begin{equation} \label{eu_eqn}
  e^{\pi i} + 1 = 0
\end{equation}

\begin{figure}[tbh]\hspace*{\fill}
 \begin{game}{2}{2}[$t_1=S$] & $F$ & $NF$\\
$F$ &$1$, -$2$ &$2$, -$1$\\ $NF$ &-$1$, $2$ &$0, 0$ \\
\end{game}
\hspace*{10mm}
\begin{game}{2}{2}[$t_1=W$] & $F$ & $NF$\\ $F$
&-$1,1$ &$2$, -$1$ \\ $NF$ &$0, 2$ &$0, 0$\\ 
\end{game}\hspace*{\fill}%
\caption[]{\textit{A game with incomplete information}} 
\end{figure}    

\begin{tabular}{ll}
  And what about & normal table?\\
\end{tabular}

\end{document}

We set basic externalization stuff in the preamble. We can't get rid of the disambiguation for \tikzexternalize, unfortunately.

The config file contains code for SVG inclusion, tex4ht configuration for the externalization and request for conversion of game environment to picture:

\Preamble{xhtml,mathml}
\makeatletter
\Configure{graphics*}  
         {svg}{  
          {\Configure{Needs}{File: \Gin@base.svg}\Needs{}}
          \Picture[\csname a:GraphicsAlt\endcsname]{\csname Gin@base\endcsname.svg \csname a:Gin-dim\endcsname}%  
         }  
\makeatother

\ConfigureEnv{game}{\Picture+{}}{\EndPicture}{}{}
\begin{document}
\tikzset{
    tex4ht inc/.style={
        /pgf/images/include external/.code={%
            \includegraphics[]{##1.svg}%
        }
    }
}
\tikzset{tex4ht inc}
\EndPreamble

You can compile the document using

tex4ebook -f epub3 -c mycfg.cfg filename.tex

This is the result: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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