Automatic line numbering


Is it possible to include text line numbering in Pressbooks, or has a theme been developed that has this feature? Think of line numbering for legal documents, which some word processors can do automatically.

We have a professor using both the online (self-hosted Pressbooks) version of a textbook and the print version of the same book in a class. The prof would like to see line numbering that he can use to guide discussion of pinpointed text for analysis, which would appear in both the online version and PDF exports.

Has this been done by anyone yet?


The use case you’re describing might not be well served by this, as line lengths can’t be assumed to be the same in webbook and PDF versions of the book. (Also, there’s no pure CSS way to add line numbers to a block element that I’m aware of… maybe others can correct me on this point.) A (certainly) easier solution would be to use a CSS counter to number paragraphs (and this could be added to any theme with some fiddling using our Custom Styles feature:

If anyone knows a method to add line numbering, I’d be interested in hearing it.


Hi Billy–I don’t think there’s a good way to do it with lines as they exist inside of fluid paragraphs, as Ned noted. It could be done with <pre> blocks, though, I believe. See for one example. You could do paragraph numbering though. See, or and for some other examples. One of my favorite online poetry magazines, Jacket, used to have numbered paragraph blocks which I loved when citing articles I read there: I think they used div’s and extra elements, though. I’m sure I’ve seen a recent project that not only created numbered paragraphs automatically, but also created anchor links for paragraphs, but it’s slipping my mind. NYT was playing around with a very cool idea called “emphasis” a few years back that I think would be very interesting for Open Textbooks:


Thanks @ned and @SteelWagstaff, that makes sense in terms of the line breaks, screen size, exports etc.

I think the paragraph numbering might be the best bet at this point, will give it a shot.



as gutenberg is the new text editor, that is an issue for the future. and I think much simple would be.


Some really interesting work ongoing here: Anyone else the community following (or getting involved) with this?


@hughmcguire and I attended the initial conference in Cambridge in January. We’re following their work with interest and contributing where we can.