clerkma / ptex-ng

Asiatic pTeX
293 stars 31 forks source link

特定条件会触发长度计算错误(溢出?) #7

Closed leo-liu closed 8 years ago

leo-liu commented 8 years ago

凑出来的重现代码:

\documentclass{minimal}
\usepackage{amsmath}
\usepackage{array}

\begin{document} 
\begin{gather}
  \begin{matrix} a \end{matrix} \\
\end{gather}
\end{document}

算不上最小示例,但把 amsmatharray 宏包里面的宏解析出来估计比较费时。总之足够重现错误了。

无论是使用 W32TeX 的预编译版本还是目前库里面的版本,就会触发 ! Dimension too large. 的错误。我估计是哪里计算长度的时候溢出了。

同样的代码,uplatex 编译是没有问题的。

详细的 log 为:

This is Asian pTeX, Version 3.14159265 (W32TeX) (preloaded format=platex-ng 2016.2.26)  2016 MAR 25 11:20
entering extended mode
**z
(z.tex
pLaTeX2e <2011/05/07u00>+0 (based on LaTeX2e <2016/02/01> patch level 0)
Babel <3.9q> and hyphenation patterns for 81 language(s) loaded.
(c:/texlive/2015/texmf-dist/tex/latex/base/minimal.cls
Document Class: minimal 2001/05/25 Standard LaTeX minimal class
) (c:/texlive/2015/texmf-dist/tex/latex/amsmath/amsmath.sty
Package: amsmath 2016/03/03 v2.15a AMS math features
\@mathmargin=\skip41

For additional information on amsmath, use the `?' option.
(c:/texlive/2015/texmf-dist/tex/latex/amsmath/amstext.sty
Package: amstext 2000/06/29 v2.01 AMS text

(c:/texlive/2015/texmf-dist/tex/latex/amsmath/amsgen.sty
File: amsgen.sty 1999/11/30 v2.0 generic functions
\@emptytoks=\toks15
\ex@=\dimen118
))
(c:/texlive/2015/texmf-dist/tex/latex/amsmath/amsbsy.sty
Package: amsbsy 1999/11/29 v1.2d Bold Symbols
\pmbraise@=\dimen119
)
(c:/texlive/2015/texmf-dist/tex/latex/amsmath/amsopn.sty
Package: amsopn 1999/12/14 v2.01 operator names
)
\inf@bad=\count81
LaTeX Info: Redefining \frac on input line 199.
\uproot@=\count82
\leftroot@=\count83
LaTeX Info: Redefining \overline on input line 297.
\classnum@=\count84
\DOTSCASE@=\count85
LaTeX Info: Redefining \ldots on input line 394.
LaTeX Info: Redefining \dots on input line 397.
LaTeX Info: Redefining \cdots on input line 518.
\Mathstrutbox@=\box41
\strutbox@=\box42
\big@size=\dimen120
LaTeX Font Info:    Redeclaring font encoding OML on input line 630.
LaTeX Font Info:    Redeclaring font encoding OMS on input line 631.
\macc@depth=\count86
\c@MaxMatrixCols=\count87
\dotsspace@=\muskip10
\c@parentequation=\count88
\dspbrk@lvl=\count89
\tag@help=\toks16
\row@=\count90
\column@=\count91
\maxfields@=\count92
\andhelp@=\toks17
\eqnshift@=\dimen121
\alignsep@=\dimen122
\tagshift@=\dimen123
\tagwidth@=\dimen124
\totwidth@=\dimen125
\lineht@=\dimen126
\@envbody=\toks18
\multlinegap=\skip42
\multlinetaggap=\skip43
\mathdisplay@stack=\toks19
LaTeX Info: Redefining \[ on input line 2735.
LaTeX Info: Redefining \] on input line 2736.
)
(c:/texlive/2015/texmf-dist/tex/latex/tools/array.sty
Package: array 2014/10/28 v2.4c Tabular extension package (FMi)
\col@sep=\dimen127
\extrarowheight=\dimen128
\NC@list=\toks20
\extratabsurround=\skip44
\backup@length=\skip45
) (z.aux)
LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for JY2/mc/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for JT2/mc/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Font shape `JT2/mc/m/n' will be
(Font)              scaled to size 9.6222pt on input line 5.
LaTeX Font Info:    Font shape `JY2/mc/m/n' will be
(Font)              scaled to size 9.6222pt on input line 5.

! Dimension too large.
\calc@shift@gather ...\wdz@ \fi \ifdim \eqnshift@ 
                                                  <\z@ \global \eqnshift@ \z...
l.8 \end{gather}

? 
! Dimension too large.
\set@gather@field ...\dp \z@ \fi \kern \eqnshift@ 
                                                  \boxz@ \hfil 
l.8 \end{gather}

? 

Overfull \hbox (190578223.56172pt too wide) in paragraph at lines 8--8
[] 
 []

Overfull \hbox (85540399.56995pt too wide) in alignment at lines 8--8
[] []
 []

[1] (z.aux) ) 

Here is how much of TeX's memory you used:
 690 strings out of 10000
 7244 string characters out of 80000
 77013 words of memory out of 262140
 4276 multiletter control sequences out of 524288
 6429 words of font info for 33 fonts, out of 45975 for 65535
 929 hyphenation exceptions out of 8191
 27i,12n,20p,211b,174s stack positions out of 100i,100n,100p,1000b,1000s
 (i = in_stack, n = nest_stack, p = param_stack, b = buf_stack, s = save_stack)
 4 inputs open max out of 15

Success at breaking 2 paragraphs:
 2 single line `paragraphs'
 2 first pass (\pretolerance = 100)
 1 second pass (\tolerance = 200)

 2 overfull \hboxes

Output written on C:/Users/Leo/Desktop/MiL4/z.pdf (1 page, 2327 bytes).
leo-liu commented 8 years ago

整理了一下,只用几个 primitive 就能重现了,看起来是 \halign 的问题。

最小工作示例:

\halign{%
  # & # \tabskip0pt \cr
  a \crcr
}%

\end

对应的 log 文件:

This is Asian pTeX, Version 3.14159265 (preloaded format=ptex-ng 2016.2.26)  25 MAR 2016 12:47
entering extended mode
**z
(z [1
! Huge page cannot be shipped out.
\plainoutput ...headline \pagebody \makefootline }
                                                  \advancepageno \ifnum \out...
<output> {\plainoutput 
                       }
<to be read again> 
                   \end 
l.6 \end

? 
The following box has been deleted:
\vbox(667.20255+0.0)x31195147.66698, yoko direction
.\vbox(0.0+0.0)x469.75499, glue set 14.0fil, yoko direction
..\glue -22.5
..\hbox(8.5+0.0)x469.75499, glue set 469.75499fil, yoko direction
...\vbox(8.5+0.0)x0.0, yoko direction
...\glue 0.0 plus 1.0fil
..\glue 0.0 plus 1.0fil minus 1.0fil
.\vbox(643.20255+0.0)x31195147.66698, glue set 633.20255fill, yoko direction
..\glue(\topskip) 5.69446
..\hbox(4.30554+0.0)x31195147.66698, yoko direction
...\glue(\tabskip) 0.0
...\hbox(4.30554+0.0)x11.66667, yoko direction []
...\glue(\tabskip) 0.0
..\hbox(0.0+0.0)x469.75499
..\glue 0.0 plus 1.0fill
.\glue(\baselineskip) 17.55556
.\hbox(6.44444+0.0)x469.75499, glue set 232.37749fil, yoko direction
..\glue 0.0 plus 1.0fil minus 1.0fil
..\tenrm 1
..\glue 0.0 plus 1.0fil minus 1.0fil

] )
No pages of output.
clerkma commented 8 years ago

应该是某个hpack出了问题,引发问题的是盒子:

.\vbox(643.20255+0.0)x31195147.66698, glue set 633.20255fill, yoko direction
..\glue(\topskip) 5.69446
..\hbox(4.30554+0.0)x31195147.66698, yoko direction
...\glue(\tabskip) 0.0
...\hbox(4.30554+0.0)x11.66667, yoko direction []
...\glue(\tabskip) 0.0
..\hbox(0.0+0.0)x469.75499
..\glue 0.0 plus 1.0fill
.\glue(\baselineskip) 17.55556

还在调试中

leo-liu commented 8 years ago

我开始也以为是 hpack,后来用 printf 加 gdb 跟了半天才发现不是的。 在处理 \halign 过程里面一个一个排查,开始怀疑是 fin_rowfin_col 之类的问题,最后才发现在 fin_align 里面。不停地用 show_node_list(preamble) 显示,开始还没事,过程结束时就错了。然后一步步找回这里。

代码不熟果然调试也没什么效率,囧。

以及 Pascal 转过来的代码真难看。

clerkma commented 8 years ago

我正在查fin_align中的hpack到底哪里出了问题,应该是有个地方算错了。

clerkma commented 8 years ago

大概查到是某个glue算错了。

leo-liu commented 8 years ago

我已经改了,是 r 抄成 c 了。