# Using LaTeX to solve math problems in LaTeX more efficiently than with only paper

I have been always solving math problems in LaTeX without pen and paper, since a few years ago. Some have (many) lines of words, some (many) lines of equations, and some of both.

When I saw that I was sometimes running into time problems, and feel not so straightforward for reasoning from the LaTeX code, and worry about the time waste in switching between LaTeX code, recompiling, and viewing pdf files, I began to wonder if doing things completely in LaTeX slows me down. But I remember that when I was doing things completely in paper, I hoped that I could "copy" and "paste" like I did in computer.

I'm looking for ways to improve my productivity for reasoning and working out math problems:

• in pen and paper,
• in LaTeX,
• in some combination of both...

When solving math problems in LaTeX without pen and paper, what are your tips which can improve our productivity?

• I'm not sure that this website is the best place to ask this question, maybe productivity.stackexchange.com would be a better choice for example. By the way, to make things even more complicated, you could also consider adding some mathematical software to your toolbox. Nov 20, 2014 at 16:02
• One thing is almost certain though: if we could copy and paste on paper like on computer, we would end up copying and pasting mistakes, exactly like on computer. Also note that the related feature of "cut and paste" is available with paper, unbelievable as it is. :D Nov 20, 2014 at 16:04
• What "mathematical software"?
– Tim
Nov 20, 2014 at 16:07
• @Tim: computer algebra systems like Mathematica, Sage, or even stuff like IPython, Matlab, etc. Nov 20, 2014 at 16:17
• I usually use LyX for complex equations. It has a nice math editor, and I can just copy the code to my LaTeX document later on.
– yoki
Nov 26, 2014 at 10:54

I am pretty sure the answer to the question in the title—Is solving math problems in LaTeX without paper slower than in paper?—is yes. I work with a computer keyboard in front of me and a pen and pad to my left (yes, I'm left-handed), and when I'm typing up solutions to problems I usually leave the keyboard to scratch on the pad for a while, then go back to the keyboard to LaTeX it up. I can think of some reasons why this might be more true:

• I can think faster than I can type.
• Although in English I type much faster than I write, when writing math I write much faster than I can type LaTeX.
• I can draw pictures by hand much much faster than drawing them in LaTeX.

I admit that this is a totally subjective answer, but I don't know of any colleagues who work first in LaTeX without scribbling on paper or a black/whiteboard first.

As far as tips to be more productive when writing LaTeX, I would suggest to follow good coding practices. AFAIK there are not that many settled conventions on code organization, but some general practices I follow are:

• Start each sentence on a new line.

• Indent code within environment blocks.

• Use braces to enclose groups even if they are only one token. I break this rule in super/subscripts, but adhere to it closely in \frac-tions.

• Use the cool package to make many math expression more like macros.

So for instance (not my best example but one that's at hand),

Let $E$ be the solid.
Its volume is $\frac{1}{8} \frac{4}{3}\pi = \frac{\pi}{6}$.
In spherical coordinates it is a wedge $0 \leq \rho\leq 1$, $0 \leq \theta \leq \pi/2$, $0 \leq \phi\leq \pi/2$.
So the moments are
\begin{align*}
M_{yz} = \iiint_E x\,dV &= \int_0^{\pi/2}\int_0^{\pi/2} \int_0^1 (\rho \Sin{\phi}\Cos{\theta})\rho^2\Sin{\phi}\,d\rho\,d\phi\,d\theta \\
&= \int_0^{\pi/2} \Cos{\theta} \,d\theta\cdot\int_0^{\pi/2} \Sin{\phi}^2 \,d\phi\cdot\int_0^{1} \rho^3\,d\rho \\
&= 1 \cdot \frac{\pi}{4} \cdot \frac{1}{4} = \frac{\pi}{16} \\
M_{yz} = \iiint_E y\,dV
&= \int_0^{\pi/2}\int_0^{\pi/2} \int_0^1 (\rho \Sin{\phi}\Sin{\theta})\rho^2\Sin{\phi}\,d\rho\,d\phi\,d\theta  \\
&= \int_0^{\pi/2} \Sin{\theta} \,d\theta\cdot\int_0^{\pi/2} \Sin{\phi}^2\,d\phi \cdot \int_0^1 \rho^3 \,d\rho \\
&= 1 \cdot \frac{\pi}{4} \cdot \frac{1}{4} = \frac{\pi}{16} \\
M_{xy} = \iiint_E z\,dV
&= \int_0^{\pi/2}\int_0^{\pi/2} \int_0^1 (\rho \Cos{\phi})\rho^2\Sin{\phi}\,d\rho\,d\phi\,d\theta \\
&= \int_0^{\pi/2} d\theta\cdot \int_0^{\pi/2} \Sin{\phi}\Cos{\phi}\,d\phi \cdot \int_0^1 \rho^3 \,d\rho \\
&= \frac{\pi}{2} \cdot \frac{1}{2} \cdot \frac{1}{4} = \frac{\pi}{16}
\end{align*}
So the coordinates of the centroid are
$\left(\frac{3}{8},\frac{3}{8},\frac{3}{8}\right)$


Even for this one I did work it out on paper first.

Update 2023: Nine years after writing this I got an upvote which gave me the occasion to reread it. My workflow hasn't changed much, except that the "pen and pad" to my left is often replaced with a tablet and stylus. The advantage to this workflow is that diagrams are easier to begin freehand as well.

• "[I] adhere to it closely in \frac-tions" Do you really know of people who don't? Nov 20, 2014 at 16:57
• @T.Verron: Yes. And people who edit journals will probably tell of many more LaTeX sins. Nov 20, 2014 at 16:58
• Brr. Btw, I never heard of the cool package, it does indeed look quite cool! You could use it to prettify even further your example, for example by replacing the \int_foo^bar{baz \,dx} with \Int{foo}{x,bar,baz}. There doesn't seem to be macros replacing \iiint though. Nov 20, 2014 at 17:02
• @T.Verron: I learned about cool on this site too. I know about the \Int macro now but not the first time I wrote the code sample above. Nov 20, 2014 at 17:05
• @T.Verron: I often write \frac12 etc., though recently I try to avoid it a bit. Not a big deal, I guess. (And re: journal: yes, I do work for a journal, and I can see really, really bad LaTeX code. \frac1n really is not that bad...) Nov 20, 2014 at 21:50

If you can compose your latex-math quickly enough it gives you additional flexibility and productivity when you attempt to solve problems directly in latex. Given such speed, it can then be faster to work in latex than on paper, since long sequences can be cut and pasted, allowing next steps to be made with editing tweaks. I've worked though some tricky math this way that I probably wouldn't have tried on paper since it would have taken too long to keep writing out the long equations (all differing by just a bit).

With that in mind, here are some methods that I find improve my latex development productivity, facilitating work directly in latex when appropriate:

• Using pdflatex -synctex=1, and a pdf viewer that supports this like Sumatra PDF. That allows you to double click on text or equations in the pdf file, and immediately be editing the associated .tex files at the position of interest. If you work on Windows, Sumatra is also nicer than Adobe Reader because it doesn't apply a windows lock to the file, and will automatically reload the pdf if it is changed by running 'make' in the background.

• If there are math sequences that you find yourself typing again and again, make a macro for it. Some examples:

\newcommand{\inv}$1${\frac{1}{#1}}

\newcommand{\abs}$1${\lvert{#1}\rvert}

\newcommand{\norm}$1${\lVert{#1}\rVert}

\newcommand{\lr}$1${\left(#1\right)}

\newcommand{\Bx}$0${\mathbf{x}}

• Keep a cheatsheet of common latex patterns that you use. I use mine to quickly grab sequences that I often use. Using vim, I can run commands like the following (usually in my command history, retrieved quickly)

:r!grep equation} latexCheatSheet.tex

:r!grep bmatrix} latexCheatSheet.tex

:r!grep aligned} latexCheatSheet.tex

• Use scripting to auto-number labels.

• If there are patterns that you find yourself typing, but don't feel that you want a permanent \newcommand for, use some temporary search and replace patterns, allowing you to type things more quickly, then run a script to convert stuff to actual latex. I find that perl -pi, fed with whatever ad-hoc regex list is appropriate at the time, works really well.

• Use a version control system, like git, to manage your sources. This is especially important if you use scripting tricks to alter your sources, so that you can return to previous versions if things screw up.

• Use \begin{dmath} ... \end{dmath} from the breqn package to leave formatting of long multi-part equations to latex, instead of screwing around with aligned, & and \\ markers. This helps lets you spend your time producing content and not wasting time trying to get formatting right.

• Learn and use regular expressions and an editor (and/or tools like perl) that supports them. Your head will hurt at first, but your editing productivity can be orders of magnitude better.

These methods work well enough that I can now usually write my class notes, which are heavy on mathematics, in latex in real time.

• Use \begin{dmath} ... \end{dmath} from the breqn package This does not always work. There are problems not resolved with this package. Please see tex.stackexchange.com/questions/119334/… for some issues. Nov 27, 2014 at 21:12
• @Nasser, yes it can be touchy (and some stuff has to be done differently when used), and I'd really like better error reporting when it is used, but I still find it worthwhile. Nov 27, 2014 at 21:59
• I like this statement: long sequences can be cut and pasted. May 15, 2021 at 2:03

Regarding time waste in switching between LaTeX code, recompiling, and viewing pdf files, there are LaTeX editors with an itegrated viewer, background compilation, and even with live preview for formulas, e.g. TeXstudio.

You'll probably have to try a few tools to find the one that suits you best. Here's a list of IDEs and their features.

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
– yo'
Nov 26, 2014 at 10:43

For computaions, I use mainly Wolfram Mathematica and LaTeX. For writing LaTeX source file I developed many macros in my favorite editor WinEdt. For example, typing \[ immediately transforms the input into

\begin{gather*}
*
\end{gather*}


and _ is automatically transformed into _{} with the cursor placed between the braces. Nothing to say that \al yields \alpha, etc. This greatly increases the production speed.

I prefer to work straight in latex for algebra and equation manipulation, but on paper for problems with more geometry and drawing.

In my opinion one of the biggest benefits of LaTeX is the ability to use really advanced text editing tools. I use Sublime Text 2 with LaTeXTools, which gives me most basic vim commands (just tapping yyp will duplicate the line, so I write out every step which helps catch errors)

Using LaTeXTools adds a whole layer on top of the multi cursors, autocomplete, vi, and other awesome tools in Sublime, with completions that really speed things up. for example, to type:

\begin{align*}
\frac{4}{5} = x\\
\frac{9}{5} = x\\
\end{align*}


My keystrokes would be

bal <tab> <tab> fra <tab> 4 <tab> 5 <tab> = x \\ <esc> yyp/4r9

It looks complex, but that's 25 keystrokes to make 65 characters across 4 lines, with proper indentation, and the efficiencies only get larger with larger equations.

It also helps with writing, long words like Supercalifragilisticexpialidocious would just be superc <tab> and it would fill in the rest for me as long as I have already typed it somewhere in the document.

It also gives me cmd b to compile and show the document in Skim.