The most common Mistakes in Latex
Since I often have to fix foreign Latex sources, I thought it might be a good idea to collect the most common errors in a page. With errors, I mean problems that make life harder for the Latex user than it should be. Avoiding these errors is a matter of organization, clearness and eases debugging. Most Latex users are surprised to here that my sources run without any warnings, with the output just counting page numbers [1][2][3]… If your code does not run like this, you are a candidate for reading this page.
1. Not formatting your Source
Latex does not take care of blanks or line breaks (besides empty lines). So users are tempted to write really awful chains of Latex commands, interwoven text, and formulas without break or beauty. The result is a mess, which is hard to debug and hides errors. Like a good programmer of a programming language, you should take care to write good and clean code, and use comments. Latex is often hard enough to understand anyway.
First of all, find a good editor, which knows how to wrap lines and reformat paragraphs, so that paragraphs of text look like paragraphs also in your code. The editor should also be able to use tabs, so that your display formulas can be tabbed to be clearly visible as display formulas. Here is a sample for such code.
Kro\'o \cite{kro} proved for \(1 < p \le \infty\), \(f \in C[-1,1]\) that if the
error function of best \(L^p\)-approximation has no zero in some subinterval
\((a,b) \subset [-1,1]\) for some subsequence \((n_j)_{j \in \NN}\), then
\[
\limsup_{j\to\infty} \frac{n_{j+1}}{n_j} > 1.
\]
This was an improvement of a weaker theorem by Kro\'o and Swetits in
\cite{kroswe}.
In \cite{blatt2}, this result was sharpened. Let \(1 \in C[-1,1]\) and
\((n_j)_{j \in \NN}\) a subsequence, such that
\[
\lim_{j \to \infty} \frac{n_{j+1}}{n_j} = 1.
\]
Then there exist \(n_j+2\) points in \([-1,1]\), where the error function
of the best \(L^p\)-approximation has alternating signs and the point
measures \(\tau_{n_j}\) associated with these points of alternation have
the equilibrium distribution on \([-1,1]\) as a weak limit point. An
analogous result for \(L^1\)-approximation was proved in \cite{blatt5}.
This text reads like almost like the output. For the indentation of the display formulas, I use true tab characters, which I replaced by blanks for this HTML output. If your editor uses a number of blanks for tabs, it makes it harder to edit the tabs. Configure the tab width in the editor, so that it is not too wide. Make sure, your editor automatically inserts the proper indentations in each new line, whenever you press return to insert a new line.
Note that I used \[...\] and \(…\) for the formulas. Both make it harder to do auto-replacements, and to find errors, since the beginning and the end of the formula is now obvious. The old $…$ hides this information. Moreover, \[...\] yields a nicer and more compact result than $$…$$. I admit, that $…$ is somewhat easier to recognize in the text. But a good editor has syntax highlighting for Latex and marks formulas in color. A good editor can auto-complete \( and \[, or has a keyboard macro for that.
The same good formatting style applies to multi-line formulas. Make sure to format them as clearly as possible. Here is an example
\begin{align*}
G(x,y)
&= \{ x+\l(y-x) : \text{$\l \in \RR$} \}
\\
&= \{ (x+b)+\l((y+b)-(x+b)) - b :
\text{$\l \in \RR$} \}
\\
&= G(x+b,y+b) - b.
\end{align*}
As you see, each line in the formula (using the align environment) gets a line in the source. If the line is too long, it is continued in a new more indented line. Do not worry about wasting space. You will praise yourself for that clearness later, if you have to find, replace, or fix anything.
2. Not Using the Text Formatting of Latex
Many Latex users come from other text systems. The older ones even come from the typewriter. Those users tend to underestimate the power of Latex and its text formatting. Another source of this error is the wish to have more control over the formatting, meeting the lack of knowledge on how to achieve this. Of course, I can only give a few hints here.
By default, Latex uses blocked paragraphs, which are separated by blank lines in the source code. The number of the blank lines does not matter. The space between paragraphs, and the indent of the next paragraph can be controlled with Latex variables. I use
\parskip=5pt plus 2pt minus 1pt \parindent=0pt
for this (officially you should use \setlength). Note the "glue" in the definition of parskip, which allows it to enlarge or shrink to some extend. This will prevent underful over overfull pages, and is one reason for a clean compilation and look. Latex takes very much effort to place the paragraphs properly on the the page, and you can support it with these settings. For math, you may prefer no indentation of the first line of each paragraph, as I do. The reason is that text paragraphs are usually very short.
Locally, you can disable the indentation with \noindent, by the way. I prefer this for items like "(1)..." to the itemize environment. It looks just as good, and the numbers stand out enough for my taste. I use itemize only for paragraphs of documents with laws etc.
Latex does also wonders with headings, so you should use them. If you do not want a number, use \section* etc. Of course, you can also define your own heading command. An example would be
\goodbreak
\noindent\begin{center}{\rm\large\bf My Heading}\end{center}
\bigskip
\nopagebreak
First paragraph \ldots
I very strongly recommend defining a macro for this (see below). For the start, you should stick with the predefined headers, which you will find in any good Latex book.
I never break lines by force using "\\". This is no good style, and results in a bad reading experience. Simply start a new paragraph. If you have a list of items, use the itemize or enumeration environment to display it, or a table. A set of broken lines simply looks ugly.
Also trust on Latex's ability to insert the proper spaces. In text mode, Latex will do the right thing after commands or full stops. Do not add extras there, even if your boss thinks, he knows better. However, you may sometimes want to prevent a space to be broken into two lines. You can do this with the tilde as in "Line~A".
3. Mixing Math with Text, Punctuations or Blanks
This is one of the most common errors, and it makes reading and fixing the source very difficult. The source of this error is incomplete knowledge of Latex commands.
In the following examples, I will use the \text command often. To be able to use ti, import the amsmath package with \usepackage{amsmath}. This package is useful for many other problems, and I will cover that in a separate section.
A frequent case of this error is to write "sin(x)" instead of "\sin(x)", which will yield an ugly slanted sin looking like the product of the variables s, i and n. If you have a multi-letter variable, by the way, you should use \text{\sl sin}. The same applies to \min, \max, \lim, \sup etc. If you have a new operator, you can use "\text{\rm Kernel}\,(\phi)". Note that small space after the Operator. If you make a macro for this (always a good idea), you can include that space in the macro. There is even a facility to properly define new operators in Latex, but I won't cover that here.
A math formula is a math formula, even if it contains text. Variables in math formulas are meant to appear in slanted. So it is not a good idea to use g$_1$ instead of $g_1$ (or even better \(g_1\) as mentioned above as good source formatting). If you really want a roman g, you can use \text{g} , or even \text{\rm g} to make sure that it is roman even in italic or slanted environments like theorems. In fact, you should write a macro like \grm, if you use that often (see below about macros).
The same applies to commas or other punctuation marks. You should write "Let \(V\), \(W\) be vector spaces in \(U\).", taking the comma and the full stop out of the formula. Note, that good math style also uses marks after display formulas as in the examples above. A common mistake is to use "..." instead of "\ldots" in formulas yielding an ugly result. Conversely, do not use "-" in text for long dashes, instead use "--" or "---". The "-" is only for words like "pre-build".
You can use math mode in \text. This is useful in for all statements and sets. E.g., I routinely use \text in the definition of sets as in the example above. Here is an example for "for all".
We have
\[
x > y \qquad \text{for all \(x \in A\)}.
\]
Note the \qquad which gives just the right kind of space between the formula and the text. In general, use spaces like \, sparsely. Most things are handled by Latex automatically. An exception are the product without the German \cdot dot, which sometimes (not always, not even most of the time) requires a \, space to look good. You can simply write (a+b)\pi without additional space. But \frac{a}{b}\,\pi might look better with the space.
Another case is the hyphenation. If Latex does not hyphenate your word or not as you like it, tell it how to hyphenate the word, as in "hy\-phe\-nate". This is necessary for German words containing umlaut letters. Do not hyphenate yourself with "-", since this will have to be fixed if your paragraph changes.
4. Not using the proper Packages
Some Latex users might not have heard of some packages, and others want to keep their code "clean". I have some inclinations for you, since I had to change source code due to changes in the packages. For a long time, I used plaintex for formatting, which never changed. But using Latex and its packages makes things so much easier.
An example is the inputenc package, which allows e.g. German text to be written in German letters. Import it with "\usepackage[latin1]{inputenc}". Suddenly you can write "mäßig", instead of "m\"a\ss ig". Also import the proper language package for your language. I use \import{ngerman} for German texts. This will give you access to proper hyphenation.
For math, a very important packages are amstex and amsfonts. The latter will give you access to the blackboard bold font, which contains the usual letters for real, complex, or integer numbers. E.g., use \mathbb{R} for the reals. Even better, create a macro \RR for this.
The amstex package contains a lot of useful things to format math. One example is the \text command, which inserts text into formulas. I wrote in length about this in the previous section. Other examples are environments for multi-line formulas. The easiest one is align (or align* for use without a tag). In the first section, you can find an example for this. However, there is also the simple multline (or multline*) environment, which places the first line to the left, and the last line to the right, and does not use alignment tabs &. A very useful environment is gather, which places centered formulas one above the next.
The cumbersome, powerful array environment of Latex has an easier to use form pmatrix (or matrix without brackets) in amstex. Here is an example, defining a matrix.
\[
A_a :=
\begin{pmatrix}
a & 1 \\
1 & a
\end{pmatrix}
\]
There numerous packages for Latex. E.g., the beamer packages lets you create nice presentations with Latex. It is to be used with pdflatex, however.
... to be continued
Dear Prof. Grothmann. I have only recently become interested in LaTex and your Euler Math Toolbox. I wish to ask if LaTex can be used as input to EMT i.e. are the two applications integrated?
I will begin an MSc engineering project later this year.
Regards
Roger Gregson
No, sorry, it can’t. Probably it would not be useful anyway. Latex is more output (print) oriented than mathematically, or numerically motivated. E.g., the numerical integration in Euler looks like integrate(&sin(x),-1,2). While this might be written as \int_{-1}^2, this is no help at all for the user, since it is equally bad to type. Moreover, there are more than just one integration method in Euler. There are also more settings like the number of subintervals, or the accuracy.
There is Maxima interface producing output for Latex. There is even a GUI that uses Latex to display the results. I think, the 2D output of Maxima is good enough. And for numerical purposes the Latex output is no help.