LaTeX (Maths Typesetting)

Spread the love

Writing Beautiful Mathematics: Getting Started with LaTeX on Windows

If you haven’t done so already, you may want to start by reading the Preface to the Computing Series: Software as a Force Multiplier, Sections 1-3.

2nd ed. Revised with new templates Sep 21, 2019, 1st ed. May 18, 2010.

Getting Started with LaTex
LaTeX (open source, free) is an essential tool to write beautifully formatted mathematics efficiently. If you have extensive mathematical symbology and have been using MS Word for this, you are using the wrong tool for the job (see Figure below). Setting up LaTeX should take no more than an hour, after which you can produce publication-ready mathematical documents quickly and reliably. This article walks you through setting up a working platform for Windows, and provides the LaTeX templates you’ll need to produce your first examples. Also shared is the source code and compilation instructions for an example paper, which you can download and modify for your own use, containing several advanced stylistic elements (endnotes, figures with captions, URLs, code listings, and epigraphs).

An example of mathematics written in LaTeX, from Finite Summation of Integer Powers (Part 3), A. Ebrahim, C. Ouellette, 2010.

An example of mathematics written in LaTeX, from Finite Summation of Integer Powers (Part 3), A. Ebrahim, C. Ouellette, 2010.


If you’re not sure what LaTeX / TeX is, start with Introduction to LaTeX. If you already have a TeX platform set-up, skip to Modularity in TeX. To see an equation heavy paper on an elementary topic (accessible to undergraduates), check out Finite Summation of Integer Powers (Part 3).


Setting up LaTeX / TeX on Windows

For best results, set aside an hour and follow the instructions carefully. This is one situation where it is worth going step by step. It will be easier to configure correctly the first time rather than troubleshoot problems later.

Here’s what we’ll cover:

Let’s get started!


High quality, free versions of LaTeX/TeX are now available for Windows.

1. Download & install MiKTex, GhostScript, GhostView, PDF Xchange (optional), and TeXnicCenter

1a. Install MiKTeX.

Download the latest version of MiKTeX from here. The basic 32-bit version is fine for both 32 and 64 bit machines. You should use the Portable version so you can move your installation between machines by simply copying the directories over. Note that at 170MB, MiKTeX is a large download, this so may take several minutes. This article has been tested with MikTeX 2.9.

What is MiKTeX? In TeX terminology, MiKTeX is the TeX distribution that you’ll be using. Why MiKTeX? It is one of the comprehensive distributions of TeX, i.e. it has built into it the most common packages you’ll need including facilities for producing PDF, PostScript, or DVI document outputs and contains the most common packages such as AMS-TeX and BibTeX. Note, you won’t actually interact with MiKTeK. It is the foundation layer and provides all the required back-end facilities. Your interactions will typically be with TeXnic Center.

  1. Run the MiKTeX Installer and follow along below:
  2. Accept the copying condition (nothing alarming here)
  3. Install for anyone… (less hassle if you have multiple user accounts on your machine)
  4. NOTE WHERE the software is being installed (you’ll need to know this to configure TeXnicCenter)
    If you keep the default settings (recommended), MikTeX will be installed to

    • C:\Program Files (x86)\MiKTeX 2.9
  5. Choose your preferred paper (e.g. A4 in UK, Letter in US)
  6. Yes, install missing packages on the fly (easier if you’re new to MiKTeX)
  7. Start the install. It may take several minutes.

Note: Files to know:

  • mo.exe – MikTeX options
  • mpm.exe – MikTeX Package Manager (MPM)
  • texworks.exe – built in lite editor
  • miktex-zzdb2-2.9.tar.lzma – available for download from CTAN

1b. Install GhostScript & GhostView

Download GhostScript as a 32-bit Windows executable from here. GhostScript is an interpreter for the PostScript page description language used by laser printers.

Download GhostView as a 32-bit Windows executable from here. GhostView is a graphical interface for GhostScript that allows PostScript pages to be viewed or printed.

Note: if you want the 64-bit versions of the programs, go to each program’s downloads page: GhostScript, GhostView

  1. Install both programs: first GhostScript (gs904w32), then GhostView (gsv50w32). Keep all default settings checked.
  2. In particular, NOTE DOWN the paths where the programs are being installed. You’ll need to know these to configure TeXnicCenter in Step 1e. If you keep the default settings (recommended), GhostScript and GhostView will be installed, respectively, to paths like this:
    • C:\Program Files (x86)\gs\gs9.04
    • C:\Program Files (x86)\Ghostgum


1c. You will need a PDF Viewer. Most computers have Adobe Acrobat Reader pre-installed. However, I recommend the free PDF Xchange Viewer as it is (in my opinion) smaller, faster, and has better annotation/highlighting/editing functionality than the clunkier Adobe Acrobat reader.

  1. You can download PDF Xchange Viewer from here. Look on the right-hand side-bar, and choose the EXE installer option.
  2. Install PDF Xchange Viewer using the default installation settings EXCEPT on the LAST page of the installer:
  3. Important Note: on the last page of the installer you are asked whether you wish to install the Ask Search toolbar. Suggestion: Decline this. It is a “partner product” that is not in any way related to the PDF Viewer you want.


1d. Download TeXnicCenter 2.0 from here.(Again, you have a choice of 32- or 64-bit versions; 32-bit works for all machines.) TeXnicCenter is a visual editor (IDE) for composing your TeX documents.

  1. Run the TeXnicCenter Installer, noting the following recommended settings as you proceed:
  2. Keep the default selections, including installing the “Typical” package, which contains everything
  3. (optional) Under “Additional Tasks”, select the checkbox “Add TeXnicCenter to the Send menu” — this makes it easier to right-click on a TeX file and open it up in TeXnicCenter…

Summary / Check
This completes the installation step. You should now have installed on your computer the following applications:

  1. MiKTeX (TeX/LaTeX distribution),
  2. GhostScript (PostScript and PDF engine),
  3. GhostView (Postscript viewer),
  4. (optionally), PDF Xchange Viewer (free, fast, feature rich PDF Viewer), and, finally,
  5. TeXnicCenter (LaTeX Document preparation environment).

2. Configuring TeXnic Center, your TeX editor

Let’s setup TeXnic Center:

  1. Start TeXnic Center (Desktop shortcut or Start menu)
  2. The Configuration Wizard will appear if TeXnic Center has not previously been configured. Go through it.
  3. Directory for executables (latex, tex, etc.)? These are in MiKTeX here: C:\Program Files (x86)\MiKTeX 2.9\miktex\bin
  4. DVI viewer? It’s YAP, in MiKTeX here: c:\Program Files (x86)\MiKTeX 2.9\miktex\bin\yap.exe
  5. PostScript viewer? It’s GSView here: c:\Program Files\Ghostgum\gsview\gsview32.exe
  6. PDF Viewer? You can decide, but if you installed the recommended PDF Xchange Viewer in Step 1c. above, this should already be filled in. Otherwise, provide the installation location for your PDF Viewer.1 (If you are prompted to enter additional optional settings for PDF viewing, you can safely ignore these and just click Next.)
  7. Click Finish. TeXnicCenter will now create the main output profiles for you to create DVI, PS, and PDF documents.
  8. If successful, you will see a drop-down menu in the toolbar with LaTeX -> DVI. Change this to LaTeX -> PDF.
  9. Close TeXnic Center so that the configuration is saved and restart (if the program crashes before you close for the first time, you’ll have to reconfigure).

Note, many useful references are already in TeXnic Center, so you will have most of what you need readily to hand.

You’re now ready to start producing PDF documents from TeX source.


3. Typesetting and producing your first document

  1. In TeXnic Center, start a new document: File > New > File…Copy and paste the following “Hello World!” code into your new LaTeX document and save it somewhere. (Or you can download it from here.)

    % Minimal template for LaTeX / TeX
    \documentclass{article}
    \begin{document}
    Hello World! This is a test.

    A remarkable equation of Leonhard Euler:
    $$-e^{i \pi} = 1$$
    \end{document}

  2. Check that LaTeX => PDF output profile is selected in the drop-down list in the menu toolbar.
  3. Save the file to a working directory of your choice. The final PDF will then be written to the same directory.
  4. “Build” and “View” the document. The quickest way is with keyboard shortcut Ctrl+Shift+F5. You can also use the toolbar icon (Figure) or the Menu command: Build > Build and View Output. As the Build process is running, you’ll see a stream of commentary in the Output pane. What you care about is the result at the end of the process, hopefully:
    LaTeX-Result: 0 Error(s), 0 Warning(s), 0 Bad Box(es), 1 Page(s)

The first time you use TeX, the Build and View step may take up to 30 seconds while TeXnicCenter loads up all of the modules that it needs. After this, the process should be quick.

Assuming there are no errors, you should see a PDF appear that looks like this.

Otherwise try doing the Build and View steps separately:

  1. Build using the menu command Build > Build Output, the toolbar icon (Figure 2), or the keyboard shortcut Ctrl+F7.
  2. Verify in the Output Window that the last line is shown with 0 Errors, 0 Bad Boxes, 1 Page. If you see this, it means that there were no problems in producing the document, and 1 page of PDF output has been created.
  3. Click the View toolbar icon (Figure 3), or keyboard shortcut F5 to load PDF output file into your default PDF viewer.

If you’re using PDF Xchange Viwer, you’ll need to change the default PDF Viewer using the Menu command: Build > Define Output Profiles… > Viewer Tab. Set View project output to Command line argument and enter %bm.pdf. Set the Forward search command line argument and leave the box blank. Set the close option to Do not close. Click OK. Recompile (Ctrl+Shift+F5) and verify that a PDF pops up at the end of the compilation.

If it all works, give yourself a pat on the back. You’ve finished the configuration. The rest of the document will equip you with what you need to continue.


4. A starter template for mathematics writing.

The test code given above was minimal. Once you have gotten this working, you’ll need a richer template to be able to produce basic documents.

A better template for writing mathematical documents in TeX, shown below, produces a PDF like this.

% Working Template for LaTeX / TeX (AKE, 4.Aug.2008)
\documentclass[10pt, a4paper]{article}
% == packages
\usepackage{amssymb} % AMS maths symbology
\usepackage{amsfonts} % math fonts, e.g. $\mathbb{Z}$ for integers
\usepackage{amsmath} % \eqref, \binom, and more
\usepackage{graphicx} % include graphics with \includegraphics{file.eps}
\usepackage{wrapfig} % wrap following text around previous figure
\usepackage[pass]{geometry} % allows changing margins within document
\newgeometry{top=2.5cm,bottom=2.3cm,left=2.5cm,right=2.3cm} % better margins technical content

% == definitions
\newtheorem{theorem}{Theorem}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{proof}[theorem]{Proof}
\newcommand{\qed}{\ensuremath{_\blacksquare}} %for end of proof symbol

\begin{document}
\title{Mock Paper (or your title here)}
\author{J.Doe (or your name here)}
\date{August 4, 2008 (or /today)}
\maketitle
\tableofcontents
%\newpage % uncomment to have title on its own page

% === Put your document text below
\section{Getting Started}
Hello! Let’s kick the tires on your \TeX installation.

\paragraph{Bits and Pieces}
With \TeX\ it’s easy to use mathematical symbols.

\paragraph{Example 1}
This remarkable equation of Leonhard Euler, $$-e^{i \pi} = 1,$$ unifies geometry, trigonometry, analysis, and complex variables.

\paragraph{Example 2}
Is $\pi^{\sqrt{2}}$ algebraic or transcendental? A number is algebraic if it is the root of a polynomial with rational coefficients. Algebraic numbers include the rationals but also selected irrationals such as $\sqrt{2}, \sqrt[3]{2}$, and in general $\sqrt[n]{p}$ for any prime number $p$ and any positive integer $n$. A number is transcendental if it is not algebraic, i.e. if it is irrational and is not the solution to any polynomial with rational coefficients. Examples are $\pi$ and $e$.

% === End
\end{document}

Compiling this should give you a taste of what you can achieve using TeX.

With a little practice, it is remarkable what you can do, freeing up more time to work on your content and less time spent on formatting.

A collection of snippets may be useful.


5. A journal quality article

To write papers in a journal quality format with all of the writing devices one typically wants (footnotes, endnotes, URLs, epigraphs, figures with captions, etc.), you will need to install packages (see next section for how).

Once you do, here’s an example of what you can produce: it’s an expository paper I wrote in June 2016 on Number, using the packages: amsfonts (which includes amssymb), amsmath, graphicx, wrapfig, epigraph, listings, mathtools, amsaddr, url, endnotes, footmisc).

An expository paper I wrote in LaTeX in June 2016 on Number. Uses the packages: amsfonts (which includes amssymb), amsmath, graphicx, wrapfig, epigraph, listings, mathtools, amsaddr, url, endnotes, footmisc.

An expository paper I wrote in LaTeX in June 2016 on Number. Uses the packages: amsfonts (which includes amssymb), amsmath, graphicx, wrapfig, epigraph, listings, mathtools, amsaddr, url, endnotes, footmisc.

You can download the source code, compilation script, and paper here:
Paper Source (.tex) and Paper Template (.tex)
PDF paper
compilation script (.bat)


6. Adding packages to LaTeX

What is a package? A package is a .lzma or .cab compressed file that contains various files including a .sty which adds additional styles and commands to LaTeX.

You can add packages to your TeX installation manually.

1. Run MiKTeX Package Manager (MPM): cmd then mpm. Select the local package repository: Repository > Change Package Repository > Packages shall be installed from directory > Choose directory..., typically MikTek\TeX\.

2. To install packages, you will need to have three essential database files (miktex-zzdb*-2.9.tar.lzma, where *=1,2,3) in the local package repository. This step only needs to be done once.

Now you are ready to download & install packages:

3. LaTeX packages can be downloaded for free from CTAN (Comprehensive TeX Archive Network). Copy the .lzma file to the local repository (see above). Then in MPM (Repository > Synchronize) you’ll see the tar.lzma file you’ve just downloaded (e.g. wrapfig). Install it by pressing (+).

That’s it.

To use the package within TeX source code, use the command \usepackage{ }.


7. LaTeX reference sheets and resource links.

Close & Happy TeX-ing!

The final article in this series explains how to use a modular approach to document development that may help make your TeX-ing easier to manage and more efficient. You’ll find shared there a collection of modular templates to get you started.

Happy TeX-ing! Good luck on your journey using LaTeX for your technical document preparations needs!


>> Further reading:

 

 

  1. If you don’t have a PDF Viewer, consider PDF Xchange Viewer, which is free, much faster, and much more capable than the Adobe Acrobat Reader, which is available for free from Adobe’s site.

2 comments to LaTeX (Maths Typesetting)

  • loshi

    I’ve been exploring for a little bit for any high-quality articles or blog
    posts in this sort of area . Exploring in Yahoo I eventually stumbled upon this
    site. Studying this information I am happy to say that I came upon just
    what I needed.

  • Assad Ebrahim

    Loshi, thanks! Note, I’ve uploaded to Section 5 additional templates to illustrate a journal format article. Feel free to download the source code (.tex) and paper (PDF).

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Your comments are valued! (Please indulge the gatekeeping question as spam-bots cannot (yet) do simple arithmetic...) - required

Optionally add an image (JPEG only)

 

Stats: 1,066,417 article views since 2010 (March update)

Dear Readers:

Welcome to the conversation!  We publish long-form pieces as well as a curated collection of spotlighted articles covering a broader range of topics.   Notifications for new long-form articles are through the feeds (you can join below).  We love hearing from you.  Feel free to leave your thoughts in comments, or use the contact information to reach us!

Reading List…

Looking for the best long-form articles on this site? Below is a curated list by the main topics covered.

Mathematics-History & Philosophy

  1. What is Mathematics?
  2. Prehistoric Origins of Mathematics
  3. The Mathematics of Uruk & Susa (3500-3000 BCE)
  4. How Algebra Became Abstract: George Peacock & the Birth of Modern Algebra (England, 1830)
  5. The Rise of Mathematical Logic: from Laws of Thoughts to Foundations for Mathematics
  6. Mathematical Finance and The Rise of the Modern Financial Marketplace
  7. A Course in the Philosophy and Foundations of Mathematics
  8. The Development of Mathematics
  9. Catalysts in the Development of Mathematics
  10. Characteristics of Modern Mathematics

Electronic & Software Engineering

  1. Electronics in the Junior School - Gateway to Technology
  2. Coding for Pre-Schoolers - A Turtle Logo in Forth
  3. Experimenting with Microcontrollers - an Arduino development kit for under £12
  4. Making Sensors Talk for under £5, and Voice Controlled Hardware
  5. Computer Programming: A brief survey from the 1940s to the present
  6. Forth, Lisp, & Ruby: languages that make it easy to write your own domain specific language (DSL)
  7. Programming Microcontrollers: Low Power, Small Footprints & Fast Prototypes
  8. Building a 13-key pure analog electronic piano.
  9. TinyPhoto: Embedded Graphics and Low-Fat Computing
  10. Computing / Software Toolkits
  11. Assembly Language programming (Part 1 | Part 2 | Part 3)
  12. Bare Bones Programming: The C Language

Pure & Applied Mathematics

  1. Fuzzy Classifiers & Quantile Statistics Techniques in Continuous Data Monitoring
  2. LOGIC in a Nutshell: Theory & Applications (including a FORTH simulator and digital circuit design)
  3. Finite Summation of Integer Powers: (Part 1 | Part 2 | Part 3)
  4. The Mathematics of Duelling
  5. A Radar Tracking Approach to Data Mining
  6. Analysis of Visitor Statistics: Data Mining in-the-Small
  7. Why Zero Raised to the Zero Power IS One

Technology: Sensors & Intelligent Systems

  1. Knowledge Engineering & the Emerging Technologies of the Next Decade
  2. Sensors and Systems
  3. Unmanned Autonomous Systems & Networks of Sensors
  4. The Advance of Marine Micro-ROVs

Math Education

  1. Teaching Enriched Mathematics, Part 1
  2. Teaching Enriched Mathematics, Part 2: Levelling Student Success Factors
  3. A Course in the Philosophy and Foundations of Mathematics
  4. Logic, Proof, and Professional Communication: five reflections
  5. Good mathematical technique and the case for mathematical insight

Explore…

Timeline