Search code examples
pandocgroff

Convert simple groff coded file into tabbed and aligned .txt file


I have this text file coded with some groff style that I can convert it to .pdf, but I want to convert it to a .txt or .md file (I do not mind which one of the two, but no postscript) that keeps and preserves the groff tabbed and alienated style, as long as it is not .pdf.

.pl 11.15i
.TL
Main Title

.PP
.I
References

.in 2.6
.ti -1.1
I. MAIN outlined point including the following points A. and 1.
.ft R
.in 4.1
.ti -1.35
A. Next outlined point included in the above point I.
.in 5.2
.ti -1.1
1. Next outline point included in the above Point A.

To convert it into .pdf I used this, and it works very well if one tries it:

groff -ms myfile.txt -Tpdf > myfile.pdf

But I can not find a way to make a .txt or .md that keeps the alienated style given by groff.

I tried this: pandoc myfile.txt -o output.txt pandoc myfile.txt -o output.md

but with no success.


Solution

  • The normal way to convert it to a text-file is to use nroff.

    nroff in.roff -ms -Tutf8 filename | sed 's/\x1B\[[0-9;]*[JKmsu]//g'
    

    The sed is there to remover the control-codes that nroff puts there to underline, bold etc.