Line numbers for rtf output

Create issue
Issue #1513 new
Jonas Camillus Jeppesen created an issue

I suggest to add a crude line numbering option to the RTF formatter available in pygments/pygmentize

Basically, after the rtf output is generated numbers padded with spaces could be added to the rtf document, in front of every line of highlighted code.

{ 2 } and {10 } serves very well as line numbers if put in front of every line of highlighted code (with a monospaced font of course). A script to do this is easily crafted, but it would be nice to add it to the RTF formatter. See the attached RTF-document as an example of my suggestion.

The only downside is that the code is not copy friendly in the final document (i.e. you will copy the line numbers as well), but who copies code from RTF/Word/LibreOffice documents anyway? My use case is students who do not write reports using LaTeX. This formatting option would make it easy to generate nice looking code snippets to paste into their reports (without resorting to taking screenshots).

I might get round to looking at submitting a patch during the summer, but maybe someone else will be hooked by this. In any case, now it is here for reference.

Comments (2)

  1. Jonas Camillus Jeppesen reporter

    I’ve made a patch / changes to `pygments-main/pygments/formatters/rtf.py` which implements this.
    Do I need permission to submit a PR?

  2. Log in to comment