Hi

Le 06/02/2023 à 11:41, jfbu a écrit :
Le 06/02/2023 à 06:29, atsuo ishimoto a écrit :
Hello list,

Currently, docs.python.org has stopped generating PDF documents in Japanese
due to a failure. I am trying to restart it by changing the latex engine
from platex to LuaTeX, but I need help with the following error.

Building following document causes Arithmetic overflow error with lualatex:

$ cat source/index.rst
1111111111111
#############

2222222222222
*************

3333333333333
=============

4444444444444
-------------

:class:`555555555555555`
^^^^^^^^^^^^^^^^^^^^^^^^

+-------------+------+
| 0000000     | AAAA |
|             +------+
|             | BBBB |
+-------------+------+

$ cat source/conf.py
project = 'test1'
copyright = '2023, a'
author = 'a'

extensions = []

templates_path = ['_templates']
exclude_patterns = []

language = 'ja'

html_theme = 'alabaster'
html_static_path = ['_static']

latex_engine="lualatex"

latex_docclass = {
'manual': 'ltjsbook',
'howto': 'ltjsarticle'
}

$ make latexpdf
...
...
! Arithmetic overflow.
\sphinx@@multirow ... \divide \count@ \count \tw@
                                                   \advance \dimen@ -\count@
...

l.64 \end{tabulary}


The error doesn't happen if I replace the row

:class:`555555555555555`
^^^^^^^^^^^^^^^^^^^^^^^^

with

the :class:`555555555555555`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I reproduced the error on Ubuntu and macOS.

Ubuntu:

$ sphinx-build --version
sphinx-build 6.1.3

$ lualatex --version
This is LuaHBTeX, Version 1.14.0 (TeX Live 2022/dev/Debian)

$ uname -a
Linux u2204 5.15.0-58-generic #64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023
x86_64 x86_64 x86_64 GNU/Linux

macOS:

$ sphinx-build --version
sphinx-build 6.1.3

$ lualatex --version
This is LuaHBTeX, Version 1.15.0 (TeX Live 2022)

$ uname -a
Darwin mbp16.local 21.4.0 Darwin Kernel Version 21.4.0: Mon Feb 21 20:34:37
PST 2022; root:xnu-8020.101.4~2/RELEASE_X86_64 x86_64

To reproduce, I created a github repository of the sphinx project at:
     https://github.com/atsuoishimoto/lualatex-arithmetic-overflow

With the repo, you can reproduce with:

$ git clone 
git-9UaJU3cA/F/qt0dzr+a...@public.gmane.org:atsuoishimoto/lualatex-arithmetic-overflow.git

Looks like some quirk happened here and it should be as above with 
https://github.com...

$ cd lualatex-arithmetic-overflow/sphinx-error
$ make latexpdf

As I am new to TeX, I cannot determine if this problem is due to  Sphinx's
TeX styles or a bug in LuaTeX. Any advice would be appreciated.

Regards,


Hi,

Thanks for your test projects.

This looks like a tough one, provisory conclusion is that this is not caused by 
Sphinx's LaTeX styles.

I am in the midst of pressing deadlines and can't examine it more thoroughly 
until next week, in particular I have not tried to produce a non-Sphinx example 
but expect for reasons I explain below that this will be easily feasible.

here is what I can say so far (thanks to your projects).

The error is a division by zero error.

This is caused by the box \@arstrutbox having zero height.  This height is 
queried by Sphinx in its multirow implementation.

The \@arstrutbox height is configured by the tabulary environment using 
\strutbox height.

The \strutbox height is unexpectedly having zero height at this location of 
start of tabulary.

But does not have zero height when `the` (or for that matter any Latin letter) 
is present at start of the preceding sectioning title.

Thus \strutbox is unexpectedly modifed by how this sectioning title looks, 
which is definitely not a Sphinx matter.

The \strutbox seems to have some specific Lualatex behavior which may involve 
the current direction of typesetting.  Here is what happens if I add 
\showthe\ht\strutbox after this sectioning title

good case

```
11.19995pt.
\strutbox ...etparameter {direction}=4 \ystrutbox
                                                   \else \tstrutbox \fi \fi
l.125 \showthe\ht\strutbox
```

bad case

```
0.0pt.
\strutbox ...etparameter {direction}=4 \ystrutbox
                                                   \else \tstrutbox \fi \fi
l.125 \showthe\ht\strutbox
```

(line numbering is meaningless due to added debugging stuff in produced LaTeX 
file)

A priori and after quick check nothing in Sphinx LaTeX files will deliberately 
modify \strutbox.

If I have time later I will try to produce a non-Sphinx minimal example.  It 
would go via trying to make a division by the height of the \strutbox.

I suspect a connection with direction of typesetting.  Maybe in vertical 
typesetting the \strutbox is interpreted to provide width, not height.  
Unfortunately I am both very ignorant in Lualatex specifics and in non-Latin 
scripts especially regarding not Left to Right usage of TeX.


As per

Currently, docs.python.org has stopped generating PDF documents in Japanese
due to a failure. I am trying to restart it by changing the latex engine
from platex to LuaTeX, but I need help with the following error.

Where can one see this failure? Maybe it will be easier to fix it than trying 
to use lualatex without a lualatex + Japanese + Sphinx expert available.

By the way Sphinx now uses uplatex which is Unicode aware.
------------
Running 'uplatex  -kanji=utf8  -recorder  "foo.tex"'
------------
This is e-upTeX, Version 3.141592653-p4.0.0-u1.28-220214-2.6 (utf8.uptex) (TeX 
Live 2023/dev) (preloaded format=uplatex)

however I suspect the "failure" was already tested with recent Sphinx and that 
the uplatex does not fix it as you report using Sphinx 6.1.3 in your test of Lualatex.

Could you please open a ticket at Sphinx, something with title "LaTeX: build failure 
if language is Japanese when using LuaLaTex (not pLaTeX)".  As I mentioned it will 
probably not be addressed before some time.  This is for documentation, as I expect that 
the issue is not directly imputable to Sphinx, in view of circumstances above.

Thanks

Jean-François





As workaround please try with this merged into your conf.py

latex_elements = {
   'preamble': r"""
\makeatletter
% we add a \normalsize to fix a ltjsbook + titlesec "\strutbox" problem
\titleformat{\subsubsection}{\normalsize\py@HeaderFamily}%
            {\py@TitleColor\thesubsubsection}{0.5em}{\py@TitleColor}
% also extra \normalsize here
\titleformat{\paragraph}{\normalsize\py@HeaderFamily}%
            {\py@TitleColor\theparagraph}{0.5em}{\py@TitleColor}
\titleformat{\subparagraph}{\normalsize\py@HeaderFamily}%
            {\py@TitleColor\thesubparagraph}{0.5em}{\py@TitleColor}
""",
}

and report here if it worked.  Perhaps there will be further unrelated issues.


Please open a ticket at https://github.com/sphinx-doc/sphinx/issues
linking to <d39abd23-6713-44b3-be93-4ba42844e3...@googlegroups.com>

Indeed, the addition of \normalsize can be perhaps done upstream at Sphinx as 
it looks non-breaking to existing projects.  I could not use the 
\py@HeaderFamily hook (which defaults to \sffamily\bfseries) because for 
section and chapter it comes after, not before, a font size change.

However the above is only a workaround.

It was obtained after reducing to the non-Sphinx situation as shown next.

The problem arises in Sphinx because Sphinx uses titlesec.

For some reason which only experts of Lualatex + ltjsbook can debug, the usage 
of titlesec will let a \leavevmode (which originates in your Sphinx example 
from a \texttt ultimately originating in the class role) at start of the 
subsubsection title cause the \strutbox to acquire a zero height.

But adding a \normalsize to the titlesec configuration for subsubsection fixes 
this.


---- pure ltjsbook + titlesec example demonstrating issue
\documentclass{ltjsbook}

% OK: not loading titlesec
% BAD: loading titlesec AND using for subsubsection the format as shown below
\usepackage{titlesec}
\titleformat{\subsubsection}{}{\thesubsubsection}{1em}{}

% BUT this format with \normalsize added would be OK
%%%% \titleformat{\subsubsection}{\normalsize}{\thesubsubsection}{1em}{}

\begin{document}

% for debugging attempts
% \tracingmacros1
% \tracingstacklevels1

% BAD with \leavevmode
% memo: \texttt{A} will cause \leavevmode hence be BAD

% In absence of \leavevmode the issue is not triggered.

\subsubsection{{\leavevmode A}}

% \tracingmacros0

\showthe\ht\strutbox % BAD IF 0pt, OK IF REASONABLE > 0pt

\end{document}
----

It would be too complex for me to pinpoint more precisely the root cause of the 
issue.

Strangely if one replaces *all* "subsubsection" everywhere in the above LaTeX code by 
"section" there is no problem even without the \normalsize.

Please report the above demonstrating file and my comments to the ltjsbook.cls 
maintainers
LuaTeX-ja is developed on

  <https://osdn.jp/projects/luatex-ja/wiki/FrontPage(en)>.

and perhaps to the titlesec maintainer

https://github.com/jbezos/titlesec

Jean-François




--
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sphinx-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sphinx-users/trr1nf%24nrq%241%40ciao.gmane.io.

Reply via email to