|
|
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!
|
|
|
answered Sep 3 '11 at 13:13
|
|