# Slow math typing

I have been using LaTeX for quite some time, but I find the math writing to be a bit frustrating. It seems to take me a relatively long time to code-write long math expressions, and sometimes it's hard to see where { start and end. I am interested in writing as fast as possible.

Is code-typing each symbol really the fastest way? Is there any good program (in the spirit of Word's MathType) that enables producing math expressions by button clicking, that you recommend?

-
Are you using a dedicated TeX editor? –  ℝaphink Sep 3 '11 at 8:34
And you really think that clicking buttons or choosing symbols from a menu is faster then just typing them on the keyboard? –  Thorsten Donig Sep 3 '11 at 8:47
I think it's faster. But maybe I'm not trained enough. Plus visual viewing of the formula is helpful I think, alongside the code itself. help visualizing complex formulae –  Andro Sep 3 '11 at 9:35
vim with vim latex-suite has increased my speed significantly. vim has a learning curve, but it's worth learning if only for LaTeX (it can be used to edit any plain text) –  cmhughes Sep 3 '11 at 13:56
@PineApple: I've converted your answer to a comment. Please register with the site, and you'll then automatically be able to comment on your own questions. –  Joseph Wright Sep 4 '11 at 7:16

I find it quite natural to code math in LaTeX. Having said that, part of this is because I define macros to make it faster. Without being able to express myself with the following macros,

• \x to produce \times ( × ) and \ox to produce \otimes ( ⊗ )
• \C to produce \mathbb C ( ℂ ) and \Z to produce \mathbb Z ( ℤ )
• M\trans to produce M^\top ( M ) and M\herm to produce M^\dagger ( M )
• \ens{1,2,3} to produce \left\{ 1, 2, 3 \right\} ( {1,2,3} )
• \norm{A} to produce \left\| A \right\| ( || A || )
• \ket{x} to produce \left| x \right\rangle ( |x⟩ )

and their like, I would take a lot longer to express myself mathematically in LaTeX. Defining macros such as this will make it more difficult to collaborate on a single file, however, unless you and your co-authors agree on the same set of macros.

-

As with learning any spoken language, getting the hang of expressing your math thoughts in TeX and LaTeX takes some time and requires quite a bit of practice to become truly proficient. And, as with learning any spoken language, the learning curve does flatten out considerably after a while, and writing math in LaTeX will seem to have become second nature. (Aside: I've been using TeX and LaTeX for nearly 20 years.)

That said, I've found that the following "tricks" do help ease the learning process; and they tend to save you a lot of keystrokes in the process:

• Do study the manuals of the amsmath package; they're chock-full of good examples of interesting (to look at!) formulas. Really. The amsmath package provides lots of great commands for typesetting equations and for entering matrices, to list just two examples.
• Use a text editor that provides various syntax highlighting methods and highlights matching parentheses, brackets, and curly braces. If it gives you little pull-down menus to choose and click math terms, all the better, but you'll likely find yourself using that particular piece of support less and less.
• After you've entered a few formulas, look at the code and decide if there are any repeated stretches of code, such as second partials, integrals, and numerators and/or denominators of fractions. If these elements occur reasonably frequently, it's worth defining them as little macros in your document's preamble and invoking them as needed in the main text. For example, if you have a lot of second partial derivatives, you may want to define a macro like

\newcommand{\secondp}[3]{\ensuremath{\displaystyle%
\frac{\partial^{2}\!{#1}}{\partial{#2}\,\partial{#3}}}}


You'd invoke this macro as follows: \secondp{f(x,y)}{x}{y} or, if each argument consists of a single character, as \secondp f x y. (Putting braces around the f, x, and y won't hurt, of course, and would likely make the code more readable as well.) What if you have a lot of own second partial expressions? Piece of cake -- just define another macro that takes two inputs:

\newcommand{\ownsp}[2]{\ensuremath{\displaystyle%
\frac{\partial^{2}\!{#1}}{\partial{#2}^2}}}

• Two side benefits of using macros in this way are: (i) they will save you a lot of typing over time and (ii) they will eliminate a major source of typos (and hence frustration arising from having to track down typos!). In the process of using macros frequently, you'll find that it becomes entirely natural to scrutinize formulas dispassionately, like an architectural critic who looks at the edifice as a whole, rather than like a laborer whose sole concern is how to place the next brick, or gargoyle, or whatever! By looking at the "big picture," so to say, you'll develop a facility to spot flaws in your edifice that you wouldn't be able to discover otherwise. E.g., is some part of the integrand "missing"? Should that be a minus sign instead of a plus sign?

• In addition, make a habit of scrutinizing your code for ways to separate, as much as possible, the content of your mathematical expressions from its appearance. What do I mean by this? A main feature of the entire structural philosophy of LaTeX is to separate content from appearance; while appearance depends (obviously!) on the content, it is also affected by decisions about how the content is formatted. While you may be comfortable with your formatting decisions, your thesis adviser, a journal editor, or co-authors may desire different styles for formatting various terms. If you've hard-coded (using lower-level LaTeX/TeX commands) all of the formatting commands, you're going to have to spend a lot of time re-formatting the content of your work to meet these new requirements. Take, for instance, the case of the cardinality of some set A, sometimes (often?) displayed as |A|. Now, some people like this formatting style, but others prefer ||A|| (double vertical bars), or whatever. If you've defined a macro \card as follows: \newcommand{\card}[1]{\ensuremath\left|#1\right|} (implementing the former style) and have been using it consistently, your extra work should somebody demand a different style will be minimal. A side benefit of using the macro \card is that it emphasizes the logic of your code rather than the appearance -- never a bad thing, right?

• To take a different example: if you have lots of determinants of matrices, you're probably aware that they are required to be displayed as |A| in some journals but as [A] or det(A) in others, and in yet different styles in further journals. In order not to have to reformat all of your input to meet the formatting requirements of a particular journal, it's best to use a macro named \det each time your enter the determinant of a matrix. Actually, the macro \det is already defined, as a "math operator" that sets the letters "det" in upright (not italicized} text mode. If you find that you'd really prefer to have determinants typeset as det(A) -- with the matrix being the argument of the \det command -- or as |A| instead of the default det A, you could redefine the \det macro, say as follows:

\let\origdet\det
%% You should comment out one of the two next renewcommands
\renewcommand{\det}[1]{\origdet\mathopen{}\left(#1\right)}   % to get "det(A)"
\renewcommand{\det}[1]{\left\lvert#1\right\rvert} % to get "|A|"

• Finally, I strongly recommend that you collect all of your macros in a so-called LaTeX style file (e.g., as mymacros.sty), store this file somewhere in the LOCALTEXMF tree, and load this style file from your document with the command \usepackage{mymacros}. That way, you'll always have easy access to your macros, and if you ever want to redefine them, you'll only have to do so once. Another change you might want to make to your macros is (if you haven't already done so from the very beginning) is to add copious comments as to what they're supposed to achieve. (Of course, providing copious comments is considered a good programming habit everywhere, not just amoung LaTeX-ers.)

Happy TeXing!

-
(By the way, you shouldn't let worrying about comments prevent you from editing your answer to make it better. You can always say, "(Thanks to Barbara Beeton for pointing this out in the comments)". Then it's clear that Barbara's comment refers to an earlier version and you've corrected your answer accordingly. Indeed, I'd encourage you to do this.) –  Loop Space Sep 3 '11 at 16:51
@Mico: you're also missing a pair of braces after your two \ensuremath. Spacing-wise, it's a bit dangerous to put a \! as one may want to use \secondp{\mathbf{H}}{x}{y} and then the 2 and the H telescope. Also, normally, you don't put a thin space before a \partial, as it serves no purpose. –  Philippe Goutet Sep 3 '11 at 19:19
@Mico: you should also add a \mathopen{} between \origdet and \left to avoid a spurious space: \renewcommand{\det}[1]{\origdet\mathopen{}\left(#1\right)}. –  Philippe Goutet Sep 3 '11 at 21:18

The vim-latex package for vim and auctex for emacs have shortcuts like a expands to \alpha, * expands to \times, etc. These shortcuts greatly speed up math typesetting. When using the luatex engine (either lualatex or context), I change these shortcuts so that a produces α` and so on. This makes it much easier to edit math expressions later on.

-