LaTeX Tips for Effective Typesetting

LaTeX is a powerful typesetting system used extensively for scientific documents, academic papers, and any situation which requires precision in presentation. Below are some effective tips and tricks to enhance your LaTeX typesetting, ensuring consistency and clarity in your documents.

Keeping Text Together and Box Usage

Ensuring Word Cohesion with mbox and fbox

To prevent LaTeX from breaking up text between lines or pages, you can use the \mbox{} command, which will keep the text inside intact regardless of formatting. It’s particularly useful when dealing with text that must stay together, such as proper names or specific code snippets.

My phone number will change soon. It will be \\mbox{0116 291 2319}.

My phone number will change soon. It will be 0116 291 2319.

Similarly, \fbox{} wraps the content with a visible box, which can be helpful for highlighting information or creating distinct sections visually.

\fbox{This text is boxed.}

To stop specific ligatures—two or more letters combined into a single character (ff fi fl f) —from being used, insert an \mbox{} between the characters.

shelf\\mbox{}ful

shelfful

Typography and Quotation Marks

In LaTeX, the correct way to start and end quotes is to use a grave accent ` for opening quotes and a simple vertical quote ' for closing quotes. For double quotes, use two grave accents and two vertical quotes.

`single quotes'

Word Separation with slash

Using \slash allows you to correctly separate words, particularly useful in compound words that require a “read or write” representation.

read\slash write

read\write

Math Expressions in LaTeX

Roman Letters in Equations

To use Roman letters within an equation, you should use the \mathrm{} directive.

\int\_{0}^{\infty} x\^{}2 \\mathrm{e}\^{-x} \\mathrm{d}x $$\int_{0}^{\infty} x^{2} \mathrm{e}^{-x} \mathrm{d}x$$

Ellipsis Representations

LaTeX offers different types of ellipsis () representations:

  • \ldots for a horizontal ellipsis in text. ($\ldots$)
  • \cdots for centered ellipsis dots in math mode. ($\cdots$)
  • \vdots for vertical ellipsis dots in math mode. ($\vdots$)
  • \ddots for diagonal ellipsis dots in math mode. ($\ddots$)
  • \cdot for a single centered dot in math mode. ($\cdot$)

Spacing and Non-Breaking in LaTeX

The tilde character ~ in LaTeX creates a non-breakable space, ensuring that certain elements stay together. This generates a space that cannot be enlarged and additionally prohibits a line break.

Dr.~Dre

Dr. Dre

When using \@ before a period, LaTeX understands the period as the end of a sentence even if it is preceded by an uppercase letter.

PROF.~SMITH WAS HAPPY TO SEE HER \@.

PROF. SMITH WAS HAPPY TO SEE HER.

In-Line Math Expressions

When typesetting in-line math expressions that are tall or deep, the \smash{} command can help avoid irregular spacing in the surrounding text.

A $d_{e_{e_p}}$ mathematical expression followed by a $h^{i^{g^h}}$ expression. As opposed to a smashed \smash{$d_{e_{e_p}}$} expression followed by a \smash{$h^{i^{g^h}}$} expression. A $d_{e_{e_p}}$ mathematical expression followed by a $h^{i^{g^h}}$ expression. As opposed to a smashed \smash{$d_{e_{e_p}}$} expression followed by a \smash{$h^{i^{g^h}}$} expression.

The example above is not correct and cannot be displayed in the browser.

Displaying Fractions

Using \frac{numerator}{denominator} you can display fractions. For in-line equations, fractions will be resized to fit the line, but you can use \dfrac{} for a display-size fraction within text.

$1\frac{1}{2}$~hours $\qquad 1\dfrac{1}{2}$~hours

$1\frac{1}{2}$ hours $\qquad 1\dfrac{1}{2}$ hours.

The slashed form 1/2 is often preferable for simple fractions due to its clarity and the fact that it takes less vertical space.

\tfrac{1}{2} can be used in equation mode to shrink the size of the fraction.

\begin{equation*}
3/8 \qquad \frac{3}{8}
\qquad \tfrac{3}{8}
\end{equation*}

$$3/8 \qquad \frac{3}{8} \qquad \tfrac{3}{8}$$

Referencing Equations

Inside the equation environment, you can label an equation with \label{} and refer to it anywhere in the text using \eqref{}.

\begin{equation}
E = mc^2 \label{eq:energy\_mass}
\end{equation}

As shown in equation \eqref{eq:energy\_mass} …

If you want to assign a custom name to an equation, use \tag{} instead.

Underlines and Overlines

To create horizontal lines over or under expressions, use \overline{} and \underline{} respectively.

\\underline{x+y}

$$\underline{x+y}$$

For double underlines, you can stack the command:

\\underline{\\underline{x+y}}

$$\underline{\underline{x+y}}$$

Advanced Mathematical Customizations

LaTeX also offers commands for more advanced operations:

  • \stackrel{#1}{#2}: Places a symbol over another in superscript size. f_n(x) \stackrel{*}{\approx} 1 $f_n(x) \stackrel{*}{\approx} 1$

  • \DeclareMathOperator: Declares a new operator (must be used in the preamble). \DeclareMathOperator{\func}{Function} Then use \func to display the operator.

  • \bmod and \pmod: Used for modulus operations in math mode. a \bmod b \qquad x \equiv a \pmod{b} $a \bmod b \qquad x \equiv a \pmod{b}$

  • \newtheorem: For defining new theorem-like environments. \newtheorem{name}[counter]{text}[section] Here, name is the short keyword to identify the theorem, and text is the text to be displayed. The optional section argument allows you to define the sectional unit that the theorem will be numbered with. the counter argument to specify the name of a previously declared “theorem”. The new “theorem” will then be numbered in the same sequence.

  • \newcommand: To define new, custom commands for repetitive use. \newcommand{name}[num]{definition} Here, name and definition are required, and num is optional. If num is specified, the command will expect that number of arguments. Upto 9 arguments can be specified. #1, #2, etc. are used to refer to the arguments in the definition. \providecommand is similar to \newcommand, but it does nothing if the command is already defined.

  • \newenvironment: To define new environments. \newenvironment{name}[num]{before}{after} Here, name is the name of the environment, before is the text to be printed before the environment, and after is the text to be printed after the environment. If num is specified, the environment will expect that number of arguments. Upto 9 arguments can be specified. #1, #2, etc. are used to refer to the arguments in the definition. \ignorespacesafterend and \ignorespaces are useful commands to ignore spaces after the environment. \newenvironment{myenvironment}{\begin{center}}{\end{center}}

  • Read 6.1.5 of the source for more information about creating package.

Adjusting Spacing

Horizontal and Vertical Spaces

To manage horizontal and vertical spaces within your document, LaTeX offers various commands:

  • \hspace{length} and \vspace{length}: To add space horizontally or vertically. Supported units are pt, mm, cm, in, ex, em, mu, fil, fill, and filll. pt: point (1/3 mm); em: width of the letter M in the current font; mu: math unit, 1/18 em; ex: height of the letter x in the current font.

  • \bigskip and \smallskip: For predefined vertical skipping.

  • Additional space between two lines of the same paragraph or within a table is specified with the \\[length] command.

  • \!, \,, \quad, and \qquad: For fine-tuning spacing in math mode.

Flexible spacing can be achieved with \stretch{n} which expands to fill all available space.

Changing Line Spacing

To modify line spacing, use \setlength{\baselineskip} followed by a scaling factor.

\setlength{\baselineskip}{1.5\baselineskip}

Source: The Not So Short Introduction to LaTeX2e
http://tug.ctan.org/info/lshort/english/lshort.pdf

0%