michal-h21 / tex4ebook

Converter from LaTeX to ebook formats (epub, mobi). Using tex4ht and texlua scripts.
311 stars 32 forks source link

babel/lualatex issue: english/greek/hebrew #94

Closed hanetzer closed 1 year ago

hanetzer commented 1 year ago

Finally pared this down to a mwe. Given the example at stackexchange, I've produced this mwe:

% vim: spell spelllang=en ft=tex
\documentclass[14pt,a4paper,english]{memoir}

\usepackage[bidi=basic, english]{babel}

\babelprovide[onchar=fonts ids]{ancientgreek}
\babelprovide[onchar=fonts ids]{hebrew}

\babelfont{rm}{Linux Libertine O}
\babelfont[*greek]{rm}{SBL BibLit}
\babelfont[*hebrew]{rm}{SBL BibLit}

\begin{document}

A Hebrew text is בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת הַשָּׁמַיִם וְאֵת
הָאָרֶץ, and a Greek one is Ἐν ἀρχῇ ἐποίησεν ὁ Θεὸς τὸν οὐρανὸν καὶ τὴν
γῆν.

\end{document}

This compiles fine with lualatex alone, resulting in: testmwe

Running it through tex4ebook results in:

tex4ebook -f mobi -l testmwe.tex -a debug[INFO]    mkparams: Output dir:
[INFO]    mkparams: Compiler: dvilualatex
[INFO]    mkparams: Latex options: -jobname=testmwe
[INFO]    mkparams: tex4ht.sty: xhtml,,charset=utf-8
[INFO]    mkparams: tex4ht:  -cmozhtf -utf8
[INFO]    mkparams: build_file: testmwe.mk4
[INFO]    mkparams: Output format: mobi
[STATUS]  tex4ebook: Conversion started
[STATUS]  tex4ebook: Input file: testmwe.tex
[INFO]    mkutils: Load extension       common_domfilters
[INFO]    tex4ebook: No conffile
[INFO]    mkutils: Cannot open config file      testmwe.mk4
[INFO]    exec_epub: remove dir testmwe-mobi
[INFO]    make4ht-lib: setting param correct_exit
[INFO]    make4ht-lib: setting param correct_exit
[INFO]    make4ht-lib: setting param correct_exit
[INFO]    make4ht-lib: setting param ext
[INFO]    exec_epub: Output file: testmwe.epub
[INFO]    htlatex: LaTeX call: dvilualatex --interaction=errorstopmode -jobname=testmwe   '\makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCode"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.{\AddToHook{class/before}{\RequirePackage[#1,html]{tex4ht}\RequirePackage{tex4ebook}}\let\HCode\documentstyle\def\documentstyle{\let\documentstyle\HCode\expandafter\def\csname tex4ht\endcsname{#1,html}\def\HCode####1{\documentstyle[tex4ht,}\@ifnextchar[{\HCode}{\documentstyle[tex4ht]}}}\makeatother\HCode xhtml,,charset=utf-8,charset=utf-8,mobi,uni-html4.a.b.c.\input "\detokenize{testmwe.tex}"'
This is LuaTeX, Version 1.14.0 (TeX Live 2022/dev/Debian)
 restricted system commands enabled.
LaTeX2e <2021-11-15> patch level 1
L3 programming layer <2022-01-21> (./testmwe.tex
(/usr/share/texlive/texmf-dist/tex/generic/tex4ht/tex4ht.sty)
(/usr/share/texlive/texmf-dist/tex/generic/tex4ht/usepackage.4ht)
(/usr/share/texlive/texmf-dist/tex/latex/tex4ebook/tex4ebook.sty
(/usr/share/texlive/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/share/texlive/texmf-dist/tex/latex/kvoptions/kvoptions.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty)
(/usr/share/texlive/texmf-dist/tex/generic/kvsetkeys/kvsetkeys.sty))
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/share/texlive/texmf-dist/tex/generic/tex4ht/graphics-hooks.4ht)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/dvips.def))))
(/usr/share/texlive/texmf-dist/tex/latex/memoir/memoir.cls
Document Class: memoir 2021/06/16 v3.7p configurable book, report, article docu
ment class
(/usr/share/texlive/texmf-dist/tex/generic/iftex/iftex.sty)
(/usr/share/texlive/texmf-dist/tex/latex/memoir/mem14.clo)
(/usr/share/texlive/texmf-dist/tex/latex/tools/array.sty)
(/usr/share/texlive/texmf-dist/tex/latex/tools/dcolumn.sty)
(/usr/share/texlive/texmf-dist/tex/latex/tools/delarray.sty)
(/usr/share/texlive/texmf-dist/tex/latex/tools/tabularx.sty)

LaTeX hooks Warning: Generic hook 'package/before/framed' is deprecated.
(hooks)              Use hook 'package/framed/before' instead.

(/usr/share/texlive/texmf-dist/tex/latex/textcase/textcase.sty)

LaTeX hooks Warning: Generic hook 'package/before/float' is deprecated.
(hooks)              Use hook 'package/float/before' instead.

) (/usr/share/texlive/texmf-dist/tex/generic/babel/babel.sty
(/usr/share/texlive/texmf-dist/tex/generic/babel/luababel.def)
(/usr/share/texlive/texmf-dist/tex/generic/babel/luababel.def
(/usr/share/texlive/texmf-dist/tex/luatex/luatexbase/luatexbase.sty
(/usr/share/texlive/texmf-dist/tex/luatex/ctablestack/ctablestack.sty)))
(/usr/share/texlive/texmf-dist/tex/generic/babel-english/english.ldf))
(/usr/share/texlive/texmf-dist/tex/generic/babel/locale/grc/babel-ancientgreek.
tex)
(/usr/share/texlive/texmf-dist/tex/generic/babel/locale/he/babel-hebrew.tex)
(/usr/share/texlive/texmf-dist/tex/generic/tex4ht/fontspec-hooks.4ht
(/usr/share/texlive/texmf-dist/tex/generic/tex4ht/usepackage-fontspec.4ht))
(/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec.sty
(/usr/share/texlive/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
(/usr/share/texlive/texmf-dist/tex/generic/tex4ht/expl3-hooks.4ht)
(/usr/share/texlive/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-dvips.def)))
(/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec-luatex.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty)
(/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec.cfg)))
(/usr/share/texlive/texmf-dist/tex/generic/babel/locale/en/babel-english.tex)

! LaTeX Error: Encoding scheme `' unknown.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.9 \babelfont{rm}{Linux Libertine O}

? q
OK, entering \batchmode[FATAL]   make4ht-lib: Fatal error. Command htlatex returned exit code 1

Not sure where to go from here.

michal-h21 commented 1 year ago

Try to save the following code as babel-sty-hooks.4ht:

% babel-sty-hooks.4ht, generated from tex4ht-4ht.tex
% Copyright 2022 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 2022-08-17-14:10}

\NewDocumentCommand\:babelfont{o m o m}{}

\:AtEndOfPackage{%
\let\babelfont\:babelfont
}

\ifdefined\recall:sup
\recall:sup
\:AtEndOfPackage{
  \early:sup
}
\fi

It suppress the \babelfont command, because it causes this fatal error.

hanetzer commented 1 year ago

same result; do I need to pass some extra flags or something to make it 'take'?

michal-h21 commented 1 year ago

Which TeX distribution do you use? It should work in up to date TeX Live.

hanetzer commented 1 year ago

I have two distributions. My daily driver is gentoo, and unfortunately they're behind, so I spun up a debian chroot to deal with it. The latter reports:

This is LuaHBTeX, Version 1.14.0 (TeX Live 2022/dev/Debian)

Execute  'luahbtex --credits'  for credits and version details.

There is NO warranty. Redistribution of this software is covered by
the terms of the GNU General Public License, version 2 or (at your option)
any later version. For more information about these matters, see the file
named COPYING and the LuaTeX source.

LuaTeX is Copyright 2021 Taco Hoekwater and the LuaTeX Team
hanetzer commented 1 year ago

erm, ubuntu chroot*

michal-h21 commented 1 year ago

It seems a bit old. You will probably need also this file, usepackage.4ht:

% usepackage.4ht (2022-11-21-13:19), generated from tex4ht-4ht.tex
% Copyright 2003-2009 Eitan M. Gurari
% Copyright 2009-2022 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 2022-11-21-13:19}

   \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 ,!*?: }
\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}
\Configure{PackageHooks}{titlesec.sty}{titlesec-hooks.4ht}
\Configure{PackageHooks}{biblatex-chicago.sty}{biblatex-chicago-hooks.4ht}
\Configure{PackageHooks}{cleveref.sty}{cleveref-hooks.4ht}
\Configure{PackageHooks}{xr.sty}{xr-hooks.4ht}
\Configure{PackageHooks}{xr-hyper.sty}{xrhyper-hooks.4ht}
\Configure{PackageHooks}{eso-pic.sty}{esopic-hooks.4ht}
\Configure{PackageHooks}{showframe.sty}{showframe-hooks.4ht}
\Configure{PackageHooks}{expl3.sty}{expl3-hooks.4ht}
\Configure{PackageHooks}{savetrees.sty}{savetrees-hooks.4ht}
\Configure{PackageHooks}{newcomputermodern.sty}{newcomputermodern-hooks.4ht}
\Configure{PackageHooks}{newcomputermodern.sty}{newcomputermodern-hooks.4ht}
\Configure{PackageHooks}{fontawesome5-utex-helper.sty}%
{fontawesome5-utex-helper-hooks.4ht}
\Configure{PackageHooks}{fontawesome5.sty}{fontawesome5-hooks.4ht}
\Configure{PackageHooks}{biblatex.sty}{biblatex-hooks.4ht}
\Configure{PackageHooks}{xeCJK.sty}{xecjk-hooks.4ht}
\Configure{PackageHooks}{unicode-math.sty}{unicode-math-hooks.4ht}
\Configure{PackageHooks}{ctex.sty}{ctex-hooks.4ht}
\AddToHook{class/ctexart/before}{\input{ctexart-hooks.4ht}}
\Configure{PackageHooks}{luatexja.sty}{luatexja-hooks.4ht}
\Configure{PackageHooks}{luatexja-fontspec.sty}{luatexja-hooks.4ht}
\Configure{PackageHooks}{polyglossia.sty}{polyglossia-hooks.4ht}
\Configure{PackageHooks}{fontspec.sty}{fontspec-hooks.4ht}
\Configure{PackageHooks}{tikz.sty}{tikz-hooks.4ht}
\Configure{PackageHooks}{pdfbase.sty}{pdfbase-hooks.4ht}
\Configure{PackageHooks}{pdfx.sty}{pdfx-hooks.4ht}
\Configure{PackageHooks}{lua-widow-control.sty}{lua-widow-control-hooks.4ht}
\Configure{PackageHooks}{tagpdf.sty}{tagpdf-hooks.4ht}
\Configure{PackageHooks}{breakurl.sty}{breakurl-hooks.4ht}
\Configure{PackageHooks}{hyperref.sty}{hyperref-hooks.4ht}
\Configure{PackageHooks}{bookmark.sty}{bookmark-hooks.4ht}
\Configure{PackageHooks}{caption.sty}{caption-hooks.4ht}
\Configure{PackageHooks}{footnotebackref.sty}{footnotebackref-hooks.4ht}
\AddToHook{package/doc/before}{\SUPOff}
\AddToHook{package/doc/after}{\SUPOn}
\AddToHook{package/hypdoc/before}{\SUPOff}
\AddToHook{package/hypdoc/after}{\SUPOn}
\Configure{PackageHooks}{babel.sty}{babel-sty-hooks.4ht}
\Configure{PackageHooks}{minted.sty}{minted-sty-hooks.4ht}
\Configure{PackageHooks}{graphics.sty}{graphics-hooks.4ht}
\Configure{PackageHooks}{graphbox.sty}{graphbox-hooks.4ht}
\Configure{PackageHooks}{xcolor.sty}{xcolor-hooks.4ht}
\Configure{PackageHooks}{imakeidx.sty}{imakeidx-hooks.4ht}
\Configure{PackageHooks}{fancyhdr.sty}{fancyhdr-hooks.4ht}
\Configure{PackageHooks}{exerquiz.sty}{exerquiz-hooks.4ht}
\Configure{PackageHooks}{hyperxmp.sty}{hyperxmp-hooks.4ht}
\Configure{PackageHooks}{datetime2.sty}{datetime2-hooks.4ht}

\endinput
hanetzer commented 1 year ago

What distro/version are you using? As the above barfs on bookmark-hooks.4ht

michal-h21 commented 1 year ago

I am using vanilla TeX Live updated to the latest version.

The \Configure{PackageHooks}{package name}{config file} command in usepackage.4ht tries to load the config file when you load the package name in your document. Some of these config files may be missing on your system, as you have an older TL version. In this case, you can remove the line with the missing config file.

hanetzer commented 1 year ago

I am using vanilla TeX Live updated to the latest version.

I mean linux distro/or windows/mac, whatever. Trying to find where I can 'get' this version easily enough without a manual compile/install. Nixing the package hook line for bookmarks gets me further on the mwe but unfortunately the full doc barfs out here:

Package biblatex Warning: Patching footnotes failed.
(biblatex)                Footnote detection will not work.

(./fulldoc.aux) (/usr/share/texmf-dist/tex/latex/base/ts1cmr.fd
) (/usr/share/texmf-dist/tex/generic/hyph-utf8/loadhyph/loadhyph-en-us.tex
ASCII Hyphenation patterns for American English
(/usr/share/texmf-dist/tex/generic/hyph-utf8/patterns/tex/hyph-en-us.tex))
(/usr/share/texmf-dist/tex/latex/biblatex/lbx/english.lbx)
No file fulldoc.bbl.
(/usr/share/texmf-dist/tex/latex/ragged2e/ragged2e.sty)
(/usr/share/texmf-dist/tex/generic/soulutf8/soulutf8.sty
(/usr/share/texmf-dist/tex/generic/soul/soul.styUnsupported font        ectt1000
))
(/usr/share/texmf-dist/tex/latex/pdflscape/pdflscape.sty
(/usr/share/texmf-dist/tex/latex/graphics/lscape.sty
(/usr/share/texmf-dist/tex/generic/tex4ht/graphics-hooks.4ht)))
! TeX capacity exceeded, sorry [input stack size=5000].
\old:outputpage ->\old:outputpage
                                  {}
l.134

 3079 words of node memory still in use:
   9 hlist, 2 vlist, 1 rule, 2 local_par, 1 dir, 15 glue, 3 kern, 3 penalty, 4
glyph, 248 attribute, 224 glue_spec, 216 attribute_list, 1 temp, 4 if_stack, 1
open, 5 write, 218 special nodes
   avail lists: 1:5,2:6,4:2,5:4,8:1
!  ==> Fatal error occurred, bad output DVI file produced!
No pages of output.
Transcript written on fulldoc.log.
[FATAL]   make4ht-lib: Fatal error. Command htlatex returned exit code 1
michal-h21 commented 1 year ago

I am no Fedora. The error from your last post seems to be related to the pdfbase package, but I still think that it must be a version mismatch, because I cannot really reproduce it.

You can also try to disable the problematic packages from loading directly in your TeX file, like this:

% vim: spell spelllang=en ft=tex
\documentclass[14pt,a4paper,english]{memoir}

\usepackage[bidi=basic, english]{babel}
\usepackage{pdflscape}
\usepackage{bookmark}

\ifdefined\HCode\else
\babelprovide[onchar=fonts ids]{ancientgreek}
\babelprovide[onchar=fonts ids]{hebrew}

\babelfont{rm}{Linux Libertine O}
\babelfont[*greek]{rm}{SBL BibLit}
\babelfont[*hebrew]{rm}{SBL BibLit}
\fi

\begin{document}

A Hebrew text is בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת הַשָּׁמַיִם וְאֵת
הָאָרֶץ, and a Greek one is Ἐν ἀρχῇ ἐποίησεν ὁ Θεὸς τὸν οὐρανὸν καὶ τὴν
γῆν.

\end{document}

In this way, you don't need usepackage.4ht, so you shouldn't experience these clashes between different versions of files.

hanetzer commented 1 year ago

Ok so I ended up just biting the bullet and installing the netinst version to my home folder and purged out the distro packages. This solves my mwe issue wrt all of the above, without any *.4ht files. (install-tl-unx.tar.gz which unpacked to install-tl-20221124).

I've managed to pare it down to work 'more' but I'm still getting unrelated issues, so I'll close this, as the subject matter issue was solved by either updating or using your 4ht files/\ifdefined\HCode bits.