How to add line numbering?

I’m interested in adding line numbering to my document, or sections of my document similar to what I can do with lineno in LaTeX. Any pointers on how to do this?

See: https://texblog.org/2012/02/08/adding-line-numbers-to-documents/

1 Like

I do not think that it is currently possible, this would require to intercept the lines after the typesetter determined them and add some more boxes before the rendering. It should need some low level hacking in C++…

But is nice feature and its design is already relatively fixed by the TeX implementation. I will add to the wishlist.

Actually it could be implemented using \datoms (see the manual). I’ve gave a try but is not perfect, I think is a bit fragile, anyway… it is a 10 min attempt. There are some problems with section numbers.

<TeXmacs|1.99.15>

<style|generic>

<\body>
  <\hide-preamble>
    <new-counter|line-nr>
    <assign|line-nr-shift|-1em>
    <assign|number-line|<macro|<inc-line-nr><the-line-nr>>>
    <assign|decorate-line|<macro|body|<resize|<shift|<tiny|<number-line>>|<line-nr-shift>|>|0em||0em|><arg|body>>>
  </hide-preamble>

  <\datoms|<macro|x|<decorate-line|<arg|x>>>>
    Here is a sufficiently long paragraph. Here is a sufficiently long
    paragraph. Here is a sufficiently long paragraph. Here is a sufficiently
    long paragraph. Here is a sufficiently long paragraph. Here is a
    sufficiently long paragraph.

    <section|fkdjfksjdfksdjkfjksdjkfjsdk>

    dflfksldkfds

    <\equation*>
      x<rsup|2>+y<rsup|2>\<leqslant\>3
    </equation*>

    dsdklsakdlaskdlas

    slkdlkasldkaslkdas

    dsamd,aslkdlakla

    <section|fkdjfksjdfksdjkfjksdjkfjsdk>

    ss

    sss

    <section|fkdjfksjdfksdjkfjksdjkfjsdk>

    \;
  </datoms>
</body>

<\initial>
  <\collection>
    <associate|page-medium|paper>
  </collection>
</initial>
1 Like

Thanks for the response mgubi. I think native support for this would be useful.

https://savannah.nongnu.org/projects/fangle

I tried this before. It provides lineno in code blocks.

In limited context, the technique I used above works. But for whole documents not.