Skip to content

Non convergence: place() seems to change here() #3614

Closed

Description

@memeplex

Description

This doesn't converge, it keeps pushing the box downwards and abort after 5 iterations. Should the absolute positioned box change the result of here()?

0.11.0:

#let f() = context {
  place(
    top + right,
    dy: here().position().y,  
    square(width: 10pt),
  )
}

#lorem(50)#f()

0.10.0:

#let f() = locate(loc => {
  place(
    top + right,
    dy: loc.position().y,  
    square(width: 10pt),
  )
})

#lorem(50)#f()

Reproduction URL

No response

Operating system

Web app

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on Mar 10, 2024
  2. AxiomOfChoices commented on Mar 10, 2024

    @AxiomOfChoices

    I could be wrong but I think this is working as intended, the here function grabs the location of the current scope, which in this case surrounds the square. Thus the here function will grab the location of the square itself and cause the box to be pushed downwards.

    To circumvent this you need to give the here function an anchor to grab onto, so in 0.11 placing an invisible box will do the trick:

    #let f() = context {
      place(top+left,box())
      let cur_y = here().position().y;
      place(
        top + right,
        dy: cur_y,  
        square(width: 10pt),
      )
    }
    
    #lorem(50)#f()
    

    image

    All that being said I feel like this is not ideal behavior, assuming my understanding of the situation is correct, the location of the scope of a context should probably be fixed to the location where it is called.

  3. memeplex commented on Mar 11, 2024

    @memeplex
    Author

    the here function grabs the location of the current scope, which in this case surrounds the square. Thus the here function will grab the location of the square itself and cause the box to be pushed downwards. To circumvent this you need to give the here function an anchor to grab onto,

    I'm trying to wrap my mind around this. I'm very new to Typst.

    The original scenario was something like this:

    text here square --> text _ here square --> text __ here square --> ...

    The new scenario, with an invisible box:

    text ibox here square --> text ibox here square

    In what sense the invisible box is more of an anchor than the content that previously preceded here() (which wasn't moving either)?

    And in what sense the new "surrounding scope" is different to the previous one?

  4. AxiomOfChoices commented on Mar 11, 2024

    @AxiomOfChoices

    I'd have to wait till I have more free time to play with the source code and see how exactly this works, or see what @laurmaedje has to say, but my understanding is this:
    The scope of the context is everything placed inside of the context, so in the original case this is just the square, so the abstract syntax tree looks something like this.
    image
    The here function grabs the location of closest node of the tree to its left and then above it, so in the original case it grabs the location of the context scope itself. Now the context scope only contains the square so its location after the square is placed is the same as that of the square, it wraps itself around the square. So the here ends up getting the location of the square.

    On the other hand in the situation with the invisible box the syntax tree looks like this.
    image
    Now when the here function runs it finds the box first and so it grabs its location instead of that of the context, and that location is fixed so it is independent of the number of iterations.

  5. laurmaedje commented on Mar 11, 2024

    @laurmaedje
    Member

    I would classify the current behaviour as wrong. If you use here inside of a show rule for an element, it should grab that element's proper location. However, with an explicit context block, it attaching itself to the first contained element rather than being free-standing is more a result of the current implementation than intended behaviour.

  6. added
    introspection
    on Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugintrospection

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions