LaTeX Math Formatting: A Beginner’s Easy Guide

When expressing complex concepts or ideas, we often seek to formalize them for greater accuracy. While charts and graphics are effective means of explaining problems, mathematical equations are undoubtedly the most precise and universally recognized.

LaTeX, as a professional typesetting language, provides us with the ideal platform to create and share these mathematical expressions.

This article introduces how to use LaTeX to clearly and accurately express complex concepts and ideas.

1. Installation and Configuration

1.1 Installing LaTeX

On a Mac, the simplest method is to use the following command:

brew install --cask mactex

Alternatively, you can try:

  • TeX Live (a large 6GB package): Visit the official website.
  • TinyTeX: A smaller alternative, but it requires Perl.

1.2 Adding the LaTeX Workshop Plugin for IDEs

2. Basic LaTeX Examples

Create a new .tex file and enter the following:

documentclass{article}

begin{document}

The sum of two variables (a) and (b) is given by:
[ a + b ]

end{document}

Here, it is important to define the document type using documentclass{article}.

The document type can be defined with documentclass{article} (which can also be report, book, letter, beamer, memoir, etc.), and the content begins with begin{document} and ends with end{document}.

Next, you need to compile the LaTeX project (on Mac, this is done with ⌥ ⌘ B or by clicking the ▶️ button), which will generate a PDF that you can preview or open.

3. Advanced LaTeX Examples

3.1 Representation of Einstein’s Mass-Energy Equation

documentclass{article}

begin{document}

noindent Einstein's famous equation ( E = mc^2 ) relates  
energy (( E )), mass (( m )), and the speed of light (( c )).

end{document}

This yields:

Here, the equation is surrounded by $$ Equation… $$; variables are denoted with double parentheses: (( Variable )); and some formatting is applied using noindent to remove the first-line indentation and to add a line break.

3.2 More Basic Mathematical Expressions

documentclass{article}

begin{document}

Fraction: ( frac{3}{4} )

Exponent: ( x^{2} )

Square root: ( sqrt{2} )

Subscript and superscript: ( x_{1} )

Greek letters: ( alpha, beta, gamma )

Summation: ( sum_{i=1}^{n} i )

Integral: ( int_{0}^{π} sin(x) dx )

Limit: ( lim_{x to 0} frac{sin(x)}{x} )

Multiplication: ( 3 cdot 4 )

Division: ( 10/2 )

end{document}

This will produce:

3.3 Complex Equations

documentclass{article}

begin{document}

( frac{{1}}{{2πi}} oint_C frac{{f(z)}}{{(z - z_0)^{n+1}}} , 
dz = frac{{f^{(n)}(z_0)}}{{n!}} ) 

end{document}

This results in the Cauchy Integral Formula:

3.4 Matrices

documentclass{article}
usepackage{amsmath}
begin{document}

$$
begin{bmatrix} 
1 & 2 & 3 
4 & 5 & 6 
7 & 8 & 9
end{bmatrix}
$$

end{document}

Note: Matrices and arrays can be tricky because each LaTeX library handles them differently. We must import a package: amsmath. Also, note that we use $$ instead of $$ … $$, which is an alternative syntax.

3.5 Using Theorem Environments

documentclass{article}
usepackage{amsthm} % Required for theorem environments

theoremstyle{plain} % Style for theorems (italicized body)
newtheorem{theorem}{Theorem} % Define theorem environment

begin{document}

begin{theorem}[Fundamental Theorem of Arithmetic]
Every integer greater than 1 can be uniquely expressed as a
product of prime numbers, up to the order of the factors.
end{theorem}

begin{proof}
Let ( n ) be an integer greater than 1. We'll prove the 
theorem by induction on ( n ).

textbf{Base Case:} For ( n = 2 ), the theorem holds 
since 2 is itself a prime number.

textbf{Inductive Step:} Assume the theorem holds for all integers ( k ) such that ( 2 leq k leq n ). 
We'll show that it holds for ( n + 1 ).

If ( n + 1 ) is prime, then it can be expressed as a 
product of a single prime number, which satisfies the theorem.

If ( n + 1 ) is composite, then it can be expressed as 
( n + 1 = ab ), where ( 2 leq a, b leq n ). 
By the induction hypothesis, both ( a ) and ( b ) 
can be expressed as products of prime numbers. 
Therefore, ( n + 1 ) can also be expressed as a product of prime numbers.

Thus, by mathematical induction, the theorem holds for 
all integers greater than 1.
end{proof}

end{document}

This will yield:

4. Resources for Further Learning

Now that readers should have a basic understanding of LaTeX, it’s important to note that everyone’s project needs will differ. Here are some general resources to share:

  • LaTeX Wikibook: A comprehensive resource for all things LaTeX.
  • Overleaf (Learning Version): An online LaTeX editor with excellent documentation and numerous tutorials.
  • TeX — LaTeX Stack Exchange: If you encounter challenges while using LaTeX, you can search in the LaTeX section of Stack Overflow or boldly ask your questions. Additionally, there is a dedicated LaTeX community on Reddit (subreddit: r/LaTeX) where many enthusiasts gather to provide help.

5. Advanced Features

LaTeX can do even more:

5.1 Elements of Academic Papers (e.g., Footnotes)

documentclass{article}

begin{document}

This is a sentence with a footnotefootnote{This is the footnote text}. Next is another sentence.

end{document}

This is just the tip of the iceberg. LaTeX also supports complex lists, cross-referencing, graphic insertion, table creation, and much more.

Categories: AI Tools Guide
X