Writing Mathematical Expressions in LaTeX
LaTeX is widely used for typesetting mathematical expressions due to its powerful and flexible syntax. It allows you to create complex equations and symbols with ease. Below, we will explore how to write mathematical expressions in LaTeX in detail, along with sample code.
1. Inline vs. Display Math
In LaTeX, you can write mathematical expressions in two main ways: inline and display mode.
- Inline Math: This is used for short mathematical expressions that are part of a paragraph. You can enter inline math by enclosing the expression with dollar signs (
$...$
). - Display Math: This is used for larger equations that you want to stand out on their own. You can enter display math using double dollar signs (
$$...$$
) or theequation
environment.
2. Inline Math Example
Here is an example of an inline mathematical expression:
The equation of a line is given by $y = mx + b$.
In this example, the expression y = mx + b
will appear inline with the text.
3. Display Math Example
Here is an example of a display mathematical expression:
$$ E = mc^2 $$
Alternatively, you can use the equation
environment for display math:
\begin{equation}
E = mc^2
\end{equation}
Using the equation
environment will automatically number the equation.
4. Common Mathematical Symbols
LaTeX provides a wide range of symbols for mathematical expressions. Here are some commonly used symbols:
- Superscript:
x^2
producesx²
- Subscript:
x_i
producesx<sub>i</sub>
- Fractions:
\frac{a}{b}
produces½
- Square root:
\sqrt{x}
produces√x
- Summation:
\sum_{i=1}^{n} i
produces∑<sub>i=1</sub><sup>n</sup> i
- Integral:
\int_{a}^{b} f(x) \, dx
produces∫<sub>a</sub><sup>b</sup> f(x) dx
5. Example of a Complete LaTeX Document with Math
Here is a complete example of a LaTeX document that demonstrates both inline and display mathematical expressions:
\documentclass{article} % Specifies the document class
\begin{document} % Start of the document
The equation of a line is given by $y = mx + b$.
Here is a famous equation in display mode:
$$ E = mc^2 $$
And here is an equation in the equation environment:
\begin{equation}
a^2 + b^2 = c^2
\end{equation}
\end{document} % End of the document
6. Conclusion
Writing mathematical expressions in LaTeX is both powerful and flexible. By using inline and display math modes, you can create a wide range of mathematical symbols and equations. Understanding how to format these expressions will greatly enhance the quality of your LaTeX documents, especially in academic and scientific writing.