20

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?

lockstep
  • 250,273
Tim
  • 5,763
  • 1
    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. – T. Verron Nov 20 '14 at 16:02
  • 4
    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 – T. Verron Nov 20 '14 at 16:04
  • What "mathematical software"? – Tim Nov 20 '14 at 16:07
  • @Tim: computer algebra systems like Mathematica, Sage, or even stuff like IPython, Matlab, etc. – Aditya Nov 20 '14 at 16:17
  • @Verron: How does some math software "make things even more complicated"? I would like to make things more convenient and productive. – Tim Nov 20 '14 at 16:43
  • Well, it gives you one more possibility for making things more convenient and productive. So instead of the 3 choices in your question, you have 6 (with or without a CAS). And then, on top of that, you will have the choice of the CAS, and maybe the "best" choice will be to use several of them. The end result will hopefully be a more convenient and productive workflow, but the road to reach that is more complicated with every tool you need to consider. – T. Verron Nov 20 '14 at 16:49
  • @ the reviewers: please have a look to the existing answer before voting to close. – T. Verron Nov 20 '14 at 17:03
  • 1
    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 '14 at 10:54
  • I solve stuff in LaTeX, since i never get in right on paper... – Per Alexandersson Dec 01 '14 at 21:45

5 Answers5

15

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.

Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195
  • "[I] adhere to it closely in \frac-tions" Do you really know of people who don't? – T. Verron Nov 20 '14 at 16:57
  • @T.Verron: Yes. And people who edit journals will probably tell of many more LaTeX sins. – Matthew Leingang Nov 20 '14 at 16:58
  • 2
    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. – T. Verron Nov 20 '14 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. – Matthew Leingang Nov 20 '14 at 17:05
  • Using snippets from the editor, macros, and apps like TextExpander, you can definitely end up writing faster on the computer than in paper. Still, I think one thinks faster on paper, too many distractions in the computer (even if you are not doing anything but writing in your editor). – Manuel Nov 20 '14 at 20:18
  • @Manuel: re "definitely end up writing faster" with macros and text expansion I will believe it when I see it. I am pretty sure I can scribble a faster that you can type \phi. – Matthew Leingang Nov 20 '14 at 20:39
  • @MatthewLeingang I would type something like f and then press TAB. In any case, why would you write φ alone? The cool thing about text expansion is that you can fasten the input on “large structures”. If you write a 100 pages document, the first ten would be “training”, where you learn what constructions do you need and use. The remaining 90 would be pretty fast, IMHO. – Manuel Nov 20 '14 at 20:50
  • 3
    @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...) – mbork Nov 20 '14 at 21:50
  • @mbork, I was about to write same. Indeed, \frac12 == \frac1 2 == \frac 1 2 == \frac{1}2 == \frac 1{2}. It can save a lot of code space. In some context \over can make the code more readable, (although some people don't like it). – alfC Nov 28 '14 at 08:50
  • @alfC: there is no point in optimizing code space if it makes the code harder to read or edit. If you have five ways to write the same fraction, what if you have to search for one? Or change them all? For that reason I find it more efficient to key it the same way each time. As for \over, it's been taboo since the dawn of LaTeX. – Matthew Leingang Nov 28 '14 at 12:21
  • @MatthewLeingang, sure, consistency is important. I am saying that {} can be legally omitted in many cases. frac is an example of this. In many cases both {}{} in \frac can be omitted making the code shorter. I find frac commands to be responsible for increasing a lot the lenght of the code. And in this way it can be shortened quite a bit. Specially simple fractions involving few symbols and integer (which are common normalization factors). E.g. $\frac{\sqrt\pi}2$ vs $\frac{\sqrt{\pi}}{2}$ or \frac\pi2 vs. \frac{\pi}{2}. – alfC Nov 28 '14 at 14:12
  • @alfC: I am aware that braces are optional in one-token parameters. In my answer I am advocating for including them anyway to make the code more readable, searchable, etc. And I don't think that code length is something that needs to be prioritized over code readability. When documents become long and you need to match a missing } it helps to have all the braces out there. – Matthew Leingang Nov 28 '14 at 14:25
  • I hate to bring in a reference from outside the domain, but the Zen of Python comes to mind: namely Explicit is better than implicit, and There should be one—and preferably only one—obvious way to do it. – Matthew Leingang Nov 28 '14 at 14:27
  • @MatthewLeingang, with that criterion \int_0 should be ` – alfC Nov 28 '14 at 22:25
6

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.

Andrew Swann
  • 95,762
Peeter Joot
  • 3,025
  • 2
  • 25
  • 35
  • Use \begin{dmath} ... \end{dmath} from the breqn package This does not always work. There are problems not resolved with this package. Please see http://tex.stackexchange.com/questions/119334/why-does-adding-usepackagebreqn-even-if-not-used-cause-latex-compile-errors for some issues. – Nasser Nov 27 '14 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. – Peeter Joot Nov 27 '14 at 21:59
  • I like this statement: long sequences can be cut and pasted. – Ziqi Fan May 15 '21 at 02:03
3

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.

user24582
  • 191
2

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.

2

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.

Ryan
  • 2,914