4

I am trying to create a Marathi ebook using the packages Polyglossia an tex4ebook. Following is the MWE I prepared following the instructions from @michal.h21 (which were given to produce the MWE that had merely the text and they worked well, thanks to Michal):

\documentclass{article}

%Setting Marathi as main language and Shobhika as main font using package Polyglossia.
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage[numerals=devanagari]{marathi}
\setmainfont[Script=Devanagari, Mapping=devanagarinumerals]{Shobhika}
\newfontfamily\marathifont[Script=Devanagari, Mapping=devanagarinumerals]{Shobhika}

%Index detail
\usepackage{imakeidx}
\makeindex[name=Art,title={लेखांची सूची},intoc]
\makeindex[intoc]

\begin{document}
\author{रोहित दिलीप होळकर}
\title{मराठी ई-पुस्तक}

\maketitle
\tableofcontents

\section{ई-बुक}

टेक्-४-ई-बुक पॅकेज वापरून मराठी इ-पुस्तके बनवणे.

\section{सूचीकरीता लिखाण}
मी टेक्-४-ई-बुक पॅकेज \index[Art]{पुस्तक! ई-पुस्तक} वापरून पुस्तक\index{पुस्तक} बनवण्याचा प्रयत्न करीत आहे.

\printindex
\printindex[Art]

\end{document}

% Local Variables:
% TeX-engine: xetex
% End:

This produces a desired output when XeLaTeX is used--- the default index is title "सूची" and the other one "लेखांची सूची". If Hyperref is used, hyperlinks are produced. However, this does not work perfectly when tex4ebook -x "tex-file" is used. Following five are the issues:

  1. Devanagari ligatures do not work for the author-name in \maketitle command, see the image below:

title page

  1. When I use Pandoc to prepare ebooks, table of contents is created in the left top corner close to the book icon. That does not happen with tex4book. I find the toc that pandoc creates more useful for ebooks. Compare the following screenshot (of the ebook prepared using Pandoc) with the one in 1 above: enter image description here Moreover, the intoc parameter for \makeindex does not make the indexes appear in the toc.
  2. As per my knowledge, the preamble I have written is sufficient to use Devanagari numerals in the document if (Xe)LaTeX is used. However, tex4ebook uses Arabic numerals for sections as well as page-numbers. See the screenshot below and the next point: enter image description here
  3. XeLaTeX titles the index as "सूची" for language Marathi. The other index which I have made using package imakeidx comes appropriately title when XeLaTeX is used. However, tex4ebooks does not title any of the indexes at all. See the screenshot:enter image description here
  4. Finally, tex4ebook did not create hyperlinks even after using package hyperref.

I am not used to TeX or developmental issues but I use LaTeX decently. Following this discussion that Michal sent me, I created imakeidx.4ht file in the directory /usr/local/texlive/2018/texmf-dist/tex/generic/tex4ht/. (It may sound stupid, however,) I also tried replacing contents of idxmake.4ht by the one discussed in the answer of above discussion. However, it did not work out.

An answer, with possibly, step-by-step instructions, and some explanation will be useful. A general explanation of using imakeidx with Polyglossia for non-latin script shall be welcome! Thanks in advance!

Note: \setmainlanguage{marathi} might not work; in that case use sanskrit or hindi as the language, and ignore the index names that could appear in English. FYI, I am using MacTeX 2018.

  • I hope that I will be able to look at these issues tomorrow – michal.h21 May 2 '18 at 15:55
  • I am still investigating it, I've found several bug in tex4ebook and tex4ht, so it will take more time than I expected. – michal.h21 May 4 '18 at 11:33
  • I've updated tex4ht for Unicode support in the preamble. It fixes the issue with missing labels for table of contents and similar. The update should be available in TL in few days. – michal.h21 May 8 '18 at 11:17
3

You've found quite a lot issues. I've found issues in tex4ht, tex4ebook and make4ht. I had to fix lot of files, so I cannot post the correct versions here, this post would be too large. It is necessary to wait few days until everything is fixed in TL (yes, it will work only in TL 2018, I am not sure about Miktex).

ad 1)

title is printed in different font and due to bug in tex4ht, all characters are wrapped in <span> elements. Some viewers can display it correctly, others, as your Ebook viewer will display them separately, which result in wrong rendering. You can fix it using tex4ebook extension common_domfilters, which joins consecutive <span> elements into one. It is then displayed correctly.

To request it use:

 tex4ebook -xf epub3+common_domfilters filename.tex

enter image description here

ad second 1)

tex4ebook creates TOC, I don't know why it doesn't work in your viewer:

enter image description here

ad 2)

tex4ht redefines sections, so it doesn't use the Devanagari numbers. It can be fixed using configuration, which I will show later.

ad 3)

this was caused by the way tex4ht handled Unicode with XeTeX. It was enabled only after preamble, which means that names declared by Polyglossia didn't work. I fixed that in the sources, but it will take few days until everything is updated. Try the following updated TeX file:

\documentclass{article}

%Setting Marathi as main language and Shobhika as main font using package Polyglossia.
\usepackage{fontspec}
\setmainfont[Script=Devanagari, Mapping=devanagarinumerals]{Shobhika}
\newfontfamily\marathifont[Script=Devanagari, Mapping=devanagarinumerals]{Shobhika}
\usepackage{polyglossia}
\setmainlanguage[numerals=devanagari]{marathi}

%Index detail
\usepackage[noautomatic,xindy]{imakeidx}
\makeindex[name=Art,title={लेखांची सूची},intoc]
\makeindex[intoc]

\begin{document}
\author{रोहित दिलीप होळकर}
\title{मराठी ई-पुस्तक}

\maketitle
\tableofcontents

\section{ई-बुक}

टेक्-४-ई-बुक पॅकेज वापरून मराठी इ-पुस्तके बनवणे.

\section{सूचीकरीता लिखाण}
मी टेक्-४-ई-बुक पॅकेज \index[Art]{पुस्तक! ई-पुस्तक} वापरून पुस्तक\index{पुस्तक} बनवण्याचा प्रयत्न करीत आहे.
\subsection{subsection}

xxx

\printindex
\printindex[Art]

\end{document}

% Local Variables:
% TeX-engine: xetex
% End:

It is necessary to declare some font with Script=Devanagari option before loading Polyglossia!

enter image description here

ad 4)

It is necessary to use special configuration for Xindy to get index links working. It also use section numbers instead of page numbers as index locations, as pages don't exist anymore.

The configuration is provided by indexing4ht package, which is part of helpers4ht bundle, which needs to be installed manually.

The following configuration file mycfg.cfg fixes some issues with the index and the Devanagari section numbers:

\usepackage{indexing4ht}
\Preamble{xhtml}
\Configure{textbf}{\ifvmode\EndP\fi\HCode{<strong>}\NoFonts}{\EndNoFonts\HCode{</strong>}}
\begin{document}
\ConfigureMark{section}{\devanagaridigits{\number\thesection}}
\makeatletter
\ConfigureMark{subsection}{\devanagaridigits{\number\c@section.}\devanagaridigits{\number\c@subsection}}
\def\tocsection#1#2#3{\par
           \HCode{<span class="sectionToc" \csname a:LRdir\endcsname>}\def\@temp{#1}\ifx \@temp\empty\else
         \devanagaridigits{#1} \fi #2\HCode{</span>}\par}
\expandafter\def\csname toc:num\endcsname#1#2#3{\def\@temp{#1#2}%
   \HCode{<span class="#1Toc" \csname a:LRdir\endcsname>}\ifx \@temp\empty
      \else \def\@temp{#2}\ifx\@temp\empty\else \devanagaridigits{#2} \fi \fi #3\HCode{</span>}}
\renewcommand\idxkeyword[1]{%
  \global\advance\idxkwdcnt by 1\relax%
  \csname a:IdxKW\endcsname{}{idxkw\the\idxkwdcnt}#1\csname b:IdxKW\endcsname
}

% print index locators. make links to destinations in document
\renewcommand\idxlocator[1]{%
\ifTag{sec#1}{\csname a:locatorlink\endcsname{\Ref{sec#1}}{}\devanagaridigits{#1}\csname b:locatorlink\endcsname}{#1}%
}

\makeatother
\EndPreamble

To invoke Xindy, it is necessary to use a build file, mybuild.mk4:

Make:add("xindy", function(par)
  -- par.encoding  = par.encoding or "utf8"
  -- par.language = par.language or "english"
  par.idxfile = par.idxfile or par.input .. ".idx"
  local modules = par.modules or {}
  local t = {}
  for k,v in ipairs(modules) do
    t[#t+1] = "-M ".. v
  end
  par.moduleopt = table.concat(t, " ")
  local xindy_call = "xindy -L ${language} -C ${encoding} ${moduleopt} ${idxfile}" % par
  print(xindy_call)
  return os.execute("xindy -L ${language} -C ${encoding} ${moduleopt} ${idxfile}" % par)
end, {modules = {"texindy"}, language = "english", encoding = "utf8"})

Make:htlatex {}
Make:xindy {modules = {"filename"}, language = "marathi"}
Make:xindy {modules = {"filename"}, language = "marathi", idxfile = "Art.idx"}
Make:htlatex {}

The modules should contain filename which should be same as the basename of the TeX file. idxfile in the second invocation of Xindy requires Art.idx, the first one use filename.idx by default.

It is also necessary to install Marathi support for Xindy, from Zdeněk Wagners page

This is the resulting index:

enter image description here

The command used for compilation is:

tex4ebook -e mybuild.mk4 -xf epub3+common_domfilters  -c mycfg.cfg filename.tex

There are still more issues, like missing index headers in table of contents or arabic numbers in TOC. I can investigate these issues later.

  • Thanks a lot Michal! I shall need some time to go through your answers. I am also waiting for the updates. I have already upgraded to TeXLIve 2018. – Rohit D. Holkar May 11 '18 at 6:29
  • @RohitD.Holkar TL should be updated already, there is only one missing file, but it shouldn't affect you. Try to run tlmgr update --all. – michal.h21 May 11 '18 at 7:05

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.