gfngfn / SATySFi

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

SATySFi says that all cross references were solved while they aren't #68

Closed yudai-nkt closed 6 years ago

yudai-nkt commented 6 years ago

Consider the following mwe.saty. Note that \ref(`sec:fooo`); is a typo on purpose.

@require: stdja

StdJa.document (|
  title = {};
  author = {};
  show-title = false;
  show-toc = false
|) '<
  +section ?:(`sec:foo`) {Foo} <
    +p {
      This is Section \ref(`sec:fooo`);.
    }
  >
>

If we typeset this document, we obtain the log shown below and it claims all cross references were solved. after the 2nd trial.

$ satysfi mwe.saty -o mwe.pdf
 ---- ---- ---- ----
  target file: 'mwe.pdf'
  dump file: 'mwe.satysfi-aux' (will be created)
  parsing 'mwe.saty' ...
  parsing 'stdja.satyh' ...
  parsing 'pervasives.satyh' ...
  parsing 'gr.satyh' ...
  parsing 'list.satyh' ...
  parsing 'math.satyh' ...
  parsing 'color.satyh' ...
 ---- ---- ---- ----
  reading 'pervasives.satyh' ...
  type check passed.
 ---- ---- ---- ----
  reading 'list.satyh' ...
  type check passed.
 ---- ---- ---- ----
  reading 'color.satyh' ...
  type check passed.
 ---- ---- ---- ----
  reading 'math.satyh' ...
  type check passed.
 ---- ---- ---- ----
  reading 'gr.satyh' ...
  type check passed.
 ---- ---- ---- ----
  reading 'stdja.satyh' ...
  type check passed.
 ---- ---- ---- ----
  reading 'mwe.saty' ...
  type check: document
 ---- ---- ---- ----
  evaluating texts ...
  evaluation done.
 ---- ---- ---- ----
  breaking contents into pages ...
  needs another trial for solving cross references...
 ---- ---- ---- ----
  evaluating texts (2nd trial) ...
  evaluation done.
 ---- ---- ---- ----
  breaking contents into pages ...
  all cross references were solved.
 ---- ---- ---- ----
  embedding fonts ...
 ---- ---- ---- ----
  writing pages ...
 ---- ---- ---- ----
  output written on 'mwe.pdf'.

However, SATySFi obviously cannot find a label entry for sec:fooo and a question mark is printed on the output PDF. This situation wouldn't be considered as "solved" IMHO.

qnighy commented 6 years ago

Yes, currently the message indicates that the resolution reached a fixpoint. Here is an artificial example where the resolution cannot reach a fixpoint:

@require: stdja

let-inline \foo =
  let bar =
    match get-cross-reference `bar` with
    | Some(`foo`) -> `bar`
    | _ -> `foo`
  in
  let () = register-cross-reference `bar` bar in
  {}
in

StdJa.document (|
  title = {};
  author = {};
  show-title = false;
  show-toc = false
|) '<
  +section ?:(`sec:foo`) {Foo} <
    +p {
      This is Section \ref(`sec:fooo`);.
      \foo;
    }
  >
>

So, in addition to the CrossRef.changed flag, we may want to watch whether get-cross-reference ever returned None, and change the message accordingly.

yudai-nkt commented 6 years ago

Thanks for the explanation and the PR. I now understand how cross reference resolution works to some degree.

in addition to the CrossRef.changed flag, we may want to watch whether get-cross-reference ever returned None

Second it, that's the exact behavior I expected.