1

My ebook has several figures, and I would also like to embed font files. I have dealt with the figures in an ad hoc way: after the first compilation, I go to the book-epub folder and drop the files in the figs folder (which contains the cover already). When I rebuild the ebook they are included. This works, but the files are not included in the manifest, so the epub is not well-formed. If I use an ebook editor (I think it was Sigil but may have been Calibre), it doesn't preserve the figs files when it re-saves.

Edit 1: I am using \Picture, e.g.:

\Picture{figs/toc.svg align=center height=600}
  • figures included with \includegraphics should be included automatically, could you post more details? – michal.h21 Nov 20 '14 at 20:02
  • Hi @michal.h21, I added some detail above, but also realized that even so what should I do about the file for the embedded font? Is there a macro that says "list this file on the manifest"? – Nat Kuhn Nov 20 '14 at 21:09
4

You shouldn't use tex4ht commands like \Picture directly in your document, they are supposed to be used in configuration files. The problem is, that this way you are no longer able to process your document with normal LaTeX in order to produce pdf.

I would use following schema in your case:

if you have figures in svg format, convert them also to pdf, so you will be able to use them for pdf production. In your TeX file, include these files with:

\includegraphics[width=600pt]{figs/toc}

so leave out file extension, correct file will be included depending on the used compilation tool.

Regarding fonts, I will use code from my older answer. This is the complete .cfg file:

\Preamble{xhtml}
\makeatletter
% Various helper functions
% default font size
\newcommand\emwidth{16}
\let\emwidth\f@size
% convert pt to rem
\newcommand\CalcRem[1]{\strip@pt\dimexpr(#1)/\emwidth}
  \Configure{graphics*}  
         {svg}  
          {\Picture[pict]{\csname Gin@base\endcsname.svg
          \space style="width:\CalcRem{\Gin@req@width}em;"
          }%  
          \special{t4ht+@File: \csname Gin@base\endcsname.svg}
         }  
\DeclareGraphicsExtensions{.svg,.png,.jpg}
\begin{document}
\newcommand\AddFontFace[4]{%
\Css{@font-face {
    font-family: #1;
    src: local("#2"),
        url('#3');
    #4
 }}
\special{t4ht+@File: #3}
}
\edef\CurrentFontFamily{rmfamily}
\newcommand\SetFontFamily[1]{
\edef\CurrentFontFamily{#1}
}
\newcommand\NormalFont[2]{\AddFontFace{\CurrentFontFamily}{#1}{#2}{font-weight: normal;font-style: normal;}}

\newcommand\BoldFont[2]{\AddFontFace{\CurrentFontFamily}{#1}{#2}{font-weight: bold;font-style: normal;}}
\newcommand\ItalicFont[2]{\AddFontFace{\CurrentFontFamily}{#1}{#2}{font-weight: normal;font-style: italic;}}
\newcommand\BoldItalicFont[2]{\AddFontFace{\CurrentFontFamily}{#1}{#2}{font-weight: bold;font-style: italic;}}

\NormalFont{STIXDefault}{STIXGeneral-Regular.woff}
\BoldFont{STIXDefault}{STIXGeneral-Bold.woff}
\ItalicFont{STIXDefault}{STIXGeneral-Italic.woff}
\BoldItalicFont{STIXDefault}{STIXGeneral-BoldItalic.woff}
\Css{body{font-family:rmfamily, "STIXDefault", sans-serif;}}
\EndPreamble

important configurations are these:

  \Configure{graphics*}  
         {svg}  
          {\Picture[pict]{\csname Gin@base\endcsname.svg
          \space style="width:\CalcRem{\Gin@req@width}em;"
          }%  
          \special{t4ht+@File: \csname Gin@base\endcsname.svg}
         }  

this configures svg inclusion, \CalcRem command calculates relative size for given dimension, it is better to use relative units like em, than fixed sizes like pt or px. \special{t4ht+@File: command register file as tex4ht output, so we can include it in the opf manifest

now the fonts. basic command is:

\newcommand\AddFontFace[4]{%
\Css{@font-face {
    font-family: #1;
    src: local("#2"),
        url('#3');
    #4
 }}
\special{t4ht+@File: #3}
}

it registers font file for inclusion and declares necessary css properties.

  • Thanks, @michal.h21! Wish I had known this at the beginning! This is exactly my situation, I had pdfs in the book but wanted svgs in the ebook, so I dealt with them one-by-one. Fortunately, there are only four! So at this point, it's easiest to just use \special{t4ht+@File: ...}, which works great. It looks as though I do have to move the figure and font files by hand into the "project-format" directory, is that correct? – Nat Kuhn Nov 21 '14 at 11:35
  • 1
    @NatKuhn all files referenced by \special{t4ht+@File: ...} should be included in the output, if they are in current directory or in subdirectories – michal.h21 Nov 21 '14 at 11:38
  • Yes, that works, not sure why it didn't (or why I thought it didn't) previously. – Nat Kuhn Nov 21 '14 at 12:51

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.