ntjess / typst-drafting

Some common drafting utilities for the `typst` document typesetter
The Unlicense
52 stars 2 forks source link

Line numbering #9

Open yochem opened 7 months ago

yochem commented 7 months ago

I'm currently working on having draft line numbers for paragraphs:

image

There are still some known bugs, but nothing that can't be fixed. Would this be something that you would like to include in this project? It seems like a great addition to this package to me.

ntjess commented 7 months ago

I'm very interested in this feature, but I would want it to work the same way as preprints (numbering is associated with absolute page positions rather than text lines). This will allow it to work with images, headings, etc.

My first attempt was to #set page(background: ...) but this had too many edge cases preventing it from working. But that was awhile ago (typst 0.7 I think?), maybe the attempt would work better now.

In any case, if you submit a PR that adds numbering to the page itself, I'd be quite happy to merge the feature!

ntjess commented 7 months ago
#let numbered = layout(size => {
  style(styles => {
    let spacing = 1.2em
    let line-height = measure(v(spacing), styles).height
    set align(left + top)
    show: pad.with(left: 1em)
    box(height: 100%)[
      #for ii in range(int(calc.ceil(size.height / line-height))) {
        place(dy: spacing * ii, str(ii + 1))
      }
    ]
  })
})

#set page(margin: 0.8in, background: numbered)

Here is a start, I will need to troubleshoot to see if there are any problems.

image

yochem commented 7 months ago

I was thinking about that too, but then it might be ambiguous which number a line would have. Communicating it like "on the line that is between 9 and 10 you missed a comma" is probably not ideal. It is much simpler to implement though.

yochem commented 7 months ago

This is how my current solutions handles e.g. headings and tables:

image

We could improve this to number every element:

image

But it currently changes the spacing, which is of course not desired. I'll fix that.

ntjess commented 7 months ago

@yochem How does it handle figures, grids, column environments, etc.? If it is robust, I like the way it looks here:

Things to check:

yochem commented 6 months ago
image

I also haven't fixed the weird spacing issue yet.