In this article, I will gather up all useful LaTeX command for ease access to me.
LaTeX? Visit here.
Locally, I use Texmaker. Online, I also use overleaf.
introduction
-
documentClass
In the beginning of our LaTeX
.tex
file, we have to declare/define what type of document is we are going to create. Some example includes: see here.- article - for articles in scientific journals, presentations, short reports, program documentation, etc...
- IEEEtran - for articles with the IEEE Transactions format.
- report - for longer reports containing several chapters, small books, thesis, etc...
- book - for real books
- slides - for slides.
- letter - for writing letters.
\documentclass[]{article}
Here, [] → is an optional argument where we can pass the font size, eg. [11pt], or leave it blank or even remove it
-
begin, end
Until now, we haven’t done anything which would give us any output. For this, we have to use
\begin{}
class and\end{}
class. If we only use\begin{}
class, then it will not produce any output as it will look for ending of the document. In between begin and end, we can write our text or any text. Then, compile to see the word in pdf generated.\begin{document} Heyy, This is my first LaTeX file. \end{document}
Bang, if we enclose LaTeX with ‘
\
' in both side of LaTeX, like\LaTeX\
, then, we will get wonderful effect. -
newline
two ways:
-
Hardcoded one blank line —> creates new paragraph with indented
-
softcoded: use
\\
at the end of line, not indented\begin{document} Heyy, This is my first \LaTeX\ file.\\ Thhis is just sentence in same paragraph with new line This is new paragraph \end{document}
-
-
math mode
We need to enclose with $ symbols to indicate mathematical format, which writes in italic.
eg.
$(x+1)$
Further, to write an quadratic equation:
$A(x) = X^2 + X + 1$
but if our equation goes in two lines with splitted and we want to have on a single line, then, we need to enclose in{ }
braces. e.g.${A(x) = X^2 + X + 1}$
One thing to notice is, If we use two
$$
symbols, then, the match equation is written in center with its own line.Further
-
dots
\ldots
—> lower 3 dots $\ldots$\cdots
—> center 3 dots $\cdots$ -
using package
To use some packages, use this after
\documentclass$\cdots$
:
\usepackage{comma,separated,names,of,packages}
-
space
use
\vspace{distance}
eg.\vspace{1cm}
will add vertical space of 1 cm. -
useful tools
✍️ Use
\hline
for horizontal line
✍️ two figures in two columns in single row: answer from\usepackage{multicol} \usepackage{graphicx} \begin{document} \begin{figure*} \begin{multicols}{2} \includegraphics[width=\linewidth]{figure name}\par \includegraphics[width=\linewidth]{figure name}\par \end{multicols} \begin{multicols}{2} \includegraphics[width=\linewidth]{figure name}\par \includegraphics[width=\linewidth]{figure name}\par \end{multicols} \caption{caption here} \end{figure*} \end{document}
-
some (adding later)
-
mathematical notations
-
superscripts
Use dollar
$
symbol to indicate math mode
$2x^3$
→ 2
$2x^34$
—> gives 2$x^3$4 but what if we want to write 2$x^{34}$
$2x^{34}$
—> 2$x^{34}$
$2x^{3x+4}$
—> 2$x^{3x+4}$
$$2x^{3x+4}$$
—> $2x^{3x+4}$
$$2x^{3^{x^{45}+5}+6}+7$$
—> $2x^{3^{x^{45}+5}+6}+7$
-
subscripts
$$x_1$$
—> $x_1$
$$x_12$$
—> $x_12$
$$x_{12}$$
—> $x_{12}$
$$x_{y_{2_3}}$$
—> $x_{y_{2_3}}$
$$x_{y_{2_3}}$$
—> $x_{y_{2_3}}$
$$a_0,a_1, a_2, \ldots, a_{100}$$
—> $a_0,a_1, a_2, \ldots, a_{100}$ -
greek letter
$$\pi$$
—> $\pi$
$$\Pi$$
—> $\Pi$
$$\alpha$$
—> $\alpha$
$$A=\pir^2$$
—> this gives error as it can’t identify pi, so give one space between pi and r
$$A=\pi r^2$$
—> $A=\pi r^2$
-
trigonometry function
$$y=sin x$$
—> $y=sin x$ (this is not our way, so not use like this, instead do:)
$$y=\sin x$$
—> $y=\sin x$
$$y=\cos x$$
—> $y=\cos x$
$$y=\csc \theta$$
—> $y=\csc \theta$
$$y=\sin^{-1} 1$$
—> $y=\sin^{-1} 1$
$$y=\arcsin x$$
—> $y=\arcsin x$
-
Log
$$y=\log x$$
—> $y=\log x$
$$y=\log_5 x$$
—> $y=\log_5 x$
$$y=\ln x$$
—> $y=\ln x$
-
roots
$$y=\sqrt{2}$$
—> $y=\sqrt{2}$
$$y=\sqrt[3]{x^4}$$
—> $y=\sqrt[3]{x^4}$
$$\sqrt{x^2 + y^2 }$$
—> $\sqrt{x^2 + y^2}$
$$\sqrt{ 1+\sqrt{x} }$$
→ $\sqrt{ 1+\sqrt{x}}$
-
Fraction
$$\frac{Numerator}{Denominator} $$
—> $\frac{Numerator}{Dinominator}$
$$\frac{2}{3}$$
—> $\frac{2}{3}$
$\dfrac{2}{3}$
—> $\dfrac{2}{3}$ —> to make fraction a little larger in inline format, usedfrac
instead offrac
,dfrac
is display frac.⚠️ Double dollar symbol
$$...$$
already includes display math mode…$$\displaystyle frac{2}{3}$$
—> $\displaystyle \frac{2}{3}$ —> We can also use
\displaystyle
\frac{Numerator}{Denominator}
⚠️ While showing fraction, two lines may look very near, and in such case, we can specify some distance between line with line breaker symbol at the end i.e.\\
like,\\[6pt]
this will actually place some space between two lines, giving fraction to be visible fine.❗Further, we can also remove the page number by putting below line after the
\documentclass$\cdots$
:\pagestyle{empty}
❗To use packages, use
\usepackage{package,name,with,comma,separation}
If we use some functions without mentioning package name, then, we may encounter error like:!Undefined control sequence. $$\dfrac
$$\frac{\sqrt{x+1}}{\sqrt{x+2}}$$
—>$\frac{\sqrt{x+1}}{\sqrt{x+2}}$
$$\frac{1}{1+\sqrt{x}}$$
-→$\frac{1}{1+\sqrt{x}}$
$$\sqrt{\frac{x+1}{y+2}}$$
—>$\sqrt{\frac{x+1}{y+2}}$
-
brackets
We need to use packages to use braces:
\usepackages{amsmaths,amsfonts,amssymb}
✍️ parenthesis:
$a(b+c) = ab+ac$ for all $a, b, c \in \mathbb{R}$
→ $a(a+b) = ab+ac$ for all $a, b, c \in \mathbb{R}$✍️ bracket:
$a$ is $[a]$
—> a is $[a]$✍️ curly braces $A$ is defined to be ${1,2,3}$ —> this will not display { } braces. we have to escape them as they are special symbol in the LaTeX.
$\{1,2,3\}$
-→ {1,2,3}✍️ dollar symbol $: To write
$
, we have to escape it:$\$ 23$
—> $ 23 -
braces in fraction
✍️
$$2(\frac{1}{x^2-1})$$
—> $2(\frac{1}{x^2-1})$ —> In LaTeX, if we don’t use\left
and\right
, then, our parenthesis will not cover our fraction.$$2\left(\frac{1}{x^2-1}\right)$$
—> $2\left(\frac{1}{x^2-1}\right)$$$2\left\{\frac{1}{x^2-1}\right\}$$
$$ 2 \left[\frac{1}{x^2-1}\right] $$
-
angular braces
We need to use
\langle
and\rangle
$$ 2 \left\langle\frac{1}{x^2-1}\right\rangle $$
—> $2 \left\langle\frac{1}{x^2-1}\right\rangle$ -
differentiation $\frac{dy}{dx}$
$$\frac{dy}{dx}|_{x=1}$$
—> $\frac{dy}{dx}|_{x=1}$$$\left.\frac{dy}{dx}\right|_{x=1}$$
—> $\left.\frac{dy}{dx}\right|_{x=1}$
✍️ Here, since we can't use$\right$
alone, we must have to have equivalent pairing$\left$
. Hence, we added one$\left$
. But, we don't wan't it to display, hence, we put one period(.)
there so that it will not be displayed.$$ \left(\frac{1}{1+\left(\frac{1}{1+x}\right)}\right) $$
—>$\left(\frac{1}{1+\left(\frac{1}{1+x}\right)}\right)$
-
table
✍️ We add new tabular block with
\begin{tabular}
and\end{tabular}
✍️ Here, we mentioned$ccc $\ldots$ $
not for columns, but for actually thealignment
. This c represent center alignment, other values that can go here is l -> left, r -> right align.\ Default separation is & , but if we want to use as column separator, we can specify in definition as: {|c|c|c|} so on.\\begin{tabular}{cccccc} x & 1 & 2 & 3 & 4 & 5\\ Here, we mentioned ccc $\ldots$ not for columns, but for actually the alignment. This c represent center alignment, other values that can go here is l -> left, r -> right align.\\ Default separation is , but if we want to use as separator, we can specify in definition as: {|c|c|c|} so on.\\ \\[16pt] \end{tabular}
\begin{tabular}{|c||c|c|c|c|c|} \hline x & 1 & 2 & 3 & 4 & 5\\ \hline $f(x)$ & 1 & 4 & 9 & 16 & 25 \\ \hline \end{tabular} \vspace{1cm} But adding this table type, actually places our table based on where it will be best-fitted in our page, hence, it has moved it to top.\\ However, we can explicitly tell to put the table wherever I have coded it to be. to do so, we need to add $[H]$ with table definition and also have to add package: float\\ Why we are wrapping tabular with a table block is because when using fraction in a table, the value is not showing good enough, hence, to add a little bit of space there.\\ we have to define a arraystretch after begin table: \begin{table}[H] \def\arraystretch{1.5} \centering to put our table in the center \begin{tabular}{|c||c|c|c|c|c|} \hline x & 1 & 2 & 3 & 4 & 5\\ \hline $f(x)$ & $\frac{1}{2}$ & 4 & 9 & 16 & 25 \\ \hline \end{tabular} \caption{These values present the function of $f(x)$} \end{table}
✍️ Adding caption to our table: before
\end{table}
and after\end{tabular}
watch from31:04
, J’ai sommeil. Bonne nuit!!