top | item 35976222

(no title)

b3lm0nt | 2 years ago

I've started using plain vanilla groff (eg., no mom or other macro packages) for formatting text files. Just run: groff -Tascii example.groff

I've found it be perfect for my purposes. LaTeX felt like too much overhead for generating a few nice-looking README files and blog posts. I also have a soft spot for older UNIX / GNU tools.

The best sources of documentation (which did take some time to track down) are:

- gtroff reference: https://www.gnu.org/software/groff/manual/groff.html#gtroff-...

- man 7 groff: https://man7.org/linux/man-pages/man7/groff.7.html

I keep a small, annotated .groff file in a gist. It serves as a reference for the formatting functions I use most frequently: https://gist.github.com/benjamindblock/0926f7346b79b93e739ab...

discuss

order

noisy_boy|2 years ago

Thanks for sharing your groff file. I'm on a Debian derivative and running the below command did produce a pdf but the line "This paragraph should be right-justified and indented by th" was chopped off on the right side:

    groff -Tpdf example.groff > example.pdf
Also, the left/right margins are partically non-existent (top/bottom margins look fine).

Did I miss any command-line option?

b3lm0nt|2 years ago

First point: the groff file in my gist is designed for plain-text files, so not all the functionality will exactly translate to PDF rendering.

Second point: to resolve the issue you're running into, remove these lines from the groff file to allow the default margins for PDF rendering to occur.

    \# Set the line lenth to \nl
    .ll \nl
There can occasionally be some strange behavior with the macros when different output devices are used (some options are ignored, some may have unexpected consequences). I took a look at the PDF output using my file directly, and it looks like the em sizing for gropdf is different from the grotty implementation, causing some overflow. (Maybe the font needs to be set explicitly before setting the line-length? Not sure).

Using a different unit of measurement (like inches or points) may be a better option for PDF files: https://www.gnu.org/software/groff/manual/html_node/Measurem...

Bonus note: you can confirm the final output device that will be used by a groff command by adding the -V option. Example:

    groff -Tpdf -V examaple.groff
Outputs:

    troff -Tpdf example.groff | gropdf
Using -Tascii instead will produce:

    troff -Tascii example.groff | grotty
Ref on output devices: https://www.gnu.org/software/groff/manual/html_node/Output-D...

* Edit: See 2b3a51's response for a better explanation.

2b3a51|2 years ago

Try

    groff -ms -Tpdf example.groff > example.pdf
The difference is the use of the ms macro package. That package generates page breaks and makes assumptions about the page size. -Tpdf will typeset your text using proportional fonts, justification and so on.

The previous poster's command generated nicely justified text in the terminal (or redirected to a file).