gfngfn / SATySFi

A statically-typed, functional typesetting system
GNU Lesser General Public License v3.0
1.18k stars 84 forks source link

When there is no text or no command after \enumerate, pagebreak error occur. #323

Open Reyon62 opened 2 years ago

Reyon62 commented 2 years ago

Example

Input

@require: stdjareport
@require: itemize

document (|
  title = {bug report};
  author = {syaoshao};
  show-title = true;
  show-toc = true;
|) '<
    +p{
        \enumerate{
            *${aaa}
            *${bbb}
            *${ccc}
        }
    }
>

Output

 ---- ---- ---- ----
  target file: 'bug.pdf'
  dump file: 'bug.satysfi-aux' (already exists)
  parsing 'bug.saty' ...
  parsing 'stdjareport.satyh' ...
  parsing 'pervasives.satyh' ...
  parsing 'gr.satyh' ...
  parsing 'geom.satyh' ...
  parsing 'list.satyg' ...
  parsing 'option.satyg' ...
  parsing 'math.satyh' ...
  parsing 'code.satyh' ...
  parsing 'color.satyh' ...
  parsing 'vdecoset.satyh' ...
  parsing 'annot.satyh' ...
  parsing 'footnote-scheme.satyh' ...
  parsing 'itemize.satyh' ...
 ---- ---- ---- ----
  type checking 'color.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'pervasives.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'option.satyg' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'geom.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'list.satyg' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'gr.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'annot.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'footnote-scheme.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'itemize.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'math.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'vdecoset.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'code.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'stdjareport.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'bug.saty' ...
  type check passed. (document)
  preprocessing 'color.satyh' ...
  preprocessing 'pervasives.satyh' ...
  evaluating 'option.satyg' ...
  preprocessing 'geom.satyh' ...
  evaluating 'list.satyg' ...
  preprocessing 'gr.satyh' ...
  preprocessing 'annot.satyh' ...
  preprocessing 'footnote-scheme.satyh' ...
  preprocessing 'itemize.satyh' ...
  preprocessing 'math.satyh' ...
  preprocessing 'vdecoset.satyh' ...
  preprocessing 'code.satyh' ...
  preprocessing 'stdjareport.satyh' ...
  preprocessing 'bug.saty' ...
  evaluating 'color.satyh' ...
  evaluating 'pervasives.satyh' ...
  evaluating 'geom.satyh' ...
  evaluating 'gr.satyh' ...
  evaluating 'annot.satyh' ...
  evaluating 'footnote-scheme.satyh' ...
  evaluating 'itemize.satyh' ...
  evaluating 'math.satyh' ...
  evaluating 'vdecoset.satyh' ...
  evaluating 'code.satyh' ...
  evaluating 'stdjareport.satyh' ...
 ---- ---- ---- ----
  evaluating texts ...
modified version of stdjareport.
  evaluation done.
 ---- ---- ---- ----
  breaking contents into pages ...
page content 1
column start.
Uncaught exception:

  "Assert_failure src/backend/pageBreak.ml:108:42"

Raised at Main__PageBreak.chop_single_column.normalize_after_break.omit_redundant_clear in file "src/backend/pageBreak.ml", line 108, characters 42-54
Called from Main__PageBreak.chop_single_column.normalize_after_break in file "src/backend/pageBreak.ml", line 112, characters 12-40
Called from Main__PageBreak.chop_single_column.aux in file "src/backend/pageBreak.ml", line 229, characters 33-62
Called from Main__PageBreak.chop_single_column.aux.(fun) in file "src/backend/pageBreak.ml", line 191, characters 22-422
Called from Main__PageBreak.chop_single_column.aux in file "src/backend/pageBreak.ml", line 146, characters 10-1023
Called from Main__PageBreak.chop_single_column.aux.(fun) in file "src/backend/pageBreak.ml", line 263, characters 20-413
Called from Main__PageBreak.chop_single_column.aux in file "src/backend/pageBreak.ml", line 220, characters 10-1023
Called from Main__PageBreak.chop_single_column.aux.(fun) in file "src/backend/pageBreak.ml", line 191, characters 22-422
Called from Main__PageBreak.chop_single_column.aux in file "src/backend/pageBreak.ml", line 146, characters 10-1023
Called from Main__PageBreak.chop_single_column.aux.(fun) in file "src/backend/pageBreak.ml", line 263, characters 20-413
Called from Main__PageBreak.chop_single_column.aux in file "src/backend/pageBreak.ml", line 220, characters 10-1023
Called from Main__PageBreak.chop_single_column.aux.(fun) in file "src/backend/pageBreak.ml", line 191, characters 22-422
Called from Main__PageBreak.chop_single_column.aux in file "src/backend/pageBreak.ml", line 146, characters 10-1023
Called from Main__PageBreak.chop_single_column.aux.(fun) in file "src/backend/pageBreak.ml", line 263, characters 20-413
Called from Main__PageBreak.chop_single_column.aux in file "src/backend/pageBreak.ml", line 220, characters 10-1023
Called from Main__PageBreak.chop_single_column.aux.(fun) in file "src/backend/pageBreak.ml", line 263, characters 20-413
Called from Main__PageBreak.chop_single_column.aux in file "src/backend/pageBreak.ml", line 220, characters 10-1023
Called from Main__PageBreak.chop_single_column.aux.(fun) in file "src/backend/pageBreak.ml", line 191, characters 22-422
Called from Main__PageBreak.chop_single_column.aux in file "src/backend/pageBreak.ml", line 146, characters 10-1023
Called from Main__PageBreak.chop_single_column.aux.(fun) in file "src/backend/pageBreak.ml", line 263, characters 20-413
Called from Main__PageBreak.chop_single_column.aux in file "src/backend/pageBreak.ml", line 220, characters 10-1023
Called from Main__PageBreak.chop_single_column.aux.(fun) in file "src/backend/pageBreak.ml", line 191, characters 22-422
Called from Main__PageBreak.chop_single_column.aux in file "src/backend/pageBreak.ml", line 146, characters 10-1023
Called from Main__PageBreak.chop_single_column.aux.(fun) in file "src/backend/pageBreak.ml", line 263, characters 20-413
Called from Main__PageBreak.chop_single_column.aux in file "src/backend/pageBreak.ml", line 220, characters 10-1023
Called from Main__PageBreak.chop_single_column.aux.(fun) in file "src/backend/pageBreak.ml", line 191, characters 22-422
Called from Main__PageBreak.chop_single_column.aux in file "src/backend/pageBreak.ml", line 146, characters 10-1023
Called from Main__PageBreak.chop_single_column in file "src/backend/pageBreak.ml", line 538, characters 4-454
Called from Main__PageBreak.main_multicolumn.iter_on_column in file "src/backend/pageBreak.ml", line 744, characters 10-83
Called from Main__PageBreak.main_multicolumn.iter_on_page in file "src/backend/pageBreak.ml", line 774, characters 25-86
Called from Main.eval_document_file.aux in file "src/frontend/main.ml", line 392, characters 16-151
Called from Main.error_log_environment in file "src/frontend/main.ml", line 464, characters 4-16
Called from Satysfi in file "bin/satysfi.ml", line 1, characters 9-21

@ R_O_R_I_J_O also found this error: https://twitter.com/R_O_R_I_J_O/status/1505121840565735424?s=20&t=gukKQDDsyNMagWU_WiHiWQ

I could avoid this error by following ways:

  1. use \listing instead of \enumerate
  2. write some texts or place some commands after \enumerate{}

@ R_O_R_I_J_O checked no error using \listing in place of \enumerate: https://twitter.com/R_O_R_I_J_O/status/1505039343991533571?s=20&t=gukKQDDsyNMagWU_WiHiWQ.

This error occured when \enumerate is placed in +p, +definition, +lemma, +theorem, +corollary commands. However, such document can be compiled in +proof command. For example,

@require: stdjareport
@require: itemize

document (|
  title = {bug report};
  author = {syaoshao};
  show-title = true;
  show-toc = true;
|) '<
    +proof{
        \enumerate{
            *${aaa}
            *${bbb}
            *${ccc}
        }
    }
>

Output

---- ---- ---- ----
  target file: 'bug.pdf'
  dump file: 'bug.satysfi-aux' (already exists)
  parsing 'bug.saty' ...
  parsing 'stdjareport.satyh' ...
  parsing 'pervasives.satyh' ...
  parsing 'gr.satyh' ...
  parsing 'geom.satyh' ...
  parsing 'list.satyg' ...
  parsing 'option.satyg' ...
  parsing 'math.satyh' ...
  parsing 'code.satyh' ...
  parsing 'color.satyh' ...
  parsing 'vdecoset.satyh' ...
  parsing 'annot.satyh' ...
  parsing 'footnote-scheme.satyh' ...
  parsing 'itemize.satyh' ...
 ---- ---- ---- ----
  type checking 'color.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'pervasives.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'option.satyg' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'geom.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'list.satyg' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'gr.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'annot.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'footnote-scheme.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'itemize.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'math.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'vdecoset.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'code.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'stdjareport.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'bug.saty' ...
  type check passed. (document)
  preprocessing 'color.satyh' ...
  preprocessing 'pervasives.satyh' ...
  evaluating 'option.satyg' ...
  preprocessing 'geom.satyh' ...
  evaluating 'list.satyg' ...
  preprocessing 'gr.satyh' ...
  preprocessing 'annot.satyh' ...
  preprocessing 'footnote-scheme.satyh' ...
  preprocessing 'itemize.satyh' ...
  preprocessing 'math.satyh' ...
  preprocessing 'vdecoset.satyh' ...
  preprocessing 'code.satyh' ...
  preprocessing 'stdjareport.satyh' ...
  preprocessing 'bug.saty' ...
  evaluating 'color.satyh' ...
  evaluating 'pervasives.satyh' ...
  evaluating 'geom.satyh' ...
  evaluating 'gr.satyh' ...
  evaluating 'annot.satyh' ...
  evaluating 'footnote-scheme.satyh' ...
  evaluating 'itemize.satyh' ...
  evaluating 'math.satyh' ...
  evaluating 'vdecoset.satyh' ...
  evaluating 'code.satyh' ...
  evaluating 'stdjareport.satyh' ...
 ---- ---- ---- ----
  evaluating texts ...
modified version of stdjareport.
  evaluation done.
 ---- ---- ---- ----
  breaking contents into pages ...
page content 1
column start.
LineBreak> UNREACHABLE
  [Warning] a line unable to be broken into a paragraph occurs on page 1
reach last.
column end 1 (last: T, remains: F)
page parts 1
  all cross references were solved.
 ---- ---- ---- ----
  embedding fonts ...
 ---- ---- ---- ----
  writing pages ...
 ---- ---- ---- ----
  output written on 'bug.pdf'.
Reyon62 commented 2 years ago

my SATySFi's version:

$ satysfi -v
  SATySFi version 0.0.6
leque commented 2 years ago

The assertion causing this error was introduced at the same time as PBHookPageBreak was introduced (https://github.com/gfngfn/SATySFi/commit/c6699b3a7369cf9b862d7f1b3cbe566d09292565). It might suffice to fix the problem to handle PBHookPageBreak properly in Main__PageBreak.chop_single_column.normalize_after_break.omit_redundant_clear

sankantsu commented 2 years ago

As @leque pointed out, Main__PageBreak.chop_single_column.normalize_after_break.omit_redundant_clear is the line where assertion fails.

--- a/src/backend/pageBreak.ml
+++ b/src/backend/pageBreak.ml
@@ -105,7 +105,8 @@ let chop_single_column (pbinfo : page_break_info) (area_height : length) (pbvbls
       | (PBVertSkip(_), _) :: pbvbtail -> omit_redundant_clear pbvbtail
       | (PBVertLine(_), _) :: _
       | (PBVertFrame(_), _) :: _       -> None
-      | (PBHookPageBreak(_), _) :: _   -> assert false
+      | (PBHookPageBreak(_), _) :: _   -> None
       | []                             -> Some([])  (* -- the original `pbvblst` consists only of spaces -- *)
     in

Change like above eliminates the error message and it looks there is no problem in output pdf.

But, I'm not confident that this is the right way to solve this issue.

Also, I did somewhat simplified reproduction of this problem. I hope it would be helpful.

let text-width = 440pt
let text-height = 630pt
let-inline ctx \math m = embed-math ctx m
let ctx = get-initial-context text-width (command \math)

let bb-main =
    let ib =
        inline-fil
        ++ (embed-block-breakable ctx (block-skip 1pt))
    in
    line-break true true ctx ib

let vhook = hook-page-break-block (fun _ _ -> ())

let bb = bb-main +++ vhook

in

page-break A4Paper
    (fun _ -> (| text-height = text-height; text-origin = (0pt,0pt); |))
    (fun _ -> (| header-content = block-nil; header-origin = (0pt,0pt);
                 footer-content = block-nil; footer-origin = (0pt,0pt); |))
    bb

The assertion was about PBHookPageBreak (which corresponds to hook-page-break-block) but, preceding block-box also matters. When I change block-skip in the embed-block-breakable to something like block-nil or some paragraph didn't reproduce the problem.

In the original situation, \enumerate have a embed-block-breakable, which contains block-skip as the last element, and it is followed by hook-page-break-block which is introduced in stdjareport class document function.

(edit)

Code like below also reproduces the problem. embed-block-breakable is not important, but the combination of

is sufficient.

let text-width = 440pt
let text-height = 630pt
let-inline ctx \math m = embed-math ctx m
let ctx = get-initial-context text-width (command \math)

let bb-main =
    let it = {some text} in
    let ib = read-inline ctx it in
    line-break true true ctx ib

let vhook = hook-page-break-block (fun _ _ -> ())

let bb = bb-main +++ (block-skip 1pt) +++ vhook

in

page-break A4Paper
    (fun _ -> (| text-height = text-height; text-origin = (0pt,0pt); |))
    (fun _ -> (| header-content = block-nil; header-origin = (0pt,0pt);
                 footer-content = block-nil; footer-origin = (0pt,0pt); |))
    bb