mathsoftware

A course about LaTeX and SageMath
git clone https://git.tronto.net/mathsoftware
Download | Log | Files | Refs | README | LICENSE

2-LatexFundamentals.tex (10210B)


      1 \documentclass[11pt]{beamer}
      2 \usetheme{Madrid}
      3 \usepackage[utf8]{inputenc}
      4 \usepackage{amsmath, amssymb, amsfonts, amsthm}
      5 \usepackage{xcolor}
      6 
      7 \usepackage{tikz-cd}
      8 
      9 \author[\texttt{sebastiano.tronto@uni.lu}]{Sebastiano Tronto}
     10 \title{Latex Fundamentals}
     11 \logo{\includegraphics[scale=0.1]{img/unilu.jpg}} 
     12 %\institute{University of Luxembourg} 
     13 
     14 \newcommand{\bs}{\textbackslash}
     15 
     16 \date{2021-02-19} 
     17 
     18 \begin{document}
     19 
     20 \begin{frame}
     21   \titlepage
     22 \end{frame}
     23 
     24 \begin{frame}{Latex}
     25   \begin{enumerate}
     26     \item Write code (like HTML, not like Python)
     27     \item Compile to get a pdf file
     28     \item ???
     29     \item Profit
     30   \end{enumerate}
     31 \end{frame}
     32 
     33 
     34 \begin{frame}{Document structure}
     35   \includegraphics[scale=0.5]{img/example2-preamble-edited.png}
     36 \end{frame}
     37 
     38 \begin{frame}{Preamble}
     39   \begin{itemize}
     40     \item Include packages with \texttt{\bs usepackage}
     41     \item Define properties of the document (\texttt{\bs documentclass},
     42           \texttt{\bs author}, ...)
     43     \item Define new commands and environments
     44   \end{itemize}
     45 \end{frame}
     46 
     47 \begin{frame}{Text formatting}
     48   \begin{center}
     49 
     50     \begin{tabular}{ccc}
     51       \texttt{\small \bs textbf\{Hello\}} &
     52       \texttt{\small \bs textit\{Hello\}} or \texttt{\small\bs emph\{Hello\}} &
     53       \texttt{\small \bs underline\{Hello\}} \\
     54       \textbf{Hello} & \textit{Hello} & \underline{Hello}
     55     \end{tabular}
     56   
     57     \vspace{0.7cm}
     58       \begin{tabular}{ccc}
     59       \texttt{\small \{\bs small Hello\}} & \hspace{1cm}
     60       \texttt{\small \{\bs Large Hello\}} \hspace{1cm} &
     61       \texttt{\small \{\bs huge Hello\}} \\
     62       {\small Hello} & {\Large Hello} & {\huge Hello}
     63     \end{tabular}
     64 
     65   \end{center}
     66 \end{frame}
     67 
     68 \begin{frame}{Text formatting}
     69   Some technicalities:
     70   \begin{itemize}
     71     \item Blocks are delimited by \{ and \}
     72     \item \texttt{\bs textbf\{...\}} etc. are commands with one argument
     73     \item \texttt{\bs emph\{...\}} is context-aware (when in doubt use this)
     74     \item \texttt{\bs Large} etc. change the text until the end of the block
     75     \item Some people use \texttt{\{\bs bf Hello\}}, but it is deprecated
     76   \end{itemize}
     77 \end{frame}
     78 
     79 \begin{frame}{Text formatting}
     80   \begin{center}
     81     \begin{tabular}{lc}
     82       \texttt{\{\bs tiny Hello\}}         & {\tiny Hello} \\
     83       \texttt{\{\bs scriptsize Hello\}}   & {\scriptsize Hello} \\
     84       \texttt{\{\bs footnotesize Hello\}} & {\footnotesize Hello} \\
     85       \texttt{\{\bs normalsize Hello\}}   & {\normalsize Hello} \\
     86       \texttt{\{\bs large Hello\}}        & {\large Hello} \\
     87       \texttt{\{\bs Large Hello\}}        & {\Large Hello} \\
     88       \texttt{\{\bs LARGE Hello\}}        & {\LARGE Hello} \\
     89       \texttt{\{\bs huge Hello\}}         & {\huge Hello} \\
     90       \texttt{\{\bs Huge Hello\}}         & {\Huge Hello} \\
     91     \end{tabular}
     92   \end{center}
     93 \end{frame}
     94 
     95 \begin{frame}{Math mode}
     96   \texttt{One can write math inline, like
     97           {\color{red}\bs(} \bs sum\_i\bs frac\{i\}\{2\} {\color{red}\bs)},
     98           or in displaystyle:
     99           {\color{red}\bs[} \bs sum\_i\bs frac\{i\}\{2\} {\color{red}\bs]}
    100          }
    101 
    102   \vspace{1.5cm}
    103   One can write math inline, like \(\sum_i\frac{i}{2}\) or in displaystyle:
    104   \[\sum_i\frac{i}{2}\]
    105 \end{frame}
    106 
    107 \begin{frame}{Math mode}
    108   \begin{center}
    109     For formulas spanning multiple lines you can use:
    110 
    111     \vspace{0.5cm}
    112     \texttt{\color{red}\bs begin\{align\} (...) \bs end \{align\}}
    113     \begin{align}
    114       e^x =& \sum_{n=0}^{\infty} \frac{x^n}{n!} \\
    115           =& 1 + x + \frac{x^2}{2} + \frac{x^3}{6} + \cdots
    116     \end{align}
    117     or \texttt{\color{red}\bs begin\{align*\} (...) \bs end\{align*\}} for no
    118     numbers.
    119   \end{center}
    120 \end{frame}
    121 
    122 \begin{frame}{Math mode}
    123   \begin{itemize}
    124     \item Some people use \texttt{\$2+2=4\$} instead of \texttt{\bs(2+2=4\bs)}
    125     \item Some \textbf{evil} people use \texttt{\$\$2+2=4\$\$} instead of
    126           \texttt{\bs[2+2=4\bs]} (don't try this at home!)
    127     \item For \texttt{align} use \texttt{\bs nonumber} to remove one number
    128           and \texttt{\&} to align.
    129     \item For example I always use \texttt{\$2+2=4\$} and the \texttt{align*}
    130           environment.
    131   \end{itemize}
    132 \end{frame}
    133 
    134 \begin{frame}{Math mode}
    135   \begin{itemize}
    136     \item Simple symbols: letters, numbers, $+,-,=,<,>$...
    137     \item Symbols that need a \textbf{command}:
    138 
    139           \vspace{0.6cm}
    140           \begin{tabular}{c|c|c|c|c}
    141             \texttt{\bs alpha, \bs Phi} & \texttt{\bs times, \bs cdot} &
    142             \texttt{\bs sum} & \texttt{\bs leq, \bs geq} & \texttt{\bs infty}\\
    143             $\alpha,\Phi$ & $\times,\cdot$ & $\sum$ & $\leq,\geq$ & $\infty$
    144           \end{tabular}
    145           \vspace{0.6cm}
    146     \item Negate symbols with \texttt{\bs not}:
    147           \begin{align*}
    148             \texttt{x \bs not \bs in A} \qquad\to&\qquad x\not\in A\\
    149             \texttt{x \bs not = y}\quad\text{ or }\quad\texttt{x \bs neq y}
    150              \qquad\to&\qquad x\neq y\\
    151           \end{align*}
    152   \end{itemize}
    153 \end{frame}
    154 
    155 \begin{frame}{Math mode}
    156   \begin{itemize}
    157     \item Some commands take one or more \textbf{arguments} (like 
    158           \texttt{\bs frac}).
    159           
    160           Anything can be an argument:
    161           \begin{align*}
    162             \texttt{\bs frac\{1\}\{\bs sum\_\{n\}\}}\qquad\to\qquad
    163             \frac{1}{\sum_{n} \sqrt n}
    164           \end{align*}
    165     \item A few commands take \textbf{options}:
    166           \texttt{\bs sqrt[3]\{x\}} $\to\,\sqrt[3]{x}$
    167     %\item Most of these commands work only in Math mode
    168   \end{itemize}
    169 \end{frame}
    170 
    171 
    172 \begin{frame}{Math mode}
    173   \begin{itemize}
    174     \item Every symbol can have a \textbf{subscript} and a \textbf{superscript}
    175           \begin{align*}
    176             \texttt{x\_0\^{}\{23\}} \qquad \to \qquad x_0^{23}
    177           \end{align*}
    178     \item Anything can be a sub/superscript:
    179           \begin{align*}
    180             \texttt{\bs int\_\{\bs phi (y)\}\^{}\{2\^{}\{n\_1\}\}}
    181             \qquad \to \qquad \int_{\phi(y)}^{2^{n_1}}
    182           \end{align*}
    183   \end{itemize}
    184 \end{frame}
    185 
    186 
    187 \begin{frame}{Math mode}
    188   \begin{itemize}
    189     \item Adjust parentheses size with \texttt{\bs left(} and
    190           \texttt{\bs right)}: \[\left(\frac{x+6}{y-2}\right)\]
    191     \item Insert text with \texttt{\bs text} and
    192           spaces with \texttt{\bs ,} and \texttt{\bs quad}:
    193           \[\text{this symbol}\quad \sum_{n=0}^\infty \frac{x^n}{n!} \quad
    194             \text{is in math mode}, this is not text\]
    195   \end{itemize}
    196 \end{frame}
    197 
    198 \begin{frame}{Math mode}
    199   
    200   \begin{itemize}
    201     \item Fancy letters with \texttt{\bs mathcal},
    202           \texttt{\bs mathbb} and \texttt{\bs mathfrak}:
    203           \begin{align*}
    204             \mathcal{A} \qquad \mathbb R \qquad \mathfrak p
    205           \end{align*}
    206     \item For custom operators use \texttt{\bs operatorname\{oper\}}:
    207           \begin{align*}
    208             \operatorname{oper}(x)
    209           \end{align*}
    210     \item Pro-tip: write \texttt{\bs newcommand\{\bs R\}\{\bs mathbb R\}} and
    211           \texttt{\bs DeclareMathOperator\{\bs lcm\}\{lcm\}} in your preamble!
    212   \end{itemize}
    213 \end{frame}
    214 
    215 \begin{frame}{Math mode}
    216   \begin{itemize}
    217     \item Wikibooks page on Math mode:
    218          {\small\url{https://en.wikibooks.org/wiki/LaTeX/Mathematics}}
    219     \item Advanced stuff:
    220          {\small\url{https://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics}}
    221     \item List of Mathematical symbols:
    222          {\small\url{https://www.caam.rice.edu/~heinken/latex/symbols.pdf}}
    223   \end{itemize}
    224 \end{frame}
    225 
    226 \begin{frame}{Environments}
    227   \texttt{\color{red}\bs begin\{something\}}
    228     Inside an environment 
    229   \texttt{\color{red}\bs end\{something\}}
    230 
    231   \vspace{0.8cm}
    232   \begin{itemize}
    233     \item We have seen \texttt{document} and \texttt{align}
    234     \item Text and symbols appear differently depending on the environment
    235     \item Certain commands are specific to an environment
    236     \item You can define new environments
    237   \end{itemize}
    238 \end{frame}
    239 
    240 
    241 \begin{frame}{Environments}
    242   Lists: \texttt{\color{red}itemize} and \texttt{\color{red}enumerate}
    243 
    244   \vspace{0.8cm}
    245   \begin{columns}
    246     \column{0.5\textwidth}
    247       \begin{itemize}
    248         \item First: \[2+2=4\]
    249         \item Second
    250       \end{itemize}
    251 
    252     \column{0.5\textwidth}
    253       \texttt{\bs begin\{itemize\}}
    254 
    255       \texttt{\qquad \bs item First: \bs[2+2=4\bs]}
    256 
    257       \texttt{\qquad \bs item Second}
    258 
    259       \texttt{\bs end\{itemize\}}
    260   \end{columns}
    261 \end{frame}
    262 
    263 \begin{frame}{Environments}
    264   Tables: \texttt{tabular} (text) and \texttt{array} (Math mode)
    265 
    266   \vspace{0.8cm}
    267   \begin{columns}
    268     \column{0.5\textwidth}
    269       \begin{tabular}{r|cc}
    270         This & is & just \\
    271         \hline
    272           a  & boring & table
    273       \end{tabular}
    274 
    275     \column{0.5\textwidth}
    276       \texttt{\bs begin\{tabular\}\{r|cc\}}
    277 
    278       \texttt{\qquad This \& is \& just \bs\bs}
    279 
    280       \texttt{\qquad \bs hline}
    281 
    282       \texttt{\qquad a \& boring \& table}
    283 
    284       \texttt{\bs end\{tabular\}}
    285   \end{columns}
    286   
    287   \vspace{0.8cm}
    288   Matrices: \texttt{array} with parentheses or \texttt{pmatrix}
    289 \end{frame}
    290 
    291 \begin{frame}{Sections}
    292   \begin{itemize}
    293     \item Use \texttt{\bs section\{Section Name\}} to start a new section
    294     \item Also: \texttt{\bs chapter} (book only), \texttt{\bs subsection},
    295           \texttt{subsubsection}...
    296     \item \texttt{\bs section*\{Name\}} for no number
    297     \item Sections after \texttt{\bs appendix} are numbered differently
    298   \end{itemize}
    299 \end{frame}
    300 
    301 \begin{frame}{Theorems}
    302   
    303   \begin{itemize}
    304     \item In preamble: \texttt{\bs usepackage\{amsthm\}}
    305     \item Also in preamble \texttt{\bs newtheorem \{envname\}\{Theorem\}}
    306     \item Use \texttt{\bs newtheorem*} for no number
    307   \end{itemize}
    308 \end{frame}
    309 
    310 \begin{frame}{Theorems}
    311   \begin{columns}
    312     \column{0.5\textwidth}
    313       \includegraphics[scale=0.3]{img/thm_pre.png}
    314 
    315       \vspace{0.2cm}
    316       \vdots
    317       \vspace{0.3cm}
    318 
    319       \includegraphics[scale=0.3]{img/thm_tex.png}
    320 
    321     \column{0.5\textwidth}
    322       \includegraphics[scale=0.2]{img/thm_pdf.png}
    323 
    324       \vspace{1cm}
    325   \end{columns}
    326 \end{frame}
    327 
    328 \begin{frame}{End of the lecture}
    329   For next time:
    330 
    331   \vspace{0.8cm}
    332   \begin{itemize}
    333     \item Install Latex on your PC
    334     \item Start writing something in Latex (e.g. homework)
    335     \item Email me if you have any question
    336   \end{itemize}
    337 \end{frame}
    338 
    339 \end{document}
    340