Gone Are The Days We Worship LaTeX
Ditch Latex and Submit to GNU Supremacy
In Stallman We Believe
Guess who’s back ??? yeah yeah yeah!!! Daddy is home. We back at it with another open source tool your probably haven’t heard of, me being a linux fanatic and believing in Richard Stallman Supremacy, በሽታውን ቀለል ያርግልት (him dealing with cancer).
So lets dive in.
Groff
What is Groff, Why Groff ? yeah lets answer your questions.
What Is Groff
Groff, short for “GNU troff,” is a typesetting system used to create formatted documents. Similar to LaTex.
Groff was initially developed by James Clark in 1979 as a replacement for the Unix typesetting system, troff. Richard M. Stallman, founder of the Free Software Foundation (FSF), our supreme leader :), took over the project in 1982 and renamed it GNU troff. Now the purpose of Groff was to provide a free and open-source alternative to proprietary typesetting systems.
Groff is based on the original troff language but also includes significant enhancements and additional features. The GNU troff package, which includes Groff, was first released as part of the GNU Project in 1987. Groff supports various output formats, including PostScript, PDF, HTML, and plain text.
It has a powerful macro language called “roff” that allows users to define custom formatting commands. Groff has gained popularity among Unix and Linux users for its flexibility and extensive documentation. Over the years, Groff has undergone several updates and improvements, incorporating feedback and contributions from the open-source community.Today, Groff remains a widely used typesetting system, providing a reliable and versatile tool for creating professional-looking documents.
And it is installed by default in all linux systems and light weight, latex package is 2GB or above depending on the other dependencies you add.
How to Groff
So how do you Groff ? simple using your favorite text editor (assuming your a chad its probably vim or neovim ) create a file with the .ms extension, ik sounds sus like it stands for microsoft but it actually stands for manuscript and is one of the most used macro package from groff, now groff has many macro packages like man the one they use to write manual pages for packages in linux, and also include others like mom,me,mm,mdoc and so on read the fucking manual for those.
So after creating your .ms groff file using your favorite text editor you just start writing, One thing you need to know about groff syntax is that its line inital or it have to be written above what ever you are about to input, so it would look something like this :
Now the common format we want to out put to is PDF so this command we would use to convert out .ms groff file would be
groff -ms /file/path/ -T pdf > outputfile.pdf
Then we would get an output file that would look something like this :
Here are some basic groff syntax you might want to use if you don’t want to read the man pages
- .TL: title
- .NH: heading
- .AU: author
- .AB: Abstract
- .TH: Defines the title and header information for a document.
- .SH: Starts a new section within a document.
- .SS: Starts a new subsection within a section.
- .P: Starts a new paragraph.
- .B: Applies bold formatting to text.
- .I: Applies italic formatting to text.
- .T: Inserts a table.
- .FIG: Includes a figure or image in the document.
- .EQ: Starts an equation block.
- .PS/.PE: Begins and ends a PostScript block.
- .TP: Creates a hanging paragraph with a tag and description.
- .UL: Applies underline formatting to text.
- .NF/.FI: Starts and ends a fixed-width font section.
- .TH: Defines the title and header information for a document.
- .DT/.DD: Used in a description list to define terms and descriptions.
Math and Images?
Don’t worry i got you, so now adding images to Groff is kind of tricky.
how do you add images ?
Images in groff require a .PDFPIC register, which takes PDF photos. It can be used with the -C -R -L for left, right and center respectively.
Next thing is you will need a tool called imagemagick
it is installed by default in most distros but if yours does not have it you can install it manually i.e *
- export images using the ` groff -Tpdf -U -ms /inputfile/.ms > output.pdf` command or just add the -U (unsafe) argument
will output
how do you do math ? you asking, i hear you.
you can use mathematical expressions and equations by leveraging the built-in equation capabilities. Simple as:
.EQ
x = 2 + 3 * 4
.EN
Things to note about the equation in groff is :
-
Compilation of groff when equations are added is different like ` groff -Tpdf -P-e -e -ms groff.ms > output.pdf
we use this compile command followed by the argument
-e` so groff knows we are doing math -
Every Equation in .EQ appears on one line so we would have to have multiple .EQ in one file
-
formatting greek letters phi , pi, theta and others you just write their names within the .EQ tag and it will appear
-
multiple line breaks within the .EQ won’t show up within the finished project meaning spaces and line breaks will just appear on one line.
-
you can define variables in groff to make it easier to write math equations you can use the define word followed by variable name and equation in between `` apostrophes, i.e. define disc
3 + 5
then writing disc withing any .EQ block will print out 3 + 5. -
You can write inline math using a delimiter, all you have to do is setup a delimiter within one of your .EQ and .EN saying *delim \(* meaning anything that starts with $ and ends with $ will be rendered as an equation. Your delim can be anything other than\) sign it can be ##,@@ but be sure to use two because one is a starting point and another is an ending point
Here is a simple groff math:
while the output looks like
Why i recommend groff than latex, for it being really light weight and easier to submit assignments and its preinstalled in every linux machine.
Resources ( Dive Deeper)
- Papers on troff and its companions
- The GNU Troff Manual
- Writing man Pages Using groff Linux Journal
- An Introduction to groff Douglas B. Rumbaugh
Hope you enjoyed this one and had an interesting new discovery, bit more technical and detailed but yeah you live you learn