
# 1.3: Minicourse Skills Page - MathJax/LaTeX Formatting Conventions


## Useful Formatting Conventions for Editing Math Textbooks in LibreTexts

LibreTexts makes it easy to edit both text and mathematical equations.  For text, it's almost as easy as using a word processor.  Math can be a little more challenging to lay out, since we need to use a variety of LaTeX called MathJax.  But once you learn some of the basic commands, it will help you produce some beautiful looking mathematics.

One great way to learn LaTeX commands is to look at the commands in an existing page.  But for faster progress, there are many resources online to learn how to represent any mathematics you may wish to render.

A great place to start is the LibreTexts Adding and Editing Equations page in the Construction Guide. It includes information on how to enter subscripts, superscripts, integrals, overbraces, underbraces, cancelling expressions, fractions, matrices, and how to line up multiple expressions.

For fast rendering of complicated mathematics, there's also a great app called MathPix that you can get on your smart phone and computer that will allow you to scan or select an equation, and it will give you the LaTeX for it.  Since your account synchs between the phone app and the computer, you can access the resulting LaTeX on your computer to copy and paste into LibreTexts.  You can also select an image of an equation or expression on your computer screen.  The free version allows 50 "snips" per month, but a full account costs something like \$5.00/month, if you end up using it a lot for a while.

Another great learning tool is the Realtime MathJax (LaTeX) page that allows you to enter a LaTeX expression that is not rendering in the way you expect, instantly see how it renders, and then allows you to quickly adjust the MathJax (LaTeX) element until it looks like you want it to.

As you may already know, we can render mathematics "inline" by putting MathJax codes between $$ and $$.

For example, we can enter $$\frac{\sqrt{2}}{2}$$ to obtain $$\frac{\sqrt{2}}{2}$$.

To get "display" mode, we use the delimiters, $ and $.  This will center the math on the next line, and also turn on \displaystyle.  We'll discuss \displaystyle below.

So, for example, $\int_0^1 x^2 \, dx$ gives us:  $\int_0^1 x^2 \, dx$

This minicourse is not aimed to teach you all of MathJax (or LaTeX), but I do want to show you some basic skills that will help you to adjust pages you may find in the LibreTexts math bookshelves to make them look better and follow some basic formatting conventions.

### 1. Equation numbering

In general, we'd like to avoid numbering equations unless they are key equations for the section.

But whenever we use display mathematics, the equations will automatically be numbered unless we tell it not to.  The number is displayed to the right of the display mode equation, at the edge of the page, as you can see above.

The easiest way to do this is the add the \nonumber command at the end of the display math code.

Note that this equation is not automatically numbered since it is inline:  $$f(x) = x^2 + y^2$$       In edit mode, this expression looks like $$f(x) = x^2 + y^2$$

Exercise 1: Remove the equation number from this equation while keeping it in display mode.    In edit mode, the line below originally looks like $f(x) = x^2 + y^2$

$f(x) = x^2 + y^2$

There are a couple ways to align equal signs in equations over multiple lines.  One of the nicest is to use the \begin{align*} and \end{align*} codes along with a few other code commands to align and break the lines, as we'll learn about in the next section.  But if we forget to use the asterisk, every line of the equation will be numbered automatically.

Exercise 2: Remove the autonumbering on this aligned equation by adding asterisks at the end of the word "align".     In edit mode, the lines below originally look like \begin{align} f'(x) &= 3\cdot(x^2 + 1)^2\cdot 2x \\[4pt] &=6x(x^2+1)^2 \end{align}

\begin{align} f'(x) &= 3\cdot(x^2 + 1)^2\cdot 2x \\[4pt] &=6x(x^2+1)^2 \end{align}

### 2. Formatting functions correctly: sin x, cos x, ln x, arctan x, etc.

Consider:  $$cosx, tan(x), sin^2x, lnx$$  vs. $$\cos x, \tan(x), \sin^2x, \ln x$$ yields:

$$cosx, tan(x), sin^2x$$  vs. $$\cos x, \tan(x), \sin^2x$$

As you can see, it’s important to fix the LaTeX codes for all transcendental functions so they appear formatted properly and clearly.  Note that there should be a backslash in front of each function name and there needs to be either a space or a parenthesis or a circumflex ^ immediately after the function name.  Thus “\sinx” will not be understood, but “\sin x”, “\sin(x)”, and “\sin^2x” will all be understood correctly.  Note that the last one is really equivalent to (sin x)^2.

### 3. Proper use of displaystyle

Avoid extraneous use of \displaystyle except in cases where it is needed, such as when using \lim, \int or \sum in inline math, that is, when using the  delimiters for the LaTeX.

Note that \displaystyle is not needed when using  delimiters, since these already use displaystyle automatically.

Ex.  We can remove the \displaystyle tag from$\displaystyle ∫^5_0(5+2t)\,dt. \nonumber$

But it is needed in the following cases using \int, \lim, and \sum in inline mathematics.  In these cases, it is only needed once for a whole inline expression, even if there are multiple integrals, limits, or sums.

Without \displaystyle:

Note that $$\lim_{n\to \infty} \sum_{i=1}^n f(x_i)\,\Delta x_i = \int_a^b f(x) \, dx$$.

yields:

Note that $$\lim_{n\to \infty} \sum_{i=1}^n f(x_i)\,\Delta x_i = \int_a^b f(x) \, dx$$.

With \displaystyle:

Note that $$\displaystyle \lim_{n\to \infty} \sum_{i=1}^n f(x_i)\,\Delta x_i = \int_a^b f(x) \, dx$$.

yields:

Note that $$\displaystyle \lim_{n\to \infty} \sum_{i=1}^n f(x_i)\,\Delta x_i = \int_a^b f(x) \, dx$$.

###### Rendering Fractions at appropriate sizes:

There are three useful fraction mode commands: \frac, \dfrac, \tfrac.

\frac{1}{2} will give a small textsize fraction when in inline mode (without a \displaystyle tag).  As here: $$\frac{1}{2}$$

But it will become large when in display mode.  So $$\displaystyle \frac{1}{2}$$ gives us the large fraction: $$\displaystyle \frac{1}{2}$$.

But there are times where it look cleaner to use a displaystyle fraction in an inline expression or a textsize fraction in a display mode expression.

\dfrac{1}{2} will force displaystyle for the fraction only.  \tfrac{1}{2} will force a small text size fraction when in display mode.

I recommend using the \dfrac mode whenever there are variables in the fraction and the expression is in inline mode.  I recommend \tfrac for numerical fractions that are coefficients when in display mode.

For example: $$f(x) = \dfrac{1}{x}$$ gives us $$f(x) = \dfrac{1}{x}$$, while $$f(x) = \frac{1}{x}$$would give us $$f(x) = \frac{1}{x}$$.

And $$\displaystyle \int \tfrac{3}{4}x^5\, dx$$ gives us: $$\displaystyle \int \tfrac{3}{4}x^5\, dx$$, while $$\displaystyle \int \frac{3}{4}x^5\, dx$$ gives us: $$\displaystyle \int \frac{3}{4}x^5\, dx.$$

Exercise 3: Add \displaystyle where it is needed in the examples below and remove it where it is not.  Also consider fractions and the spacing of the differential in integrals.

There are various commands to control spacing in math mode (between $$ and $$or $ and $), including \,  \;  \:  \quad  and \qquad.

You may find it convenient to use the RealTimeMathJax link above to experiment with these. If you click on it, it will open up another window in your browser. Then you can copy and paste a few of the problems below into the textbox at the top and observe the results in the box below as you add and remove \displaystyle at the beginning of the code, or just change between a \frac and a \dfrac. (Note: To copy the code for these you must be in edit mode on this page).

$\displaystyle ∫^5_0(5+2t)\,dt. \nonumber$

$$f(x) = \frac{x^2+1}{x}$$

$$\frac{1}{5}\int_0^2 \frac{x^2+1}{x}dx$$

$$\sum_{n=1}^\infty a_n$$

$$\lim_{x\to 3} f(x) = 9$$

Note that $$\lim_{n\to \infty} \sum_{i=1}^n f(x_i)\,\Delta x_i = \int_a^b f(x) dx$$.

### 4. Using \left and \right, \big, \Big, \bigg, and \Bigg to size grouping symbols appropriately.

The \left and \right LaTeX commands can be used to make matching grouping symbols resize appropriately according to what is between them.

For example, consider the following without these commands:

$$\dfrac{d}{dx}(\dfrac{x}{x-1})$$ ,$$\dfrac{dy}{dx}|_{x = 2}$$ and $$\displaystyle \int_0^2 2x\, dx = x^2|_0^2 = 2^2 - 0^2 = 4$$

yield:

$$\dfrac{d}{dx}(\dfrac{x}{x-1}),$$   $$\dfrac{dy}{dx}|_{x = 2}$$   and $$\displaystyle \int_0^2 2x\, dx = x^2|_0^2 = 2^2 - 0^2 = 4$$

While $$\dfrac{d}{dx}\left(\dfrac{x}{x-1}\right),$$   $$\left.\dfrac{dy}{dx}\right|_{x = 2}$$  and $$\displaystyle \int_0^2 2x\, dx = x^2\Big|_0^2 = 2^2 - 0^2 = 4$$

yield:

$$\dfrac{d}{dx}\left(\dfrac{x}{x-1}\right),$$   $$\left.\dfrac{dy}{dx}\right|_{x = 2}$$  and $$\displaystyle \int_0^2 2x\, dx = x^2\Big|_0^2 = 2^2 - 0^2 = 4$$

Note that there are several options to make the evaluation bar large.  You can use the \left and \right commands, using a period after the \left command, or you can use the \big, \Big, \bigg, or \Bigg commands.  These make the symbol to the right progressively larger.

Exercise 4:  Address the size of the grouping symbols and the evaluation bar.

\begin{align*} ∫^5_010+\cos(\frac{π}{2}t)\,dt &= (10t+\frac{2}{π} \sin (\frac{π}{2}t))|^5_0 \\[4pt] &=(50+\frac{2}{π})−(0−\frac{2}{π} \sin 0)≈50.6. \end{align*}

### 5. Aligning equal signs over multiple lines using  begin{align*} and end{align*}

To align the equal signs of a chain equality, use \begin{align*} and   \end{align*}.  This structure can also be used to add text explanations to the left or right of the mathematical steps.  See the two examples below.

Example A:  What I found was:

\begin{align*} \dfrac{∂^2f}{∂x^2} =\dfrac{∂}{∂x}\left[\dfrac{∂f}{∂x}\right] \\ =\dfrac{∂}{∂x}[e^{−3y}+2\cos(2x−5y)] \\ =−4\sin(2x−5y). \end{align*}

that produced:

\begin{align*} \dfrac{∂^2f}{∂x^2} =\dfrac{∂}{∂x}\left[\dfrac{∂f}{∂x}\right] \\ =\dfrac{∂}{∂x}[e^{−3y}+2\cos(2x−5y)] \\ =−4\sin(2x−5y). \end{align*}

To fix this, I needed to insert the '&' symbol in front of each equal sign (also works with \approx and other reasons to align multiple lines).  I also inserted '[6pt]' after the \\ codes that indicate a break to a new line.  This gives a wider spacing between the lines since there are so many fractions in each line.  I usually use '[4pt]' or '[5pt]', but '[6pt]' is nicer when there are fractions in each line.

Now:

\begin{align*} \dfrac{∂^2f}{∂x^2} &=\dfrac{∂}{∂x}\left[\dfrac{∂f}{∂x}\right] \\[6pt] &=\dfrac{∂}{∂x}[e^{−3y}+2\cos(2x−5y)] \\[6pt] &=−4\sin(2x−5y). \end{align*}

produces:

\begin{align*} \dfrac{∂^2f}{∂x^2} &=\dfrac{∂}{∂x}\left[\dfrac{∂f}{∂x}\right] \\[6pt] &=\dfrac{∂}{∂x}[e^{−3y}+2\cos(2x−5y)] \\[6pt] &=−4\sin(2x−5y). \end{align*}

Exercise 5:  Format this chain equality using begin(align*} and end{align*} commands.  Also fix other issues with the trig functions and powers.

$$\frac{1}{12}(\cos(3x)−9\cos x)=\frac{1}{12}(\cos(x+2x)−9\cos x)$$

$$=\frac{1}{12}(\cos(x)\cos(2x)−\sin(x)\sin(2x)−9\cos x)$$

$$=\frac{1}{12}(\cos x(2\cos^2x−1)−\sin x(2\sin x\cos x)−9\cos x)$$

$$=\frac{1}{12}(2cos_3x−cosx−2cosx(1−cos^2x)−9cosx)$$

$$=\frac{1}{12}(4cos_3x−12cosx)$$

$$=\frac{1}{3}cos_3x−cosx.$$

Example B: I found the following code:

$$∫\sin^4x\,dx=∫(\sin^2x)^2\,dx$$ Rewrite $$\sin^4x=(\sin^2x)^2$$.

$$=∫(\frac{1}{2}−\frac{1}{2}\cos(2x))^2\,dx$$ Substitute $$\sin^2x=\frac{1}{2}−\frac{1}{2}\cos(2x).$$

$$=∫(\frac{1}{4}−\frac{1}{2}\cos(2x)+\frac{1}{4}\cos^2(2x))\,dx$$ Expand $$(\frac{1}{2}−\frac{1}{2}\cos(2x))^2.$$

$$=∫(\frac{1}{4}−\frac{1}{2}\cos(2x)+\frac{1}{4}(\frac{1}{2}+\frac{1}{2}\cos(4x))\,dx.$$

that renders as:

$$∫\sin^4x\,dx=∫(\sin^2x)^2\,dx$$ Rewrite $$\sin^4x=(\sin^2x)^2$$.

$$=∫(\frac{1}{2}−\frac{1}{2}\cos(2x))^2\,dx$$ Substitute $$\sin^2x=\frac{1}{2}−\frac{1}{2}\cos(2x).$$

$$=∫(\frac{1}{4}−\frac{1}{2}\cos(2x)+\frac{1}{4}\cos^2(2x))\,dx$$ Expand $$(\frac{1}{2}−\frac{1}{2}\cos(2x))^2.$$

$$=∫(\frac{1}{4}−\frac{1}{2}\cos(2x)+\frac{1}{4}(\frac{1}{2}+\frac{1}{2}\cos(4x))\,dx.$$

(Note that it does not show all steps to finish evaluating the integral here, but shows enough for us to learn from.)

To fix it, we can make it all one \begin{align*} \end{align*} structure, making sure we either keep it on one line or use shift-enter to keep it in the same paragraph structure.  Don't overlook this important detail -- do NOT start a new line with a simple "enter" -- instead use the "shift" plus "enter" combination!! We also use '&' before each equal sign, so they align.  We'll add '\\[4pt]' at the end of each line to insert a line break with 4 pt spacing.  And to put the explanations in their own column, we add two ampersands before the text elements.  We should also insert \text for the normal text words in the explanations.

Since it contains integrals, we should also either use display math mode (which would center it), or add the \displaystyle command.

An align environment is a table-like structure, and the & (ampersand) is a column separator. The first expression in each line of an align block is right justified, then the expression within each subsequent 'column' alternates between being left-justified and right-justified. So, a 'column'  in each line will be right-justified if it is preceded by an even number (0, 2, 4...) of ampersands, and it will be left-justified if preceded by an odd number (1, 3, ...) of ampersands.

Since there was also a missing parenthesis in the last line, I added this in too.

Doing these things, we get:

\begin{align*} \displaystyle ∫\sin^4x\,dx &=∫(\sin^2x)^2\,dx && \text{Rewrite }\sin^4x=(\sin^2x)^2.\\[4pt] &=∫(\frac{1}{2}−\frac{1}{2}\cos(2x))^2\,dx &&\text{Substitute }\sin^2x=\frac{1}{2}−\frac{1}{2}\cos(2x).\\[4pt] &=∫(\frac{1}{4}−\frac{1}{2}\cos(2x)+\frac{1}{4}\cos^2(2x))\,dx && \text{Expand }(\frac{1}{2}−\frac{1}{2}\cos(2x))^2.\\[4pt] &=∫(\frac{1}{4}−\frac{1}{2}\cos(2x)+\frac{1}{4}(\frac{1}{2}+\frac{1}{2}\cos(4x)))\,dx.\end{align*}

which renders as:

\begin{align*} \displaystyle ∫\sin^4x\,dx &=∫(\sin^2x)^2\,dx & & \text{Rewrite }\sin^4x=(\sin^2x)^2.\\[4pt] &=∫(\frac{1}{2}−\frac{1}{2}\cos(2x))^2\,dx & &\text{Substitute }\sin^2x=\frac{1}{2}−\frac{1}{2}\cos(2x).\\[4pt] &=∫(\frac{1}{4}−\frac{1}{2}\cos(2x)+\frac{1}{4}\cos^2(2x))\,dx & & \text{Expand }(\frac{1}{2}−\frac{1}{2}\cos(2x))^2.\\[4pt] &=∫(\frac{1}{4}−\frac{1}{2}\cos(2x)+\frac{1}{4}(\frac{1}{2}+\frac{1}{2}\cos(4x)))\,dx.\end{align*}

Note that we could also improve the parentheses here using what we learned above.  Doing this (and also adding an explanation for the last step), we get the code:

\begin{align*} \displaystyle ∫\sin^4x\,dx &=∫\left(\sin^2x\right)^2\,dx & & \text{Rewrite }\sin^4x=\left(\sin^2x\right)^2.\\[4pt] &=∫\left(\frac{1}{2}−\frac{1}{2}\cos(2x)\right)^2\,dx & &\text{Substitute }\sin^2x=\frac{1}{2}−\frac{1}{2}\cos(2x).\\[4pt] &=∫\left(\frac{1}{4}−\frac{1}{2}\cos(2x)+\frac{1}{4}\cos^2(2x)\right)\,dx & & \text{Expand }\left(\frac{1}{2}−\frac{1}{2}\cos(2x)\right)^2.\\[4pt] &=∫\left(\frac{1}{4}−\frac{1}{2}\cos(2x)+\frac{1}{4}\left(\frac{1}{2}+\frac{1}{2}\cos(4x)\right)\right)\,dx & &\text{Substitute }\cos^2(2x)=\frac{1}{2}+\frac{1}{2}\cos(4x).\end{align*}

which gives us:

\begin{align*} \displaystyle ∫\sin^4x\,dx &=∫\left(\sin^2x\right)^2\,dx & & \text{Rewrite }\sin^4x=\left(\sin^2x\right)^2.\\[4pt] &=∫\left(\frac{1}{2}−\frac{1}{2}\cos(2x)\right)^2\,dx & &\text{Substitute }\sin^2x=\frac{1}{2}−\frac{1}{2}\cos(2x).\\[4pt] &=∫\left(\frac{1}{4}−\frac{1}{2}\cos(2x)+\frac{1}{4}\cos^2(2x)\right)\,dx & & \text{Expand }\left(\frac{1}{2}−\frac{1}{2}\cos(2x)\right)^2.\\[4pt] &=∫\left(\frac{1}{4}−\frac{1}{2}\cos(2x)+\frac{1}{4}\left(\frac{1}{2}+\frac{1}{2}\cos(4x)\right)\right)\,dx & &\text{Substitute }\cos^2(2x)=\frac{1}{2}+\frac{1}{2}\cos(4x).\end{align*}

Exercise 6:  Now, format this chain equality with explanations using begin(align*} and end{align*} commands.

Thus,

$$∫\dfrac{\sqrt{4−x^2}}{x}dx=∫\dfrac{\sqrt{4−(2\sin θ)^2}}{2\sin θ}2\cos θ \, dθ$$ Substitute $$x=2\sin θ$$ and $$=2\cos θ\,dθ.$$

$$=∫\dfrac{2\cos^2θ}{\sin θ}\,dθ$$ Substitute $$\cos^2θ=1−\sin^2θ$$ and simplify.

$$=∫\dfrac{2(1−\sin^2θ)}{\sin θ}\,dθ$$ Substitute $$\sin 2θ=1−\cos^2θ$$.

$$=∫ (2\csc θ−2\sin θ)\,dθ$$ Separate the numerator, simplify, and use $$\csc θ=\dfrac{1}{\sin θ}$$.

$$=2 ln |\csc θ−\cot θ|+2\cos θ+C$$ Evaluate the integral.

$$=2 ln \left|\dfrac{2}{x}−\dfrac{\sqrt{4−x^2}}{x}\right|+\sqrt{4−x^2}+C.$$ Use the reference triangle to rewrite the expression in terms of $$x$$ and simplify.

1.3: Minicourse Skills Page - MathJax/LaTeX Formatting Conventions is shared under a CC BY-SA license and was authored, remixed, and/or curated by Paul Seeburger.