Now Reading
The Artwork of LaTeX: Widespread Errors, and Recommendation for Typesetting Lovely, Pleasant Proofs

The Artwork of LaTeX: Widespread Errors, and Recommendation for Typesetting Lovely, Pleasant Proofs

2023-01-08 08:22:30

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:

T = { ( x, sin frac{1}{x} ) : x in (0, 1] } cup { ( 0, 0 ) }

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:


What occurs when you do not use paired delimiters

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:

% Ensure you embrace usepackage{mathtools}
DeclarePairedDelimiterparens{lparen}{rparen}
DeclarePairedDelimiterabs{lvert}{rvert}
DeclarePairedDelimiternorm{lVert}{rVert}
DeclarePairedDelimiterfloor{lfloor}{rfloor}
DeclarePairedDelimiterceil{lceil}{rceil}
DeclarePairedDelimiterbraces{lbrace}{rbrace}
DeclarePairedDelimiterbracks{lbrack}{rbrack}
DeclarePairedDelimiterangles{langle}{rangle}

Then now you can use the customized delimiters as follows, taking observe that you simply want the *
for it to auto-resize:

T = braces*{ parens*{ x, sin frac{1}{x} } : x in (0, 1] } cup braces*{ parens*{ 0, 0 }}

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:

% Macro
newcommand{bA}{boldsymbol{A}}

$$min_x lvert bA x - b rvert_2^2$$
[min_x leftlvert boldsymbol{A} x – b rightrvert_2^2]

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
newcommand{dotprod}[2]{langle #1, #2 rangle}
newcommand{bu}{boldsymbol{u}}
newcommand{bv}{boldsymbol{v}}

$$leftlvert dotprod{bu}{bv} rightrvert^2 leq dotprod{bu}{bu} cdot dotprod{bv}{bv}$$
[leftlvert dotprod{bu}{bv} rightrvert^2 leq dotprod{bu}{bu} cdot dotprod{bv}{bv}]

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:


A proof with a number of syntactical construction

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:

newcommand{inval}[2]{in^{(#1)}_mathsf{val} #2}
newcommand{foldex}[2]{mathsf{fold}_{#1}(#2)}
newcommand{recty}[2]{mathsf{rec}(#1.#2)}
newcommand{Subst}[3]{sqbracks{{#1}mathord{/}{#2}}{#3}}

And the supply for the proof appears like the next:

We verify that anti-monotonicity continues to carry for recursive sorts,
by displaying that if $m leq n$, then
$$foldex{X.A}{V} inval{n}{recty{X}{A}} textual content{ implies } foldex{X.A}{V} inval{m}{recty{X}{A}}. $$

start{proof}
We proceed by induction on $n$. 
When $n=0$, the result's trivial, so think about $n geq 0$, with the intent to show it for $n+1$.

Let $m leq n + 1$, and assume
$foldex{X.A}{V} inval{n+1}{recty{X}{A}}$. If $m = n + 1$ or $m=0$, we're trivially executed, so let $0 < m < n+1$.

We need to present that
$foldex{X.A}{V} inval{m}{recty{X}{A}}$.
By definition of step-indexed logical relations~(SILR), it suffices to point out
$V inval{m-1}{Subst{recty{X}{A}}{X}{A}}$.

Since $foldex{X.A}{V} inval{n+1}{recty{X}{A}}$, by definition of SILR,
$V inval{n}{Subst{recty{X}{A}}{X}{A}}$.

By IH on $V inval{n}{Subst{recty{X}{A}}{X}{A}}$,
we additionally know $V inval{m-1}{Subst{recty{X}{A}}{X}{A}}$.

However then by definition of SILR,
$foldex{X.A}{V} inval{m}{recty{X}{A}}$, as desired. qedhere
finish{proof}

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:


Expressions which are damaged aside

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,

tau=left(s_1, a_1, ldots, a_{t-1}, s_tproper)

can be wrapped by { and } on each side and turn into

{ tau=left(s_1, a_1, ldots, a_{t-1}, s_tproper) }

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 denote the historic trajectory as 
${ tau=left(s_1, a_1, ldots, a_{t-1}, s_tproper) }$
and action-observation historical past $(mathrm{AOH})$ for
participant $i$ as 
${ tau^i=left(Omega^ileft(s_1proper), a_1, ldots, a_{t-1}, Omega^ileft(s_tproper)proper) }$,
 which encodes the trajectory from participant $i$ 's standpoint.

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:


Expressions that brace collectively stays collectively

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:


The phrase “Determine 2” was truncated in half

To treatment this, add a ~ after Determine, which LaTeX interprets as a non-breaking house:

We evaluated the coverage periodically throughout coaching by testing it with out exploration noise.
Determine~ref{fig:env-perf} exhibits the efficiency curve for a choice of environments. 

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:


Expressions which aren’t punctuated are tiring to learn

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:


Acceptable use of commas and full cease to information the reader

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…”:


Punctuation permits the content material to movement naturally

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:


Acceptable use of punctuation when a number of equations are on a single line

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:

textit{Downside: Present that if $(x_n)_n$ converges to $x$ within the traditional sense, then
$lim_{n to infty} x_n = lim_{mathcal{F}} x_n$.}

Suppose that $(x_n)_n$ converges to $x$. We present that this $x$ can also be the
$mathcal{F}$-limit of $(x_n)_n$.

start{proof}
    Take any $varepsilon$. Then we all know that for some massive sufficient $N$, if $n geq N$, then
    $x_n in B_varepsilon(x)$. Since each non-principal ultrafilter on $N$ accommodates
    $mathcal{F}_infty$, then $mathcal{F}$ additionally accommodates $ left{ n : n geq N proper} $,
    for the reason that complement is finite. Due to this fact since filters are closed upwards, any
    sequence objects $x_n$ with $n < N$ that occur to fall within the ball round $x$,
    i.e, $x_n in B_varepsilon(x)$
    can also be contained in some filter component, so 
    $left{  n in N : lvert x_n - x rvert < varepsilon proper} in mathcal{F}$,
    as desired.
finish{proof}


Signposting utilizing the `proof` atmosphere

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:

% Identical as beforehand, contents elided for brevity
start{proof}
    % Identical as beforehand, contents elided for brevity
    $x_n in B_varepsilon(x)$
    can also be contained in some filter component, so 
    $left{  n in N : lvert x_n - x rvert < varepsilon proper} in mathcal{F}$,
    as desired.

    % Additional newline right here!
finish{proof}


Misaligned QED image

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:

% Identical as beforehand, contents elided for brevity
start{proof}
    % Identical as beforehand, contents elided for brevity
    $x_n in B_varepsilon(x)$
    can also be contained in some filter component, so 
    $left{  n in N : lvert x_n - x rvert < varepsilon proper} in mathcal{F}$,
    as desired. qedhere % All the time add qedhere as soon as you're executed!

    % Additional newline right here!
finish{proof}

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):


Lack of spacing earlier than “dz”

This might sound innocuous, however think about the next instance that makes the difficulty extra specific:

P(X) = int xyz dx
[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
[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 =:

See Also

start{align*}
    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)proper)
finish{align*}
[begin{align*}
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:

start{align*}
    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)proper)
finish{align*}
[begin{align*}
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:

DeclareMathOperator*{Pr}{mathbf{Pr}}
DeclareMathOperator*{E}{mathbf{E}}
DeclareMathOperator*{Ex}{mathbf{E}}
DeclareMathOperator*{Var}{mathbf{Var}}
DeclareMathOperator*{Cov}{mathbf{Cov}}
DeclareMathOperator*{stddev}{mathbf{stddev}}

Then you should utilize it as follows:

Pr left[ X geq a right] leq frac{Ex[X]}{a}
[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:

textual content{"Good day World!"}
[text{“Hello World!”}]

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:

textual content{``Good day World!''}


Output of appropriate utilization of quotes

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 “epsilon” appears bizarre

Utilizing varepsilon makes the reader really feel way more at peace:


“varepsilon” is normally what ought to be used

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:


Use `mathbbm` as an alternative of `mathbb`

mathbbm causes the symbols to be bolded, which is what you need.

Dots

... and dots are totally different. See the distinction:

X = left( X_1, ..., X_n proper)
X = left( X_1, dots, X_n proper)


Output of “…” versus “dots”

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:


Use “cdot” appears significantly better than “*”

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.

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top