IL LU S T R A T IO N B Y T H E P R O JE C T T W IN S Manufacturers are ditching equation editors in word-processing software in favour of the LaTeX typesetting language. Here’s how to get started. CRAFT BEAUTIFUL EQUATIONS IN WORD WITH LATEX B Y D A V I D M A T T H E W S LaTeX or Word? For physicists and math-ematicians, the choice is obvious. But for scientists in other fields the merits of LaTeX have largely gone unnoticed. The open-source software system — used to create and precisely format scientific man- uscripts — is more akin to coding than writ- ing. Since its development in 1985, LaTeX has become popular in disciplines such as math- ematics, physics and computer science. Proponents embrace LaTeX because of the total control it offers for document layout, or because it represents a blow to commercial software developers, particularly Microsoft. Others regard the software as too complicated for all but the most demanding of tasks. A 2014 study (M. Knauff & J. Nejasmic PLoS ONE 9, e115069; 2014) that asked scientists from different fields to put both Microsoft Word and LaTeX to the test ended up being one of the ten most discussed papers online the following year, according to data-science company Altmetric (Altmetric is owned by Digital Science, a firm operated by the Holtzbrinck Publishing Group, which has a share in Nature’s publisher, Springer Nature). The article has been viewed more than 240,000 times so far. Over the past few years however, the line between the tools has blurred. In 2017, Micro- soft made it possible to use LaTeX’s equation- writing syntax directly in Word, and last year it scrapped Word’s own equation editor. Other text editors also support elements of LaTeX, allowing newcomers to use as much or as little of the language as they like. “For me, LaTeX is the tool when I want to get the typesetting just so,” says Casey Greene, a bio- informatician at the University of Pennsylvania in Philadelphia. “Word is when ‘good enough’ is OK and/or I’m working with folks who need to use it.” CODING EQUATIONS Unlike ‘what you see is what you get’ text editors such as Word, LibreOffice and OpenOffice, writing in LaTeX is like program- ming. Plain text is wrapped inside commands that describe its formatting (for example, for italics, \textit{text}; and for bold, \textbf{text}), and tables are built cell by cell. This source code is then compiled into a sleek-looking PDF, ready to read. Equations are seen as LaTeX’s strong suit (see ‘Writing equations in LaTeX’). The lan- guage boasts a vast library of shortcuts to dis- play mathematical symbols. (The 2017 version of The Comprehensive LaTeX Symbol List includes some 14,000 symbols.) “One of 1 3 J U N E 2 0 1 9 | V O L 5 7 0 | N A T U R E | 2 6 3 TOOLBOX © 2019 Springer Nature Limited. All rights reserved. the reasons I started using LaTeX was that I can format equations easily that look beauti- ful,” says John Paul Minda, a psychologist at Western University in London, Canada. Indeed, equations were the only feature in which LaTeX outperformed Word in the 2014 study that compared the two tools. When it came to text and tables, Word proved faster and users were less prone to making errors, although LaTeX users “more often report enjoying using their respective software”, the authors noted. Even LaTeX critics such as Daniel Alling- ton, a computational social scientist at King’s College London who has inveighed on his blog against what he calls ‘LaTeX fetish’, acknowl- edges that it handles equations better than alternatives. But, Allington points out, scientists today can use LaTeX’s equation syntax without aban- doning what-you-see-is-what-you-get editors. For example, Allington uses the online tool MathJax. He inserts a few lines of LaTeX code into a web form — no installation is required — and MathJax renders equations in a web page. Word users can also write directly in LaTeX syntax, and then click to convert it into a for- matted equation. Microsoft says that “most” LaTeX expressions are supported, although its website lists 20 keywords that are not (such as \degree, the degree symbol). For Google Docs users, the Auto-LaTeX add-on can turn LaTeX equations into embedded images. Katie Lotterhos, a marine and environmental scientist at Northeastern University in Boston, says this combina- tion of tools works particularly well for her, because most of her collaborators do not know how to use the typesetting language. The downside, she says, is that the software inserts the equation into the document as an image, “which is fine for peer review, but unpopular for typesetters”. Similarly, users of LibreOffice, a free alter- native to Word, can code equations with an extension called TeXMaths, which converts LaTeX syntax into a PNG or SVG image. MASTERING LATEX Users hoping to dive into LaTeX can install a LaTeX software bundle, such as MiKTeX for Windows, MacTeX for Mac OS, or TeX Live for Linux. All are free to download and use, and include tools for compiling LaTeX ‘source code’ into a PDF. Word costs from US$8.25 a month per user as part of the broader Office software suite, although a Microsoft spokes- person says that the company does offer free access to the online version of Word for researchers based at some institutions. Such software bun- dles open the door to authoring entire PDF documents in LaTeX. D o i n g s o a l l o w s researchers to gain “real control” over how a document looks, says Philip Judge, a LaTeX advocate and an astronomer at the High Altitude Observatory in Boulder, Colorado. For Laura Fortunato, an evolutionary anthro- pologist at the University of Oxford, UK, it was the “unreliability” of word processors — their tendency to do something “random” when “you know you’ve done nothing wrong” — that prompted her to learn LaTeX during her PhD. But the process can feel cumbersome. “The main drawback to LaTeX for me was in constantly having to compile the text to see how it looked, and then getting errors you have to spend time tracking down,” says Shannon Nicley, a diamond-growth researcher, also at Oxford. For Nicley, the solution to that problem was Overleaf, a browser-based editor for collaboratively authoring scientific docu- ments. (Overleaf is also owned by Digital Sci- ence.) Overleaf displays the article source code and a live PDF rendering side by side, mean- ing users can quickly see how their changes translate into the finished product. The tool is free for individual users, but costs from $14 a month to add features such as collaboration and the ability to sync with code-sharing site GitHub. So is LaTeX worth mastering? It depends on the researcher: how often do you use equa- tions, how much fine-grained control do you need over a document, and how much time do you have to devote to learning a new language? Basic document creation in LaTeX is rela- tively straightforward. But creating tables is not. Unlike in Word, these cannot be drawn and placed on the page, but must be pro- grammed in, dimension by dimension. In the 2014 study, even LaTeX experts made more mistakes in generating tables, and wrote less text, than did Word novices over a 30-min- ute test period. “Making tables in LaTeX is extremely daunting, even if you have done it dozens of times before,” says Nicley. “It is con- siderably faster for me to open a new Excel sheet, type out the basics of a table, then copy and paste it directly into Word, where I can fine tune the appearance and content.” LaTeX is not the only programming-like option for document formatting. Allington often uses Markdown, which he describes as more “lightweight” than LaTeX, because the formatting commands are more straightfor- ward. In Markdown, says Anthony Gitter, a computational biologist at the University of Wisconsin–Madison, there is “very little technical syntax for contributors to break”. This was one of the reasons that Gitter, and colleagues including Greene at Pennsylva- nia, used Markdown to write an open review of deep learning in biology and medicine. In LaTeX, there is a greater risk that contributors will make changes that prevent the code com- piling into a PDF, he warns. That said, some journals and conferences don’t accept documents in Markdown for- mat, says Dmitry Fedyanin, a researcher at the Moscow Institute of Physics and Technology. Nature, for example, prefers submissions in Word, as the journal’s typesetting system requires this format, says Simon Gribbin, Nature’s managing production editor. Still, around one in ten accepted submissions are in LaTeX format; these are converted to Word before being passed to copy-editors, he says. But at Nature Physics, which covers disci- plines in which LaTeX use is widespread, the editors are more flexible about document for- matting. “LaTeX is just something that physi- cists ‘do’,” explains chief editor Andrea Taroni. “Trying to get them to do otherwise is like trying to herd cats.” ■ David Matthews is a freelance writer based in Berlin. Producing Einstein’s famous equation in LaTeX is almost as simple as writing E = mc^2. The only formatting there is the caret (^), which indicates a superscript. But to display equations in LaTeX properly, you need to wrap the content in a command. Square brackets and a backslash (\[E = mc^2\]) centres the equation on its own line, whereas wrapping an equation in dollar signs ($E = mc^2$) positions it in-line, in the body of the text. LaTeX documents typically include directives at the top that describe the document’s size (A4 paper, for example) and formatting. For mathematical commands to work, users must instruct the software to use a mathematics package, several of which are available. The Comprehensive TeX Archive Network hosts more than 5,000 packages, allowing LaTeX users to use everything from elvish scripts from the mind of author J. R. R. Tolkien to Mongolian, and typesetting styles that mimic those of newspapers. For more-complicated equations, users need to learn the syntax of the command they want to deploy. Fractions, for example, are created by entering \frac{numerator} {denominator}, whereas integrals over the range [a,b] are expressed as \int_{a}^{b}. Thus the integral over the range [0,100] for x2 + (1/2p)x, would be written as \int_ {0}^{100} x^2 + \frac{1}{2\pi}x dx. The browser-based editor Overleaf provides an overview of LaTeX equation formatting at go.nature.com/2eh1daz. D.M. Writing equations in LaTeX “One of the reasons I started using LaTeX was that I can format equations easily that look beautiful.” 2 6 4 | N A T U R E | V O L 5 7 0 | 1 3 J U N E 2 0 1 9 TOOLBOX © 2019 Springer Nature Limited. All rights reserved.