# Latex vs Groff for mathematics formatting

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?

• For a gentle introduction to roff you might be interested in the video tutorials by Luke Smith: youtube.com/… Feb 11 '20 at 3:57
• See tex.stackexchange.com/a/10308/15925 and tex.stackexchange.com/a/159741/15925 for a couple of user experiences. Feb 12 '20 at 8:02
• Hi, @fresh, and welcome to TeX.SE! If LaTeX feels overweight, you might be interested in Emacs Org-mode which is similar to Markdown but better and has nice export to LaTeX and a great community. Feb 12 '20 at 12:28

# 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}}$


## 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


• 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... Feb 12 '20 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 at 15:24
• 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 at 21:15
• @kleinbottle4 groff does in fact ship eqn as part of its base installation, but it is still a separate program. Aug 2 at 8:15

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.

• 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. Feb 11 '20 at 14:41

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


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.

• “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 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 at 15:40
• 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. Aug 6 at 16:21