2

I take this minimal example for document. I need 'polyglossia'.

\documentclass{article}

\usepackage{polyglossia}
%\usepackage[utf8]{inputenc} 
\setdefaultlanguage{arabic}
\newfontfamily\arabicfont[Script=Arabic]{Scheherazade} 
\setotherlanguage{english}
\begin{document}

شكرا 

\begin{english} Thanks \end{english}

\end{document}

Compiling with 'xelatex' works and I get the correct pdf file.

How can I get the apropriate html file ?

I've tried 'hlxelatex' but I get this message:

(/usr/share/texmf-dist/tex/generic/tex4ht/html4-math.4ht)) (./polygl.aux)
! You can't use `\relax' after \the.
\NoHtmlEnv ....0pt\ht:everypar {\the \ht:everypar 
                                                  }
l.8 \begin{document}

? 

When I remove the arabic word شكرا it also doesn't work, I have to remove the two lines in the preamble too, to get a html file.

I also tried 'tex4ht' and 'make4ht' with this simple file, I couldn't find a solution.

Any suggestions what to do or to try?

2

I was able to convert your file with slight change:

\documentclass{article}

\usepackage{fontspec}
\usepackage{polyglossia}
%\usepackage[utf8]{inputenc} 
\setdefaultlanguage{arabic}

\newfontfamily\arabicfont{Scheherazade}[Script=Arabic]
\setotherlanguage{english}
\begin{document}

شكرا 

\begin{english} Thanks \end{english}

شكرا 

\end{document}

It seems there is an issue with Arabic support for Polyglossia in TeX4ht at the moment. It can be fixed with the following file, usepackage.4ht. It contains fixes that should be executed when the packages are loaded

% usepackage.4ht (2019-10-31-14:15), generated from tex4ht-4ht.tex
% Copyright 2003-2009 Eitan M. Gurari
% Copyright 2009-2019 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2019-10-31-14:15}

   \def\:temp{tex4ht}\ifx \:temp\@currname
   \:warning{\string\usepackage{tex4ht} again?}
   \def\:temp#1htex4ht.def,tex4ht.sty#2!*?: {\def\:temp{#2}}
\expandafter\:temp \@filelist htex4ht.def,tex4ht.sty!*?: %
\ifx \:temp\empty  \else
   \:warning{if
    \string\RequirePackage[tex4ht]{hyperref} or
    \string\usepackage[tex4ht]{hyperref} was
    used try instead, repectively,
    \string\RequirePackage{hyperref} or
    \string\usepackage{hyperref}}
\fi

\fi
\gdef\a:usepackage{\use:package
xr,xr-hyper,eso-pic,expl3,savetrees,biblatex,xeCJK,polyglossia,fontspec,tikz,pdfbase,graphics,xcolor,imakeidx,minted,fancyhdr,,!*?:
}
\gdef\use:package#1,{%
   \if :#1:\def\:temp##1!*?: {}\else
      \def\:temp{#1}\ifx \@currname\:temp
             \def\:temp##1!*?: {\input usepackage.4ht  }%
      \else \let\:temp=\use:package \fi
   \fi \:temp}
\def\:temp{xr}\ifx \@currname\:temp
   \AtEndOfPackage{\let\XR:\XR@
   \def\XR@[#1]#2{%
    \Configure{AtBeginDocument}{\XR:[#1]{#2}}{}}%
}

\fi
\def\:temp{xr-hyper}\ifx \@currname\:temp
   \AtEndOfPackage{\let\XR:\XR@
    \def\XR@[#1][#2]#3{%
      \AtBeginDocument{\XR:[#1][#2]{#3}}
    }%
}

\fi
\def\:temp{eso-pic}\ifx \@currname\:temp
\:dontusepackage{eso-pic}
\newcommand\AddToShipoutPicture{\@ifstar{}{}}
\let\AddToShipoutPictureBG\AddToShipoutPicture
\let\AddToShipoutPictureFG\AddToShipoutPicture
\fi
\def\:temp{expl3}\ifx \@currname\:temp
\ifdefined\XeTeXversion%
\xenunidelblock{Latin-expl3}%
\AtEndOfPackage{\xeuniuseblock{Latin-expl3}}
\fi
\fi
\def\:temp{savetrees}\ifx \@currname\:temp
\:dontusepackage{savetrees}
\fi
\def\:temp{biblatex}\ifx \@currname\:temp
\AtEndOfPackage{%
  \def\blx@mknoautolang{%
    \blx@lbxinput{\blx@languagename}%
    {}{}%
  }%
  \def\blx@lbxinput@iii#1#2{%
  \global\csundef{blx@lng@#2}%
  \:IfFileExists{#1.lbx}
    {\blx@lbxinput@iv{#2}{#1}{language '#2' -> '#1'}}
    {\ifcsdef{blx@suffmaptried@#2}
      {}
      {\blx@warning@noline{%
          File '#1.lbx' not found!\MessageBreak
          Ignoring mapping '#2' -> '#1'}%
       \global\cslet{blx@suffmaptried@#2}\@empty}%
     \blx@lbxinput@iv{#2}{#2}{language '#2'}}}

}
\fi
\def\:temp{xeCJK}\ifx \@currname\:temp
\:dontusepackage{xeCJK}
\AtEndOfPackage{%
  \RequirePackage{fontspec}
}
\DeclareDocumentCommand\setCJKmainfont{o m o}{}
\let\setCJKsansfont\setCJKmainfont
\let\setCJKmonofont\setCJKmainfont

\DeclareDocumentCommand\setCJKfamilyfont {m o m }{}
\DeclareDocumentCommand\newCJKfontfamily {o m o
m}{\expandafter\gdef\csname #2\endcsname{\relax}}

\DeclareDocumentCommand\xeCJKsetup{m}{}
% }
\AtBeginDocument{%
  \xeuniuseblock{CJK}
}
\fi
\def\:temp{polyglossia}\ifx \@currname\:temp
\ExplSyntaxOn
\AtEndOfPackage{

\cs_set_eq:NN\orig_polyglossia@keys_define_lang:n\polyglossia@keys_define_lang:n
\cs_set_protected:Npn \polyglossia@keys_define_lang:n #1 {
  \orig_polyglossia@keys_define_lang:n{#1}
  \keys_define:nn {polyglossia}{
    #1 / direction
    .  code:n = {}
}
}
\def\RequireBidi{}%
}
\ExplSyntaxOff
\fi

\def\:temp{fontspec}\ifx \@currname\:temp
  \ifdefined\fontspec
    \:dontusepackage{fontspec}
  \else
    \input usepackage-fontspec.4ht
  \fi
\fi
\def\:temp{tikz}\ifx \@currname\:temp
\AtEndOfPackage{%
\let\use:tikzlibrary\usetikzlibrary
\def\find:externalize#1external#2\@nil{%
\if\relax#2\relax\else
  \let\tikz:externalize\tikzexternalize
  \renewcommand\tikzexternalize[1][]{\tikz:externalize[##1,mode=only graphics]}
    \tikzset{%
      tex4ht inc/.style={%
        /pgf/images/include external/.code={%
          \includegraphics[]{####1.pdf}%
        }%
      }
    }
    \tikzset{tex4ht inc}
  \fi
}
\renewcommand\usetikzlibrary[1]{%
  \use:tikzlibrary{#1}%
  \find:externalize#1external\@nil%
}
}
\fi
\def\:temp{pdfbase}\ifx\@currname\:temp
\AtEndOfPackage{%
  \let\old:outputpage\@outputpage
  \def\@outputpage{\old:outputpage{}}
}
\fi
\def\:temp{graphics}\ifx\@currname\:temp
  \ifdefined\XeTeXversion
    \PassOptionsToPackage{dvips}{graphics}
  \fi
\fi
\def\:temp{xcolor}\ifx\@currname\:temp
  \ifdefined\XeTeXversion
    \PassOptionsToPackage{dvips}{xcolor}
  \fi
\fi
\def\:temp{imakeidx}\ifx\@currname\:temp
  \PassOptionsToPackage{noautomatic}{imakeidx}
\fi
\def\:temp{minted}\ifx\@currname\:temp
  \AtEndOfPackage{%
    \define@booleankey{minted@opt@g}{breaklines}{}{}{}%
  }
\fi
\def\:temp{fancyhdr}\ifx\@currname\:temp
  \AtEndOfPackage{%
  \def\ps@fancy{}%
  }
\fi


\endinput

With this change the document compiles. It is also necessary to fix the text direction. We can use a configuration file for this:

\Preamble{xhtml}
\Configure{LRdir}{ dir="rtl"}
\ConfigureEnv{english}{\bgroup\Configure{LRdir}{ dir="ltr"}}{\egroup}{}{}
\begin{document}
\EndPreamble

The LRdir configuration is used to configure the text direction. We define the RTL direction, used in Arabic as the main text direction. For English text the LTR direction will be used.

Compile using

 make4ht -ux -c config.cfg filename.tex

This is the result:

enter image description here

| improve this answer | |
  • Thanks! It has worked as you has described. (I didn't mention it but I also have 'xecolour': \red{Thanks} stays black in the html conversion. I know: it's another question.) – rl1 Dec 13 '19 at 8:48
  • @rl1 in general, switch commands like \color are quite impossible to support. it is better to use \textcolor, which is supported. I don't know about xecolour, but it should be possible to add a support. feel free to post a new question. – michal.h21 Dec 13 '19 at 8:57
  • I will. Some tests before. – rl1 Dec 13 '19 at 9:23

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.