How to ensure display fractions don't cause alignment issues

The following:

+ Alignment problem $display(frac(1,2))$
+ No alignment problem $frac(1,2)$

Causes an alignment issue:

How can we resolve this so that aligns properly (as the second item does)?

Hello @pravin,

This is a known issue with enum/list and “bigger” content which can affect the child’s baseline. There are many threads detailling workarounds in this issue.

A solution that works for most cases is the following from Pacaunt.

Summary
#show list: it => context {
  for child in it.children {
  let width = measure(it.marker.at(0)).width + it.indent + it.body-indent
  let spacing = if it.tight { par.leading } else { par.spacing }
  let inset = if text.dir == rtl { (right: width) } else { (left: width) }
  set list(marker: it.marker.slice(1) + (it.marker.at(0),))
  block(inset: inset, below: spacing, above: spacing)[
    #h(-width)
    #box(it.marker.at(0), width: width)#child.body
  ]
}
  
} 

#show enum: it => context {
  let new-children = ()
  let curr = 0
  let curr-level = state("_enum",())
  let spacing = if it.tight { par.leading } else { par.spacing }

  for i in range(it.children.len()) {
    let child = it.children.at(i)
    if child.has("number") {
      new-children.push((number: curr-level.get() + (child.number,), body: child.body))
      curr = child.number
    } else {
      curr += 1
      new-children.push((number: curr-level.get() + (curr,), body: child.body))
    }
  }

  let max-width = calc.max(..new-children.map(child => measure(numbering(it.numbering, ..child.number)).width))
  let width = max-width + it.indent + it.body-indent
  let inset = if text.dir == rtl { (right: width) } else { (left: width) }
  for child in new-children {
    if it.full { curr-level.update(n => child.number) } 
    block(inset: inset, below: spacing, above: spacing)[
      #h(-width)
      #box(align(right,numbering(it.numbering, ..child.number)), width: width - it.body-indent)#h(it.body-indent)#child.body
    ]
  }
  curr-level.update(())
}

+ Alignment problem $display(frac(1,2))$
+ No alignment problem $frac(1,2)$

1 Like

Found a great solution in that thread you sent thank you! Let me know if any limitations with below come to mind:

#show list.item: it => context [
  #let marker = list.marker.at(0)
  #let height = measure[#it.body].height
  #box(height: height)[#marker #it.body] \
]

- test something very long here let’s eee
- Something in the list $display(frac(1,2))$
- test something nice and long

1 Like

Very clean solution from @nxllpointer on Discord:

#grid(columns: 2, gutter: 2em)[
  + abc $1/2$
  
  + def $display(1/2)$
  
  + ghi
][
#set enum(number-align: horizon)
  + abc $1/2$
  
  + def $display(1/2)$
  
  + ghi
]

However, this doesn’t work for lists.

1 Like

Posted an update to the issue on github:

Note that above solutions with alignment to horizon don’t work if the list is multi-line.

the above solution in github works flawlessly.