geqn Command in Linux



Linux provides a handy command named geqn that formats mathematical equations. In this tutorial, we'll discuss how to use the geqn command in Linux using practical examples. This command is the GNU implementation of the standard eqn preprocessor that formats mathematical equations in documents.

The geqn command works with text formatting tools like groff, troff, and nroff to create well-formatted equations for typeset documents.

Table of Contents

Here is a comprehensive guide to the options available with the geqn command −

How to Use geqn Command in Linux?

In most Linux distributions, the geqn utility is pre-installed and is ready to use. However, if it's not installed, you can use the distribution's default package manager to install it on your system.

The geqn utility makes it easier to add complex mathematical expressions to documents. It enables us to write equations in a simple and clear way. The command then translates these descriptions into formatting that typesetting systems can understand.

Basic Syntax and Options of geqn Command

To use this command in Linux, you can follow the below-mentioned syntax −

eqn [-rvCNR] [-dxy] [-Tname] [-Mdir] [-fF] [-sn] [-pn] [-mn] [files...]

The table below illustrates the commonly used options with geqn command −

Option Description
-dxy It specifies delimiters x and y for the left and right ends of in-line equations, respectively. Any delim statements in the source file will override this setting.
-C This option allows the utility to recognize ".EQ" and ".EN" blocks even if they are followed by a character other than a space or newline.
-N It disallows newlines within delimiters. It enables eqn to recover better from missing closing delimiters.
-v It prints the version number of the utility.
-r It applies only one size reduction.
-mn This option sets the minimum point size to n. As a result, subscripts and superscripts will not be reduced below this size.
-Mdir It searches the directory dir for eqnrc before checking the default directories.
-R It doesn't load the eqnrc file.
-Tname It specifies the output device as "name". This defines a macro with a value of 1 and is typically used by eqnrc to provide appropriate definitions for the output device. The default output device is ps.
-fF It is equivalent to the gfont F command.
-sn This option is equivalent to the gsize n command. This option is deprecated, as eqn will normally use the current point size when processing equations.
-pn It specifies that subscripts and superscripts should be n points smaller than the surrounding text. This option is deprecated, as eqn typically sets subscripts and superscripts to 70% of the surrounding text size.

Examples of geqn Command in Linux

Basic Use of geqn Command

Suppose we have a file named example.eqn that contains the following content −

.EQ
	e sup {i pi} + 1 = 0
.EN

Let’s run the geqn command to format the specified equation −

geqn example.eqn > formattedExample.txt
geqn Command in Linux1

You can verify the formatted equation by running the following command −

cat formattedExample.txt
geqn Command in Linux2

Writing and Processing Equations with geqn and groff to Create a PDF

In geqn, you write equations between “.EQ” and “.EN” blocks. For instance, we create a file named “sampleEquation.eqn” with the following following command −

nano sampleEquation.eqn

Now specify the following content within the sampleEquation.eqn file −

.EQ
	x sup 2 + y sup 2 = z sup 2
.EN

Now process this file with geqn and groff, as follows −

geqn sampleEquation.eqn | groff -Tpdf > sampleEquation.pdf

When you run this command, you will see a warning, however, the command executes irrespective of the warning −

geqn Command in Linux3

This command sets the output device to pdf with the -T option and specifies a minimum point size of 12 with the -s option before processing the document. Let’s display the formatted pdf using the following command −

cat sampleEquation.pdf 
geqn Command in Linux4

Writing and Processing Equations with geqn and groff to Create a PostScript

Let’s run the geqn command with -T and -s options to specify the device and minimum point size −

geqn -Tps -s 12 example.eqn | groff -Tps > example.ps

This command uses the T option to set the output device to PostScript and the -s option to specify the minimum point size to 12 before processing the document −

geqn Command in Linux5

Now run the following command to view the resulting PostScript (example.ps) to see the formatted text and equation −

cat example.ps
geqn Command in Linux6

Difference between GNU eqn and UNIX eqn

GNU eqn and UNIX eqn are both tools for formatting mathematical equations but differ in their capabilities and integration. UNIX eqn is part of the traditional UNIX troff/groff suite. It supports basic mathematical notation and works with older troff systems.

On the other hand, GNU eqn is an enhanced version that integrates with GNU Groff. It is a modern typesetting system. It offers advanced features, supports a wider range of symbols, and provides more formatting options. GNU eqn is better suited for complex and contemporary typesetting needs.

Conclusion

The geqn command in Linux is a tool for formatting mathematical equations. It works with text formatting tools like groff, troff, and nroff. geqn is the GNU version of the standard eqn preprocessor. It helps create well-formatted mathematical expressions in documents.

In this tutorial, we explained how to use geqn, including installation and basic syntax. We provide examples of formatting equations, creating PDFs, and generating PostScript files. Additionally, we compared GNU eqn with UNIX eqn. GNU eqn offers enhanced features and is better suited for modern typesetting. Understanding these differences will help you effectively use geqn for your mathematical typesetting needs.

Advertisements