Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displayed maths in +proof collapse in some cases #326

Open
gfngfn opened this issue May 5, 2022 · 3 comments
Open

Displayed maths in +proof collapse in some cases #326

gfngfn opened this issue May 5, 2022 · 3 comments

Comments

@gfngfn
Copy link
Owner

gfngfn commented May 5, 2022

Reported here: https://twitter.com/mr_konn/status/1522197421312593921?s=20&t=zNgPdOp1zqE9rwpBUGIDQw

@konn
Copy link
Contributor

konn commented May 5, 2022

A bit context: I typeset the code below:

@require: stdjareport
@require: math
document (|
  title = {あああああ};
  author = {mr_konn};
  date = {2022/04/23};
|) '<
+chapter{あああああ}<
  +proof{
    ううううううう

    \eqn(${x \in \bigcup_n A_n \Longleftrightarrow \bigcup_n A_n \in \mathcal{U}});
  }
  >
>

which resulted in:

スクリーンショット 2022-05-05 21 51 47

On the other hand, if we add extra paragraph after eqn, the math gets done right, like this:

@require: stdjareport
@require: math
document (|
  title = {あああああ};
  author = {mr_konn};
  date = {2022/04/23};
|) '<
+chapter{あああああ}<
  +proof{
    ううううううう

    \eqn(${x \in \bigcup_n A_n \Longleftrightarrow \bigcup_n A_n \in \mathcal{U}});

    ええええ
  }
  >
>

スクリーンショット 2022-05-05 22 06 45

@sankantsu
Copy link
Contributor

sankantsu commented Aug 9, 2022

I did some experiment and noticed some points.

  • \eqn uses embed-block-breakable, followed by omit-skip-after.
  • +proof put inline-fil and some endmark character at the end of commend.

In the case where the \eqn is the last content of +proof command, it seems that the omit-skip-after at the end of \eqn command absorbs the inline-fil before the endmark character and it causes line breaking problem.

Here is a simplified reproduction of the original problem and some workarounds.

@require: stdjareport

let-block ctx +add-endmark it =
    let ib-box = read-inline ctx {▪} in
    line-break true true ctx
        (read-inline ctx it ++ inline-fil ++ ib-box)

% guard (null inline-frame)
let guard = 
    let pads = (0pt,0pt,0pt,0pt) in
    let dc _ _ _ _ = [] in
    inline-frame-inner pads dc inline-nil

let-inline ctx \guard = guard

let-block ctx +add-endmark-with-guard it =
    let ib-box = read-inline ctx {▪} in
    line-break true true ctx
        (read-inline ctx it ++ guard ++ inline-fil ++ ib-box) % put guard before inline-fil

let-inline ctx \embed-block it =
    let ib = read-inline ctx it in
    let bb = line-break true true ctx (inline-fil ++ ib ++ inline-fil) in
    inline-fil ++ embed-block-breakable ctx bb ++ omit-skip-after

let-inline ctx \embed-block-with-no-omit-skip it =
    let ib = read-inline ctx it in
    let bb = line-break true true ctx (inline-fil ++ ib ++ inline-fil) in
    inline-fil ++ embed-block-breakable ctx bb

in

document (|
  title = {\#326: Displayed math in \+proof collapse};
  author = {mr_konn};
|) '<
    +chapter {Simplified reproduction} <
        +section {Case 1 (no sentence after embed-block)} <
            +add-endmark {
                First sentence.
                \embed-block {collapsed}
            }
        >
        +section {Case 2 (extra sentence after embed-block)} <
            +add-endmark {
                First sentence.
                \embed-block {not collapsed}
                Second sentence.
            }
        >
        +section {Case 3 (remove omit-skip)} <
            +add-endmark {
                First sentence.
                \embed-block-with-no-omit-skip {manual guard after block}
            }
        >
        +section {Case 4 (manual guard)} <
            +add-endmark {
                First sentence.
                \embed-block {manual guard after block}
                \guard;
            }
        >
        +section {Case 5 (modify \+proof command)} <
            +add-endmark-with-guard {
                First sentence.
                \embed-block {guarded command}
            }
        >
    >
>

326-reproduction

The first workaround (Case 3) is to remove omit-skip-after.

Another workaround (Case 4,5) is to add some guard before inline-fil and the endmark.
It seems that the inline-frame-inner with no content effectively works as guard for preventing omit-skip-after to absorb inline-fil.

I don't know the details about line-breaking implentation and do not know best solution for this problem, but I hope this workaround give some insight.

@gfngfn
Copy link
Owner Author

gfngfn commented Aug 12, 2022

Good catch! And thank you for making a detailed comparison.

The second workaround looks better in my opinion; the following exemplifies why omit-skip-after is needed:

@require: stdjareport

let-inline ctx \display-with-skip-omission it =
  let ib = read-inline ctx it in
  let bb = line-break true true ctx (inline-fil ++ ib ++ inline-fil) in
  inline-fil ++ embed-block-breakable ctx bb ++ omit-skip-after

let-inline ctx \display-without-skip-omission it =
  let ib = read-inline ctx it in
  let bb = line-break true true ctx (inline-fil ++ ib ++ inline-fil) in
  inline-fil ++ embed-block-breakable ctx bb

let text =
  {
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.
  }

in
document (|
  title = {Need for `omit-skip-after`};
  author = {`@gfngfn`};
|) '<
  +p{
    #text;

    \display-with-skip-omission{
      Texts in the embedded block
    }

    #text;
  }
  +p{
    #text;

    \display-without-skip-omission{
      Texts in the embedded block
    }

    #text;
  }
  +p{
    Take a careful look at the indentations after the embedded blocks above!
    You can nonetheless prevent indentations from being inserted simply by adding `%`:
  }
  +p{
    #text;

    \display-without-skip-omission{
      Texts in the embedded block
    }%

    #text;
  }
>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants