eqn Command in Linux



eqn is a Linux command that is used to format mathematical equations for documents processed by the troff text formatting system. This command translates equations written in a specific language into commands that troff can understand. It is a part of CNU groff package, which is a powerful document formatting system. Eqn helps users in creating well-structured and readable mathematical content within the text documents. This makes it an essential tool for technical and scientific documentation.

Table of Contents

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

Installation of eqn Command

As previously mentioned, eqn is a part of the groff package, which is an essential part of Linux, preinstalled on the system. However, in case of any issue, you can install the package from your default package manager based on the Linux system you are using.

On Debian-based systems, such as Ubuntu, Debian, or Kali Linux, you can install groff package from the below-given apt command −

sudo apt install groff

On Red HAT systems like CentOS, the groff package can be installed using −

sudo yum install groff

On Fedora Linux, you can install groff package from the following command −

sudo dnf install groff

Syntax of eqn Command

The syntax for the eqn command in Linux is as follows −

eqn [options] [file...]

Here,

  • options are various flags to customize the behavior of eqn.
  • file is the input file containing the equations to be processed.

eqn Command Options

With eqn command, you can processes and formats mathematical equations in your documents by using different options that are described below −

Option Description
-d xy Sets the delimiters for inline equations. x and y are the characters used to start and end the equations.
-e Preprocesses equations in the input file before passing it to troff.
-f F Specifies the font to use for the equations, where F is the font name.
-m Specifies a macro package to use with troff.
-p n Sets the minimum size for subscripts and superscripts, where n is the size in points.
-s n Sets the point size for the text in the equations. n is the size in points.
-T name Specifies the output device. name is the device type, such as ps for PostScript.

Examples of eqn Command in Linux

Let’s explain a few examples of eqn command in Linux −

  • Simple Equation
  • Equation with Delimiters
  • Using a File
  • Specifying Font
  • Using Macros
  • Complex Equations

Simple Equation

You can use the eqn command on Linux to process a simple equation and format it using troff. For example, to format the equation, such as x^2 + y^2 = z^2, you can use the following command −

echo 'x^2 + y^2 = z^2' | eqn | troff

This will format the equation (x^2 + y^2 = z^2) for display in a document processed by troff.

Simple Equation

Equation with Delimiters

You can also set custom delimiters for the equation by using the delim option. For example, to use $$ as delimiters with equation, you can use the below-given command −

echo 'delim $$ x^2 + y^2 = z^2 $$' | eqn | troff

This will format the equation (x^2 + y^2 = z^2) using $$ as delimiters.

Equation with Delimiters

Using a File

You can also process equations from a file by specifying the file name, for example, to process equations from a file named input.eqn, you can use −

eqn input.eqn | troff

This will format the equations contained in the input.eqn file for display in a document processed by troff.

Using a File

Specifying Font

If you want to specify the font to use for the equation, you can simply use the -f option. For example, to use the font T, you can use −

echo 'x^2 + y^2 = z^2' | eqn -f T | troff

This will format the equation (x^2 + y^2 = z^2) using the specified font T.

Specifying Font

Using Macros

You can also use macros with the eqn command to define and process equations. For example, to define a macro for differentiation, you can use the below-given command −

echo 'macro d(f,x) diff(f,x) d(f,x)' | eqn | troff

This will format the macro-defined equation for differentiation.

Macros

Complex Equations

To process a more complex equation involving a square root with the eqn command, you can use −

echo 'sqrt(x^2 + y^2) = z' | eqn | troff

This will format the equation (\sqrt{x^2 + y^2} = z).

Complex Equations

That’s how you can use the eqn command in Linux to format and process equations.

Conclusion

The eqn is a powerful command used in Linux for translating equations written in a specific language into commands that troff can understand.

In this tutorial, we explained the installation of eqn command, its basic syntax and different options that can be used with it. Further, we provided a few examples to help users understand the basics of the command and utilize them on their systems according to their needs.

Advertisements