Many word processors support this feature and I tried to implement it in typst. It works in principle but suffers from 2 issues:
- To create a certain horizontal space a box with absolute width is created, this however only works if the box has visible content
- More than 4 tab stops in one line cause the failure of document convergence
My current implementation:
#let tab = context {
let tab_left = 2.5cm // leftmost tab stop (i.e. page margin)
let tab_width = 2.0cm // width of a single tab stop
let pos = here().position() // caller position
let column = 1 + calc.trunc( (pos.x - tab_left) / tab_width ) // column where this tab is located
let advance_to = tab_left + column * tab_width // position needed for the next tab stop
// create box with the required width
// the box requires visible content to actually occupy the correct width
// for debug purposes we choose the computed column as content
box(width: advance_to - pos.x)[#text(size: 8pt, fill: purple)[#column]]
}
I applied this code to the following 3 lines for testing purposes:
One very long text #tab which covers several tab columns #tab ?\
Hello #tab#tab World #tab#tab#tab?\
A #tab B #tab C #tab D #tab E #tab F #tab G
which yields the result
Line 1 is correct but the 2 other lines have too many tabs and show weird behavior after column 4.
It produces the warning
warning: layout did not converge within 5 attempts
= hint: check if any states or queries are updating themselves
How can I solve the issues 1. and 2. ?