25

I am a physics undergraduate and I often have to write Latex documents. However, I recently heard of Groff which, from what I have gathered, is much lighter and more minimal than Latex. Is it any good for writing maths? Or is it limited like Markdown?

3

3 Answers 3

43

Equations in roff

roff (or groff or any other implementation) doesn't actually support mathematics typesetting. To this end you have to use a preprocessor which transforms equations in your document into something that groff can read. I'm only aware of the eqn preprocessor for equations but there might be others.

One obvious downside of eqn (or groff in general) is that most commands have to appear on a line by themselves, which is very disruptive when writing. That's not really a problem for displayed equations but becomes very annoying for inline math.

LaTeX vs groff

Also the output quality of groff with eqn is not on par with LaTeX (neither is anything else in my opinion).

On top of that LaTeX comes with a lot more features than groff, such as automatic cross-referencing, bibliography management, and multilingual support out-of-the-box. On top of that it is extended by great macro packages, such as amsmath for maths, siunitx for units, beamer for presentation slides, tikz for inline vector graphics, microtype for microtypographical features, and many more.

Other “features” of LaTeX are that scientific journals usually accept submissions in LaTeX and your supervisor might know LaTeX, so you can write your manuscript together. A lot of software can import and export formulas in LaTeX syntax, including Mathematica and even MS Word!

Furthermore, the LaTeX community is much larger than for groff (does it even exist?) and you can enjoy corporate support in the form of online editors such as Overleaf.

I could probably keep going as to why LaTeX is superior to any other non-commercial typesetting system (to any commercial one as well probably). Before going on to comparing output quality, let me answer your two specific questions.

Specific questions

Is it any good for writing maths?

No, the output quality is not on par with LaTeX and the equation syntax (in my opinion) is unintuitive and convoluted. For example spaces matter in some situations, but not in other, sometimes you need to wrap things in {} or "".

Or is it limited like Markdown?

Not really. While Markdown is really a flat static text format, groff at least supports macros but they don't seem to be as powerful as TeX macros (which are famously Turing-complete).

Output quality

LaTeX

\[ s = \sqrt{\frac{\sum_{i=1}^N (x_i - \bar{x})^2}{N - 1}} \]

enter image description here

groff with eqn

.EQ
s = sqrt { { sum from i=1 to N ( x sub i - x bar ) sup 2 } over { N - 1 } }
.EN

Process with

groff -e test.tr > test.pdf

enter image description here

5
  • I may be wrong, but the eqn sample that you showed looks very similar to what I'd write in LibreOffice Math (and probably in the equivalent add-on to MS Word), or to be more precise what I'd write in LOM if LaTeX disappears at once from my life...
    – gboffi
    Feb 12, 2020 at 13:47
  • You can use the eqn command delim $$ in groff (once at the top of the document) to write inline maths like in TeX. May 22, 2021 at 15:24
  • 2
    Saying groff doesn't support equations because you need to use eqn is like saying C doesn't support printing to the terminal because you need to include stdio.h. eqn is a part of groff. Aug 1, 2021 at 21:15
  • 1
    @kleinbottle4 groff does in fact ship eqn as part of its base installation, but it is still a separate program. Aug 2, 2021 at 8:15
  • @gboffi indeed, libreoffice uses the eqn syntax... Which I find much cleaner than the latex one. But less popular to share math in text form
    – yota
    Jul 27 at 6:10
6

TeX is also used much more frequently than roff or eqn, including on websites and message boards. For example, the math sites here on SX use MathJax, which is based on LaTeX. If you ever want to publish a paper, you’ll also need to know it.

2
  • 5
    Precision: AFAIK, MathJax uses a LaTeX-like syntax for mathematical formulas and a few commands such as \def and\newcommand, but is no more based on LaTeX than that.
    – frougon
    Feb 11, 2020 at 14:41
  • The underlying engine is completely different, yes. The syntax is designed to be as compatible as reasonably possible.
    – Davislor
    Mar 31, 2022 at 11:29
2

I prefer Groff (with -ms) because the commands are shorter and easier to read, especially if you make your own macros. This is because, in eqn, whitespace is used as syntax rather than curly brackets.

E.g. the eqn

cos theta + roman i sin theta

is the same as the LaTeX

\cos\theta + \mathrm{i}\sin\theta.

A Groff install is normally about 10MB, which is smaller than a typical LaTeX install. Groff is more modular and in general follows the UNIX philosophy better by taking advantage of the pipeline and having mostly two letter command names.

Ask on the GNU Groff mailing list if you need help:

https://lists.gnu.org/archive/html/groff/

Example (with macros)

.LP
By expanding out the brackets of $pq$, we find that
.L q_vec_mul
.EQ "\*[q_vec_mul]"
pq
=
[[ s _ 1 s _ 2 - #v _ 1 . #v _ 2
,~~
s _ 1 #v _ 2 + s _ 2 #v _ 1 + #v _ 1 * #v _ 2 ]] \.
.EN

groff eqn example

Limitations

In terms of limitations, Groff can do most of what LaTeX can do, but some things like blackboard characters require some research to figure out how to use.

Also, as people have pointed out, the equations look nicer in LaTeX, and it is also more commonly used nowadays.

However, you can use the -Tdvi groff option and then dvipdf the output to produce a PDF with a TeX look.

3
  • “LaTeX's install size of about half a GB” That is absolutely not true. The engine and the format plus a couple of macro packages only occupy several MB. It's TeX Live with all the fonts and documentation that takes a lot of disk space, but of course I want to install all of that because it's actually useful. Aug 2, 2021 at 8:18
  • @HenriMenke Yes that is quite true. Indeed I installed TinyTex and it was only about 70 MB or so. I have changed my answer above. Aug 6, 2021 at 15:40
  • 1
    What's interesting is to see where the size comes from. I did a write-up on this for a question on reddit a couple weeks back. reddit.com/r/LaTeX/comments/oqmb3w/… I may expand this into a proper blog post somewhere down the line.
    – Don Hosek
    Aug 6, 2021 at 16:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .