{{Short description|Preprocessor that formats equations for drawing}} {{lowercase title}} {{Infobox software | name = eqn | logo = | screenshot = | screenshot size = | caption = | author = Brian Kernighan,<br />Lorinda Cherry<br />(AT&T Bell Laboratories) | developer = Various open-source and commercial developers | released = {{Start date and age|1974|6}} | latest release version = | latest release date = | programming language = C, Yacc<ref name="Kernighan_Brailsford" /> | operating system = Unix, Unix-like, Plan 9 | platform = Cross-platform | genre = Command | license = Plan 9: MIT License<br>groff: GPL-3.0-or-later | website = }} Part of the troff suite of Unix document layout tools, '''eqn''' is a preprocessor that formats equations for printing. A similar program, '''neqn''', accepted the same input as eqn, but produced output tuned to look better in nroff. The eqn program was created in 1974 by Brian Kernighan and Lorinda Cherry. It was implemented using the yacc compiler-compiler.<ref name="Kernighan_Brailsford" />

The input language used by eqn allows the user to write mathematical expressions in much the same way as they would be spoken aloud. The language is defined by a context-free grammar, together with operator precedence and operator associativity rules.<ref name="Kernighan_Cherry_1975" /> The eqn language is similar to the mathematical component of TeX, which appeared several years later, but is simpler and less complete.

An independent compatible implementation of the eqn preprocessor has been developed by GNU as part of groff, the GNU version of troff. The GNU implementation extends the original language by adding a number of new keywords such as ''smallover'' and ''accent''. mandoc, a specialised compiler for UNIX man pages, also contains a standalone eqn parser/formatter.

== History == Eqn was written using the yacc parser generator.<ref name="Kernighan_Brailsford" />

== Syntax examples == Here is how some examples would be written in eqn<ref name="Kernighan_Cherry_1978" /> (with equivalents in TeX for comparison):

{| class="wikitable" |- !TeX !eqn !formula |- |{{code|lang=latex|a^2}} |<code>a sup 2</code> |<math>a^2</math> |- |{{code|lang=latex|1=\sum_{k = 1}^N k^2}} |<code>sum from { k = 1 } to N { k sup 2 }</code> |<math>\sum_{k=1}^N k^2</math> |- |<syntaxhighlight lang="latex" inline>x = {-b \pm \sqrt{b^2 - 4ac} \over 2a}</syntaxhighlight> |<code>x = {-b +- sqrt{b sup 2 - 4ac}} over 2a</code> |<math>x= {-b \pm \sqrt{b^2 - 4ac} \over 2a}</math> |}

Spaces are important in eqn; tokens are delimited only by whitespace characters, tildes ~, braces {} and double-quotes "". Thus <code>f(pi&nbsp;r&nbsp;sup&nbsp;2)</code> results in <math display="inline">f(pi r^{2)}</math>, whereas <code>f(&nbsp;pi&nbsp;r&nbsp;sup&nbsp;2&nbsp;)</code> is needed to give the intended <math display="inline">f(\pi r^2)</math>.

==References== {{Reflist|refs= <ref name="Kernighan_Cherry_1975">{{cite journal|year=1975|title=A System for Typesetting Mathematics|journal=Communications of the ACM|volume=18|issue=3|pages=151–157 |first1=Brian W. |last1=Kernighan |first2=Lorinda L. |last2=Cherry| author-link = Brian Kernighan| author2-link = Lorinda Cherry |doi=10.1145/360680.360684|s2cid=155801|doi-access=free}}</ref>

<ref name="Kernighan_Cherry_1978">{{Citation | last = Kernighan | first = Brian W. | last2 = Cherry | first2 = Lorinda | author-link = Brian Kernighan | author2-link = Lorinda Cherry | year = 1978 | title = Typesetting Mathematics — User’s Guide | edition = 2nd | url = https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=699ba8cbd336af184c02165bb766832f385880ab | format = PDF }}</ref>

<ref name="Kernighan_Brailsford">{{cite web|url=https://www.youtube.com/watch?v=vT_J6xc-Az0 |archive-url=https://ghostarchive.org/varchive/youtube/20211222/vT_J6xc-Az0 |archive-date=2021-12-22 |url-status=live|title=UNIX Special: Profs Kernighan & Brailsford |work=Computerphile |date=September 30, 2015 }}{{cbignore}}</ref>

}}

== External links == *[http://www.kohala.com/start/troff/v7man/eqn/eqn2e.ps Typesetting Mathematics, User's Guide (Second Edition)] *{{webarchive |url=https://web.archive.org/web/20070808042840/http://www.uwm.edu/cgi-bin/IMT/wwwman?topic=neqn(1)&msection= |date=August 8, 2007 |title=UNIX man page for neqn(1) }} * {{man|1|eqn|Plan 9}} * {{man|1|eqn|Linux}}

{{Plan 9 commands}}

eqn Category:Plan 9 commands

{{Unix-stub}}