8

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?

7
  • 2
    Are you using a dedicated TeX editor?
    – raphink
    Sep 3, 2011 at 8:34
  • 10
    And you really think that clicking buttons or choosing symbols from a menu is faster then just typing them on the keyboard? Sep 3, 2011 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, 2011 at 9:35
  • 2
    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, 2011 at 13:56
  • 1
    Math Type is paid-for software...
    – Werner
    Feb 10, 2017 at 22:20

5 Answers 5

31

As with learning any spoken language, getting the hang of expressing your math thoughts in TeX and LaTeX takes some time, and it 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 more than 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 user guide of amsmath package shows how to use many great commands for typesetting equations and for entering matrices, to list just two examples of math-writing.

  • Use a text editor that provides various syntax highlighting methods and highlights matching parentheses, brackets, and curly braces. If the editor gives you pull-down menus to choose and click math terms, all the better; however, you'll likely find yourself using this particular piece of support less and less.

  • After you've entered a few formulas, take a 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 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 it 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:

      1. they will save you a lot of typing over time and

      2. 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. This is sometimes (often?) displayed as |A|. Now, some people like this formatting choice, 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 give 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 (named, say, mymacros.sty), and store this file somewhere in the LOCALTEXMF tree. That way, you can load the style file from your documents with the command \usepackage{mymacros}, and you'll always have easy access to your macros. And, if you ever want to redefine some of the macros, 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 among LaTeX-ers.)

Happy TeXing!

19
  • 3
    excellent summary. however, i'd warn against your suggestion to \let\det\relax and then \newcommand{...}; \renewcommand will be easier for some poor production editor to identify when a file submitted to a journal happens to redefine one of their "basic" set of commands, and throws a confusing error. Sep 3, 2011 at 15:05
  • 2
    Actually, for that example you'd want to redefine \det in all cases since it would be hard to redefine \det so that \det A produced |A|. One solution would be: \let\origdet=\det \renewcommand{\det}[1]{\origdet(#1)}. Then you could do \renewcommand{\det}[1]{\left\lvert #1\right\rvert} if required. Sep 3, 2011 at 16:50
  • 2
    (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.) Sep 3, 2011 at 16:51
  • 1
    @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. Sep 3, 2011 at 19:19
  • 1
    @Mico: you should also add a \mathopen{} between \origdet and \left to avoid a spurious space: \renewcommand{\det}[1]{\origdet\mathopen{}\left(#1\right)}. Sep 3, 2011 at 21:18
12

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.

6

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.

4

I found the physics package quite helpful in writing maths code. The package though primarily making life simpler for physicists, nonetheless can be useful for general mathematical writing as well.

\qty{}

\abs{} for absolute values

\norm{} for norm of the values

plus commutators and poisson brackets.

For me, the part where physics package really shines is handling of vector notation, derivatives, braket notations and matrices.

For example \vb{A} will produce an upright bold vector A \vb*{A} will produce a slant bold vector.

\grad \div and \curl and \laplacian are predefined

enter image description here

Also it has a neat command for text within the equation with space around it: \qq{text} with white space around it, it makes writing text in equations much easier. Also there are several predefined commonly used phrases in equations such as

\qif,\qthen, \qelse, \qotherwise, \qunless, \qgiven, \qusing, \qassume, \qsince, \qlet, \qfor, \qall, \qeven, \qodd, \qinteger, \qand, \qor, \qas, \qin

enter image description here

Writing derivatives is much simplified:

\dd x will create dx with upright d and math mode x, this provides easy way to write differentials.

Similarly for derivative \dv{x} will produce d/dx with upright d and math x.

\dv[n]{f}{x} will produce d^n f/ dx^n

\pdv{x} will produce partial derivatives and so on.

enter image description here

\braket{a}{b} will produce ⟨a|b⟩.

enter image description here enter image description here

Similarly there are quite a few shortcuts for martices:

matrices

Hope this helps!

1

I found a way to type LaTeX insanely fast in any text editor (included the math.stackexchange site) under a Windows operating system (unfortunately I dont find a way to do the same in Linux distributions). It rely on a free software named autohotkey: this is a software that give you the possibility to write strong custom scripts to simplify repetitive actions.

What I did was just define a list of hotstrings: a hotstring is a typed string that is replaced immediately by another custom string, basically a hotstring is something like

::str1::str2

This means that the string str1 will be immediately replaced by the string str2 after you type it, therefore you can abbreviate the typing of any TeX command or macro to just two or three strokes.

As an example there is the actual script that I use to type LaTeX (it is carefully designed to enhance immensely the typing of LaTeX but it is designed to use with an spanish keyboard distribution, however reading the script you can adapt it easily to your preferences).

1
  • You wrote about autohotkey: "this is a software that give you the possibility to write strong custom scripts to simplify repetitive actions". It would be very helpful if you showed how this claim addresses the OP's issue, which was about math typesetting.
    – Mico
    Mar 2, 2020 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.