The Artwork of LaTeX: Widespread Errors, and Recommendation for Typesetting Lovely, Pleasant Proofs
When was the primary time you had to make use of LaTeX?
If you’re like most individuals, it was in all probability immediately pressured upon you throughout
your first math or CS class the place you needed to begin writing proofs, with minimal
steering on the best way to get began aside from one thing alongside the strains of “hey,
try this hyperlink on the best way to get issues setup, and listed below are some fundamental
instructions, now go wild!”.
Sadly, this meant that whereas many individuals have good operational data
of LaTeX and may get the job executed, there are nonetheless many small errors and
greatest practices which aren’t adopted, which aren’t corrected by TAs
as they’re both not extreme sufficient to warrant a observe, or even perhaps the TAs themselves
usually are not conscious of them.
On this publish, we cowl some widespread errors which are made by LaTeX
practitioners (even in closely cited papers), and the best way to tackle them. This
publish assumes that the reader has some working data of LaTeX.
Typesetting as a Type of Artwork
It is very important get into the best mindset everytime you typeset a
doc. You aren’t merely “writing” a doc — you’re crafting a piece
of artwork that mixes each the precision and creativity of your logical
considering, in addition to the magnificence of a superbly typeset writing. The quantity
of consideration and care you place into the presentation is indicative of the quantity
of thought you place into the content material. Due to this fact, having good fashion shouldn’t be
solely pleasant and aesthetically pleasing to learn, however it additionally serves to determine
your ethos and character. One can inform that somebody places a number of effort into their
work and takes nice pleasure in them once they concentrate even to the smallest of
particulars.
Moreover, adopting good practices additionally helps to keep away from you making
typographical errors in your proof, equivalent to lacking parenthesis or flawed
positioning. This might typically result in cascading errors which are very annoying
to repair once you uncover them afterward. There are methods to copy the strict
typechecking of statically typed languages to make sure that errors in your
expressions may be caught at compile-time.
Widespread Errors, and How To Repair Them
Within the following part, we check out widespread errors that folks make,
and the way they are often averted or mounted. We cowl fashion errors first, for the reason that
concepts behind them are extra normal. All of the screenshotted examples come from
peer-reviewed papers which have been printed to prime conferences, so they’re
undoubtedly quite common errors and also you shouldn’t really feel dangerous for making them.
The essential factor is that you’re conscious of them now in order that your fashion
will steadily enhance over time.
Model Errors
We check out fashion errors, which impairs reader understanding,
and makes it simple to commit different types of errors.
Paired Delimiters
Parenthesis, brackets, and pipes are examples of delimiters which are used to mark the beginning
and finish of method expressions. As they arrive in pairs, a standard mistake is by chance
leaving out the closing delimiter, particularly for nested expressions. Even in case you don’t
neglect to take action, there may be the difficulty of incorrect sizing.
For example, think about
the next manner of expressing the Topologist’s sine curve, which is an instance of a topology
that’s linked however not path linked:
which is rendered as follows:
[T = {(x, sin frac{1}{x} ) : x in (0, 1] } cup { ( 0, 0 ) }]The issue right here is that the curly braces have the flawed
dimension, as they need to be massive sufficient to cowl the (sin frac{1}{x}) expression vertically.
The flawed manner of resolving this might be to make use of delimiter dimension modifiers, i.e
bigl, Bigl, biggl
paired with bigr, Bigr, biggr
and the like. This
is tedious and error-prone, since it can even fortunately allow you to match delimiters
with totally different sizes. Certainly, I got here throughout the next method in a
paper just lately, the place the outer proper sq. brackets was lacking and the left one
had the flawed dimension:
The proper manner to do that can be to make use of paired delimiters,
which can routinely regulate its dimension primarily based on
its contents, and routinely end in a compile error if the matching
proper delimiter shouldn’t be included, or nested on the flawed degree.
A few of them are given under:
Uncooked LaTeX | Rendered |
---|---|
left( frac{1}{x} proper) |
(left( frac{1}{x} proper)) |
left[ frac{1}{x} right] |
(left[ frac{1}{x} right]) |
left{ frac{1}{x} proper} |
(left{ frac{1}{x} proper}) |
leftlvert frac{1}{x} rightlvert |
(leftlvert frac{1}{x} rightrvert) |
leftlceil frac{1}{x} rightrceil |
(leftlceil frac{1}{x} rightrceil) |
In reality, to make issues even less complicated and extra readable, you possibly can declare paired delimiters
to be used primarily based on the mathtools
package deal, with the next instructions on account of
Ryan O’Donnell:
Then now you can use the customized delimiters as follows, taking observe that you simply want the *
for it to auto-resize:
which provides
[T = left{ left( x, sin frac{1}{x} right) : x in (0, 1] proper} cup left{ left( 0, 0 proper) proper} ]The largest draw back of utilizing customized paired delimiters is having to recollect to
add the *
, in any other case, the delimiters won’t auto-resize. That is fairly unlucky
because it nonetheless makes it error-prone. There’s a proposed
solution
floating round on StackExchange that depends on a customized command that makes auto-resizing
the default, however it’s nonetheless a far cry from a parsimonious resolution.
Macros for Saving Time and Stopping Errors
Macros may be outlined utilizing the newcommand
command.
The fundamental syntax is newcommand{command_name}{command_definition}
.
For example, it’d get tiring to all the time sort boldsymbol{A}
to confer with a matrix (boldsymbol{A}), so you should utilize the next macro:
Macros may take arguments to be substituted throughout the definition.
That is executed by including a [n]
argument after your command identify,
the place n
is the variety of arguments that it ought to take. You may then
reference the positional arguments utilizing #1, #2,
and so forth.
Right here, we create a dotprod
macro that takes two arguments:
Macros are extremely useful as they assist to avoid wasting time, and be sure that our
notation is constant. Nevertheless, they will also be used to assist to catch
errors when typesetting grammatically structured issues.
For example, when expressing sorts and phrases in programming language principle,
there may be typically a number of nested syntactical construction, which might make it simple
to make errors. Think about the next proof:
The main points are unimportant, however it’s clear that it’s simple to overlook a letter right here
or a time period there within the proof, given how cumbersome the notation is.
To keep away from this, I used the next macros, on account of Robert Harper:
And the supply for the proof appears like the next:
It’s undoubtedly nonetheless not essentially the most nice factor to learn, however not less than now you
will probably be much less more likely to miss an argument or neglect to shut a parenthesis.
Non-breaking strains
Expressions that are logically a single unit ought to keep on the identical line, as an alternative
of being break up aside mid-sentence. Cue the next dangerous instance from one other paper:
Within the space marked in crimson, we had the expression that was defining (tau^i)
get reduce in half, which could be very jarring visually and interrupts the reader’s
prepare of thought.
To make sure that expressions don’t get break up, merely wrap it round in curly braces.
For example,
can be wrapped by {
and }
on each side and turn into
So if we render the next snippet, which might in any other case have expressions
break up in half with out the wrapped curly braces:
we get the next constructive end result the place there may be extra whitespace between
the justified textual content on the primary line, to compensate for the expression assigning (tau)
to remain on the identical line:
Non-breaking house with ~
When referencing figures and equations, you need the textual content and quantity (i.e Determine 10) to finish up on the identical line.
It is a unfavourable instance, the place the area underlined in crimson exhibits the way it was break up up:
To treatment this, add a ~
after Determine
, which LaTeX interprets as a non-breaking house:
This could be sure that “Determine 2” all the time seems collectively.
Expressions Ought to Be Punctuated Like Sentences
Your doc is supposed to be learn, and it ought to observe the foundations and buildings
of English (or whichever language you’re writing in). Which means
mathematical expressions must also be punctuated appropriately, which
permits it to movement extra naturally and make it simpler for the reader to observe.
Think about the next instance that doesn’t use punctuation:
Within the area highlighted in crimson, the expressions don’t carry any punctuation in any respect,
and by the top of the final equation (Equation 15), I’m nearly out of breath making an attempt
to course of the entire info. As well as, it doesn’t finish in a full cease, which
doesn’t give me an affordance to take a break mentally till the following paragraph.
As a substitute, commas ought to be added after every expression the place the expression doesn’t terminate,
and the ultimate equation ought to be ended by a full cease. Right here is an efficient instance of punctuation
that helps to information the reader alongside the writer’s prepare of thought:
Right here is one other good instance of how utilizing commas for the equations
enable the textual content to movement naturally, the place it takes the type of
“analogously, observe that we now have [foo] and [bar], the place the inequality…”:
This even extends to once you pack a number of equations on a single line, which
is widespread when you’re making an attempt to suit the web page restrict for convention submissions:
The proof
atmosphere
The proof
atmosphere from the amsthm
package deal is nice for signposting to your readers
the place a proof begins and ends. For example, think about how it’s used within the following instance:
It will helpfully spotlight the beginning of your argument with “Proof”, and
terminate it with a sq. that symbolizes QED.
Terminate Proofs with Express qedhere
Think about the identical instance as beforehand, however now you by chance added a further
newline earlier than the closing finish{proof}
, which occurs fairly typically:
This leads to the above state of affairs, the place the QED image now seems on the following line by itself,
which throws the whole textual content off-balance visually. To keep away from such issues taking place,
all the time embrace an specific qedhere
marker on the finish of your proof, which might trigger it
to all the time seem on the road that it seems after:
We’d then get the identical end result as earlier than initially, after we didn’t have the additional newline.
Spacing
Spacing issues loads in readability, because it helps to separate logical parts.
For example, the next instance fails so as to add spacing earlier than the differential
of the variable (dz):
This might sound innocuous, however think about the next instance that makes the difficulty extra specific:
[P(X) = int xyz dx]Now we will actually see that the portions are operating into one another, and it
turns into laborious to interpret. As a substitute, we will add math-mode spacing, summarized in
the next desk:
Spacing Expression | Sort |
---|---|
; |
Thick house |
: |
Medium house |
, |
Skinny house |
So our new expression now appears like:
[P(X) = int xyz , dx]which is way more readable.
align*
Atmosphere for Multiline Equations
When utilizing the align*
atmosphere, make it possible for your ampersands &
seem earlier than the
image that you’re aligning towards. This ensures that you simply get the proper spacing.
For example, the next is flawed, the place the &
seems after the =
:
nabla_{mu} (mathbb{E}_{xsim q_{mu}} f(x)) = & nabla_{mu} int_x f(x) q_{mu}(x) dx
= & int_x f(x) (nabla_{mu} log q_{mu}(x)) q_{mu}(x) dx
= & mathbb{E}_{x sim q_{mu}} left(f(x) nabla_{mu} log q_{mu}(x)right)
end{align*}]
It’s because there may be too little spacing after the =
signal on every line, which feels very cramped.
Placing the &
earlier than the =
is appropriate:
nabla_{mu} (mathbb{E}_{xsim q_{mu}} f(x)) & = nabla_{mu} int_x f(x) q_{mu}(x) dx
& = int_x f(x) (nabla_{mu} log q_{mu}(x)) q_{mu}(x) dx
& = mathbb{E}_{x sim q_{mu}} left(f(x) nabla_{mu} log q_{mu}(x)right)
end{align*}]
The spacing is way more comfy now.
Command Errors
We now take a look at some errors that come up from utilizing the flawed instructions.
Math Operators
As a substitute of sin (x)
((sin(x))) or log (x)
((log (x))), use sin (x)
((sin (x)))
and log (x)
((log (x))). The thought extends to many different widespread math features.
These are math operators that may de-italicize the instructions
and in addition deal with the suitable math-mode spacing between characters:
O(n log n) |
(O(n log n)) |
O(n log n) |
(O(n log n)) |
Many instances there’s a math operator that you might want to use repeatedly, however which does
not come out of the field. You may outline customized math operators with
the DeclareMathOperator
command. For example, listed below are some generally utilized in chance:
Then you should utilize it as follows:
[Pr left[ X geq a right] leq frac{Ex[X]}{a}]Double quotes
That is extra of a rookie mistake because it’s visually very apparent one thing is
flawed. Double quotes don’t work the best way you’ll anticipate:
As a substitute, encompass them in double backticks and single quotes, which is
alleged to be paying homage to the directional strokes of an precise double quote.
This permits it to know which facet to orient the ticks:
Sadly I needed to display this with a screenshot since MathJax solely
performs math-mode typesetting, however that is an occasion of text-mode typesetting.
Epsilons
It is a widespread mistake on account of laziness. Many instances, folks use epsilon
((epsilon))
once they actually meant to jot down varepsilon
((varepsilon)). For example, in evaluation
that is normally the case, and due to this fact writing epsilon
leads to a really uncomfortable
learn:
Utilizing varepsilon
makes the reader really feel way more at peace:
Equally, folks are likely to get lazy and blend up phi, Phi, varphi
((phi, Phi, varphi)),
since they’re “about the identical”. Particulars matter!
Units: mathbbm
As a substitute Of mathbb
For units like (mathbb{N}), it is best to use mathbbm{N}
(from bbm
package deal) as an alternative of mathbb{N}
(from amssymb
). See the
distinction in how the rendering of the set of pure numbers
(mathbb{N}) differs, utilizing the identical instance because the earlier part:
mathbbm
causes the symbols to be bolded, which is what you need.
Dots
...
and dots
are totally different. See the distinction:
When utilizing “…”, the spacing between every dot, and between the ultimate dot
and the comma character is flawed. All the time use “dots”.
Summation and Product
When writing summation or merchandise of phrases, use sum
and prod
as an alternative of Sigma
and Pi
. This helps to deal with the
relative positioning of the bounds correctly, and is way more idiomatic to learn
from the uncooked script:
Uncooked LaTeX | Rendered |
---|---|
Sigma_{i=1}^n X_i |
(Sigma_{i=1}^n X_i) |
sum_{i=1}^n X_i |
(sum_{i=1}^n X_i) |
Pi_{i=1}^n X_i |
(Pi_{i=1}^n X_i) |
prod_{i=1}^n X_i |
(prod_{i=1}^n X_i) |
Multiplication
To indicate multiplication, use cdot
or instances
as an alternative of *
. See the distinction under
within the equation:
Mid
For set builder notation or conditional chance, use mid
as an alternative of the pipe |
.
This helps to deal with the spacing between the phrases correctly:
Uncooked LaTeX | Rendered |
---|---|
p(mathbf{z}, mathbf{x}) = p(mathbf{z}) p(mathbf{z} | mathbf{z}) |
(p(mathbf{z}, mathbf{x}) = p(mathbf{z}) p(mathbf{z} | mathbf{z})) |
p(mathbf{z}, mathbf{x}) = p(mathbf{z}) p(mathbf{z} mid mathbf{z}) |
(p(mathbf{z}, mathbf{x}) = p(mathbf{z}) p(mathbf{z} mid mathbf{z})) |
Angle Brackets
When writing vectors, use the langle
and rangle
as an alternative of the keyboard angle brackets:
Uncooked LaTeX | Rendered |
---|---|
<u, v> |
(<u, v>) |
langle u, v rangle |
(langle u, v rangle) |
Labels
Use label
to label your figures, equations, tables, and so forth, and reference them utilizing ref
, as an alternative of hardcoding the quantity.
For example, label{fig:myfig}
and ref{fig:myfig}
.
Together with the kind of the article within the tag helps to maintain monitor
of what it’s and ensures that you’re referencing it appropriately, i.e
ensuring you write Determine ref{fig:myfig}
as an alternative of by chance saying
one thing like Desk ref{fig:myfig}
.
Conclusion
That was loads, and I hope it has been a useful learn!
I’ll proceed updating this publish sooner or later as and after I really feel like
there are different essential issues which ought to be famous which I missed.
I want to thank my good friend Zack Lee for reviewing this
article and for offering invaluable recommendations.
I might additionally like to precise my because of Ryan
O’Donnell, and my 15-751 A Theorist’s Toolkit
TAs Tim Hsieh and Emre
Yolcu for serving to me understand a number of the
style-related LaTeX points talked about on this publish, a lot of which I made
personally previously.