1

I'm trying to convert to ePub an english commentary of a Tibetan text which includes some mantras in Tibetan writing and helpful pronunciation, using tex4ebook. The follow test.tex is an example:

% !TEX encoding = UTF-8 Unicode
\documentclass[12pt,oneside]{book}   
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{ctib}

\begin{document}

Some text ...

O\d{M} \=A\d{H}  H\=U\d{M}

{\tib \om, ma nxi pa\V{de}{ma} \hung \hrih:}

\end{document}

Compilation with the following works as expected:

lualatex test.tex or pdflatex test.tex

To create the epub version I am trying:

 tex4ebook -l -c config test.tex

end config.cfg is:

\Preamble{xhtml}
\CutAt{section}
\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;}}

The problem is the output about mantras and the diacritics characters in the ePub version. Any help would be very appreciated. Thanks.

  • would you mind if the mantras came as a picture? – michal.h21 Apr 6 '17 at 15:15
  • I wouldn't prefer but as a first solution it is ok. A mantra is a sequence of sillabe and a single picture of them is ok. How can I generate a picture from the mantras? A different case is the characters \d{M} or \d{H}. The output is a picture but the effect of glue characters and picture is ugly. There is a way to print that characters? Thanks – Roberto Apr 7 '17 at 7:29
  • I am able to generate a picture for the mantras and insert it into the text. Sorry. What about the diacritics? – Roberto Apr 7 '17 at 7:36
1

There are two problems: letters with dot under accents are converted as pictures and Tibetan text comes as mix of Unicode letters and pictures with some letters missing:

enter image description here

We have to provide configuration with Unicode values for each letter with dot bellow accent. I took a look at how accenting commands are configured in tex4ht and found the following configuration:

\expand:after{\expand:after{\Configure{accent}}%
 \csname OT1\string\d\endcsname}%
 \csname OT1\string\d\endcsname{{}{}}
 {\a:accents{d}{#1}}     {\b:accents{d}{#1}{#2}}

It looks a little bit cryptic, but the point is that there should be list of letters followed by Unicode codepoints for the combined letter in this place: \csname OT1\string\d\endcsname{{}{}}. When configuration for a letter is missing, it is converted as image, as can be seen in your sample.

It should look like this instead:

\expand:after{\expand:after{\Configure{accent}}%
 \csname OT1\string\d\endcsname}%
  \csname OT1\string\d\endcsname{A{1EA0}a{1Ea1}B{1E04}b{1E05}D{1E0C}d{1E0D}%
  E{1EB8}e{1EB9}H{1E24}h{1E25}I{1ECA}i{1ECB}%
  K{1E32}k{1E33}L{1E36}l{1E37}M{1E42}m{1E43}%
  N{1E46}n{1E47}O{1ECC}o{1ECD}R{1E5A}r{1E5B}%
  S{1E62}s{1E63}T{1E6C}t{1E6D}U{1EE4}u{1EE5}%
  V{1E7E}v{1E7F}W{1E88}w{1E89}Y{1EF4}y{1EF5}%
  {}{}}
     {\a:accents{d}{#1}}     {\b:accents{d}{#1}{#2}}

Regarding the mantras, ctib uses some Metafont trickery to convert the transliterated text to images. It seems that it is not realistic to expect it to translate to Unicode flawlessly, so I would convert it to an image instead. You can introduce some simple command, which will be used in the document:

\newcommand\mantra[1]{\bgroup\tib #1\egroup}
...
\mantra{\om, ma nxi pa\V{de}{ma} \hung \hrih:}

And redefine it in the config file:

\renewcommand\mantra[1]{\Picture+{}\bgroup\tib #1\egroup\EndPicture}

The full configuration file would look like this:

\Preamble{xhtml}
\CutAt{section}
\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{\csname Gin@req@width\endcsname}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;}}

%  patch for \mantra command
\renewcommand\mantra[1]{\Picture+{}\bgroup\tib #1\egroup\EndPicture}
% Use the following configuration if you want to convert mantras to SVG instead of PNG
% Note that the compilation time is longer and the resulting SVG file much bigger
% \Configure{Picture}{.svg}
% Configuration for \d accent
\catcode`\:=11
\expand:after{\expand:after{\Configure{accent}}%
 \csname OT1\string\d\endcsname}%
  \csname OT1\string\d\endcsname{A{1EA0}a{1Ea1}B{1E04}b{1E05}D{1E0C}d{1E0D}%
  E{1EB8}e{1EB9}H{1E24}h{1E25}I{1ECA}i{1ECB}%
  K{1E32}k{1E33}L{1E36}l{1E37}M{1E42}m{1E43}%
  N{1E46}n{1E47}O{1ECC}o{1ECD}R{1E5A}r{1E5B}%
  S{1E62}s{1E63}T{1E6C}t{1E6D}U{1EE4}u{1EE5}%
  V{1E7E}v{1E7F}W{1E88}w{1E89}Y{1EF4}y{1EF5}%
  {}{}}
     {\a:accents{d}{#1}}     {\b:accents{d}{#1}{#2}}
\catcode`\:=12

\EndPreamble

And this is the result:

enter image description here

  • Thank you very much. Your answer is a perfect solution. It works perfectly. Thanks. – Roberto Apr 7 '17 at 9:46

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.