Skip to content

Line Numbers #352

Closed
Closed

Description

@mcexit

Typst seems like a good potential choice for people in the legal community to be able to write court filings. However, some courts require that legal documents include line numbers in the left-hand column. LaTeX has lineno for this, but I don't see the ability to do it with Typst. If a developer needs some examples of courts' local rules that shows the format I'd be happy to post them.

Activity

  1. added
    feature request
    layout
    on Apr 1, 2023
  2. gabrfarina commented on Apr 7, 2023

    @gabrfarina
    Sponsor

    +1. Also certain conferences in computer science require line numbers in submissions, including NeurIPS (https://neurips.cc/), one of the top conferences in machine learning. NeurIPS's template can be seen here.

  3. Andrew15-5 commented on Jul 26, 2023

    @Andrew15-5
    Contributor

    Are line numbers in these type of documents only needed to review and easily refer to a specific line?

    - I don't like *this* on the line 24.
    - Change *this* on the line 451 to *this*.
    - I like what you did on the line 69.
    

    Or line numbers have more use cases than this?

  4. Andrew15-5 commented on Jul 26, 2023

    @Andrew15-5
    Contributor

    Line numbers are probably going to pass the set margins, right? If you set left margin to 3cm then the line number would appear somewhere in the first 3 cm from the left.

    If so, then there is probably going to be the next options:

    font: string | array
    size: relative length
    offset: rect
    

    font is either a string or an array of fallback fonts. size is the size of the font. offset, I can't find a good example in the doc., but it can take something like:

    offset: (
      left: relative length,
      right: relative length,
      top: relative length,
      bottom: relative length,
      x: relative length,
      y: relative length,
      rest: relative length,
    )
    

    If offset is auto (default), then it, for example, has right: 0.5cm, so that it would be usable by default.

    One problem is that you have to somehow include an "on/off" switch somewhere in the Typst settings.

    P.S. This is just an example/markup, and I'm also still new to the Typst.

  5. changed the title [-]Feature Request: Line Numbers (Legal Documents)[/-] [+]Line Numbers[/+] on Sep 18, 2023
  6. jamesrswift commented on Oct 16, 2023

    @jamesrswift
    Sponsor

    A primitive such as line (similar to par) would be a great addition for per-line styling, which would also enable a modification of adding a number offset into the margin for each line.

  7. CGMossa commented on Oct 16, 2023

    @CGMossa
    Contributor

    Alright, well recently we got #2341, which greatly resembles what would be needed to accomplish this.

    Otherwise, yes, line-numbering everything would be helpful with paper reviews, etc.

  8. jamesrswift commented on Oct 16, 2023

    @jamesrswift
    Sponsor

    Indeed, good catch! Something like that but not just for raw

  9. Atreyu-94 commented on Oct 18, 2023

    @Atreyu-94

    I was just coming to leave an issue about this. This is very important in academic journals or even in draftsmen in the hands of reviewers.

  10. g-simmons commented on Oct 19, 2023

    @g-simmons

    FWIW I am using this for now.
    Main idea:

    • split up the input by parbreaks (numbering should skip these)
    • for each chunk between parbreaks, layout the content and calculate its height
    • divide the height of the chunk by the line height to get the number of lines (should be parameterized 🙃 )
    • make a grid, put the original content in the right half, put the line numbers in the left half, offset everything to the left to maintain placement of the original content

    (Messy) Code below

    • number_content works with multiple paragraphs, inline equations, figures. I haven't tested with other types of content yet. Haven't tested multiple columns, probably will not work without modification. Haven't tested headers.

    Credit:

    Improvements:

    • You could probably avoid numbering the figures (and whatever other content you want to avoid skipping numbering for) by splitting on these in addition to parbreaks.
    // #let l = state("lineno", 10)
    #let l = counter("mycounter")
    // #set page()
    #set text(size: 10pt)
    
    #let pad_int(i, N: 3) = {
      // pad an integer with leading zeros
      let s = str(i)
      let n_pads = N - s.len()
      for _ in range(n_pads) {
        s = "0" + s
      }
      [#s]
    }
    
    #let number_content(text_input) = {
      layout(
        size => style(
          styles => [
          #let (height) = measure(block(width: size.width, text_input), styles)
          #let numlines = int(calc.floor(height.height / 10pt))
          #let RULERWIDTH = 0.6in
    
          #move(
            grid(
              columns: (RULERWIDTH, 100%),
              gutter: 0pt,
              [
              #set text(
                rgb(50%, 50%, 100%),
                weight: "bold",
                font: "Times",
                size: 10pt,
                spacing: 65%,
              )
              // #set par(leading: 0.45em)
              #set align(left)
              #let start = locate(loc => [#l.at(loc)])
    
              #if numlines == 0 {
                numlines = 1
              }
    
              #for i in range(0, numlines) {
                l.step()
                [#l.display(pad_int) #linebreak()]
              }
              ],
              [
              #text_input
              ],
            ),
            dx: -RULERWIDTH,
            dy: 0pt,
          )
          ],
        ),
      )
    }
  11. maradotwebp commented on Oct 28, 2023

    @maradotwebp

    Recently had the same requirement of numbering paragraphs, not lines, for a legal document. I settled on this solution using numbered lists for now. Maybe it can be of help to some of you?

  12. AlexShyXie commented on Dec 24, 2023

    @AlexShyXie

    This is the line number that I need.
    Because during the review process, the editor requested the addition of line numbers, which allows reviewers to locate and ask questions using line numbers.

    image

  13. RafailFridman commented on Apr 3, 2024

    @RafailFridman

    Are there any new solutions that will allow us to get nice line numbers?

  14. jguhlin commented on Apr 5, 2024

    @jguhlin

    Another vote for line numbers for scientific papers. Current solution is pandoc to latex, and going from there.

    If someone could give me pointers I could take a look myself too.

  15. CGMossa commented on Apr 5, 2024

    @CGMossa
    Contributor

    Consideration: pages with table only should also have their content provoke a line numbering.

  16. laurmaedje commented on Apr 6, 2024

    @laurmaedje
    Member

    @RafailFridman No current news, but I wanted to take a look at this before 0.12.

  17. daskol commented on Apr 22, 2024

    @daskol

    In case of CVPR/ICML-like templates, I have managed to render lines (see 998f02ac/cvpr). I define a ruler as a couter and locatable content and put it in background kwarg of page. Counter allows to enumerate lines on a specific page in locate(loc => ...) context.

    In case of NeurIPS/ACL-like templates, it seems that there is no way to render line numbers in pure Typst without going deeper and modifying document model. I tried to override paragraph rule in order to attach on the left or on the right line number as follows.

    #show par: it => {
      place(left + top, float: true, dx: -100pt, { /* generate line numbers here */ })
      it
    }

    Unfortunately, it does not work since it recursively invokes par rendering routine infinitely.

  18. maxall41 commented on Jul 3, 2024

    @maxall41

    Any updates on this?

  19. jamesrswift commented on Jul 3, 2024

    @jamesrswift
    Sponsor

    There has been a good deal of discussion on the topic in the academia forge on discord these past few days

  20. daskol commented on Aug 29, 2024

    @daskol

    Hurray! 🎉

  21. rrrodzilla commented on Aug 29, 2024

    @rrrodzilla

    Fantastic. Thank you for the hard work on this!

  22. jreniel commented on Sep 11, 2024

    @jreniel

    Kudos!

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

    feature requestlayout

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions