Workshop on LaTeX

17 downloads 0 Views 594KB Size Report
Jun 14, 2016 - Getting ready with the LATEX platform. Online: ShareLaTeX. Log-in with your credentials. Create a new blank project (this is similar to creating ...
Missing:
Workshop on LATEX Suresh Kumar Gadi FIME, Unidad Torre´ on, Universidad Aut´ onoma de Coahuila 14th June 2016

Plan for the workshop 1

Hour 1 Why and why not LATEX? Getting ready with the LATEX platform My first article with LATEX

2

Hour 2 Inserting images to the article Change the LATEX language Inserting tables to the article

3

Hour 3 Inserting mathematics into the article Making reference to figures, tables, equations etc.

4

Hour 4 Citing articles with the help of BIBTEX Very important commands Interesting stuff

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

2 / 33

Why LATEX? The advantages of LATEX

Advantages of LATEX

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

3 / 33

Why LATEX? The advantages of LATEX

Advantages of LATEX It is a free software. Available for most of the machines. Relatively easy to typeset (specially when mathematics is involved). Easy to handle large documents.

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

3 / 33

Why not LATEX? The disadvantages of LATEX

Disadvantages of LATEX

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

4 / 33

Why not LATEX? The disadvantages of LATEX

Disadvantages of LATEX A high level of LATEX understanding is required for handling unstructured documents. Using custom fonts is not straight forward. WYSIWYG(What You See Is What You Get) editors are not available. Some partial WYSIWYG are available (I do not recommend).

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

4 / 33

Getting ready with the LATEX platform Online: ShareLaTeX Log-in with your credentials. Create a new blank project (this is similar to creating a folder in a PC) “practice”. Getting familiar with the environment.

TeXLive installed on PC Create an empty folder, name it “practice”. Open TeXStudio, create a new document (“main.tex”) inside the newly created folder. Getting familiar with the environment. *A LATEX file is a normal text file with .tex extension. S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

5 / 33

My first article with LATEX A simplest LATEX document \documentclass{article}

\begin{document} Hello {\LaTeX} \end{document} The entire LATEX code can be divided into preamble and the document environment. Considering the convenience of the user, unlike the other software, Text does not require special notation whereas LATEX commands require special notation (i.e. \). S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

6 / 33

Application of curly brackets {} to contain text Find the difference between the following snippets.

Code 1 \documentclass{article} \begin{document} Hello {\LaTeX} user. \end{document}

Code 2 \documentclass{article} \begin{document} Hello \LaTeX user. \end{document}

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

7 / 33

Handling text encoding

Insert a random Spanish text with diacritic (accents) 1

Open Spanish Wikipedia page of Universidad Aut´onoma de Coahuila.

2

Copy first paragraph and insert in your document.

3

Compile and see the difference from the original text.

LATEX functions and importance of { } and [ ] \usepackage[utf8]{inputenc} In a LATEX function { } contains obligatory arguments, [ ] contains optional arguments. Make changes to the project “practice”

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

8 / 33

Sections and chapters More information from: https://www.sharelatex.com/learn/Sections_and_chapters https://en.wikibooks.org/wiki/LaTeX/Document_Structure

Document structure \part{part} % not in letters \chapter{chapter} % only books and reports \section{section} % not in letters \subsection{subsection} % not in letters \subsubsection{subsubsection} % not in letters \paragraph{paragraph} % not in letters \subparagraph{subparagraph} % not in letters Prepare a book with 2 parts, 4 chapters, 8 sections, 16 sub-sections, 32 sub-sub-sections and 64 paragraphs and 128 sub-paragraphs. Look into the folder/project ”sample001” for “Sample001.tex” and compile it. S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

9 / 33

Inserting images to the article

More information from: https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions

Open the project “practice” and do the following changes.

Required package (Add this to preamble) \usepackage{graphicx}

Simple integration (Add this to your document) \includegraphics[width=0.5\textwidth]{sample-image} The “sample-image” is an image file. I recommend the “EPS” file format. Sample images are available in the folder “images”.

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

10 / 33

Inserting figures to the article More information from: https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions

Required package (Add this to preamble) \usepackage{graphicx}

Simple integration (Add this to your document) \begin{figure} \caption{A random picture.} \centering \includegraphics[width=0.5\textwidth]{sample-image} \end{figure} Make sure there exist “sample-image.eps” in the same folder. Pay attention to the caption! What does it says? S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

11 / 33

Change the LATEX language

Open the folder/project “sample002” and compile “Sample002.tex”. Open the project “practice” and do the following changes.

Required package (Add this to preamble) \usepackage[spanish,mexico]{babel}

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

12 / 33

Inserting tables to the article

More information from: https://en.wikibooks.org/wiki/LaTeX/Tables https://www.sharelatex.com/learn/Tables

Open the project “practice” and add the following code to the document.

Simple integration (Add this to your document) \begin{tabular}{ c c c } cell1 & cell2 & cell3 \\ cell4 & cell5 & cell6 \\ cell7 & cell8 & cell9 \\ \end{tabular}

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

13 / 33

Centering and adding border lines to the table More information from: https://en.wikibooks.org/wiki/LaTeX/Tables https://www.sharelatex.com/learn/Tables

In the project “practice” change the table snippet to the following.

Simple integration (Add this to your document) \begin{center} \begin{tabular}{ | c | c \hline cell1 & cell2 & cell3 \\ cell4 & cell5 & cell6 \\ cell7 & cell8 & cell9 \\ \end{tabular} \end{center}

S. K. Gadi (FIME-UT, UAdeC)

| c |} \hline \hline \hline

LATEX workshop

June 14, 2016

14 / 33

A table with caption Simple integration (Add this to your document) \begin{table} \centering \caption{Table to test captions and labels} \begin{tabular}{||c c c c||} \hline Col1 & Col2 & Col2 & Col3 \\ \hline\hline 1 & 6 & 87837 & 787 \\ 2 & 7 & 78 & 5415 \\ 3 & 545 & 778 & 7507 \\ 4 & 545 & 18744 & 7560 \\ \hline \end{tabular} \end{table} S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

15 / 33

Inserting mathematics into the article

More information from: https://en.wikibooks.org/wiki/LaTeX/Mathematics

Different ways to insert math into a LATEX document Type LATEX shorthand TEX shorthand LATEX environment LATEX environment for equation array

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

Inline \( \) $ $ n/a n/a

Display \[ \] $$ $$ equation eqnarray

June 14, 2016

16 / 33

Inserting math inline with the text

LATEX shorthand El ´ area \( A \) de un c´ırculo es funci´ on de su radio \( r \) (el valor del a´rea es proporcional al cuadrado del radio, \( A = \pi rˆ2 \)).

TEX shorthand El ´ area $A$ de un c´ırculo es funci´ on de su radio $r$ (el valor del ´area es proporcional al cuadrado del radio, $A = \pi rˆ2$). Open the project “practice” and insert the above two blocks of text.

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

17 / 33

How to generate TEX code for my equation? I First preference: Google chrome extension “Daum Equation Editor” https://chrome.google.com/webstore/detail/ daum-equation-editor/dinfmiceliiomokeofbocegmacmagjhe

Second preference: Semi-interactive web tools http://www.hostmath.com/Default.aspx https://www.codecogs.com/latex/eqneditor.php http: //www.sciweavers.org/free-online-latex-equation-editor https://www.latex4technics.com/

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

18 / 33

How to generate TEX code for my equation? II

Character recognition based LATEX math symbols search http://detexify.kirelabs.org/classify.html

List of symbols (in the order of preference) http://tug.ctan.org/info/symbols/comprehensive/ symbols-letter.pdf https: //www.rpi.edu/dept/arc/training/latex/LaTeX_symbols.pdf https://www.sharelatex.com/learn/List_of_Greek_letters_ and_math_symbols

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

19 / 33

Inserting math in display mode I

LATEX shorthand Snippet El ´area \(A\) de un circulo es \[A = \pi rˆ2\] donde \(\pi\) es un constante y \(r\) el es radio del circulo.

Output El ´area A de un circulo es A = πr2 donde π es un constante y r el es radio del circulo.

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

20 / 33

Inserting math in display mode II

TEX shorthand Snippet El ´area $A$ de un circulo es $$A = \pi rˆ2$$ donde $\pi$ es un constante y $r$ el es radio del circulo.

Output El ´area A de un circulo es A = πr2 donde π es un constante y r el es radio del circulo.

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

21 / 33

Using mathematics environment “equation” environment \begin{equation} x=\frac { -b\pm \sqrt { { b }ˆ{ 2 }-4ac } \end{equation}

}{ 2a }

“eqnarray” environment \begin{eqnarray} x &=& \frac{-b\pm\sqrt{{b}ˆ{2}-4ac}}{2a}\\ &=& \frac{-b}{2a}\pm\frac{\sqrt{{b}ˆ{2}-4ac}}{2a} \end{eqnarray} *The above equations are generated with the help of “Daum Equation Editor”

The symbol (or keyword) “&” represents tabspacing and “\\” skips to the next equation. S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

22 / 33

Making reference to figures, tables, equations etc. The concept is to generate a unique key (\label{}) the environment you want to cite. It can be a section, part, chapter, figure, table, or equation etc. The unique key can be used to refer (\ref{}) at any point of the document.

Put a unique key in the figure environment \begin{figure} \centering \includegraphics[width=8cm]{sample-image-000} \caption{A random picture.} \label{AUniqueKey} \end{figure}

Use the command “\ref” to refer the label A random image is shown in Figure \ref{AUniqueKey}. S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

23 / 33

Use \autoref Include the package “hyperref” in the preamble \usepackage{hyperref} Make sure \usepackage{hyperref} is used after \usepackage[spanish,mexico]{babel}. Use \autoref{key} instead of \ref{key}.

Exercise (15 min maximum) Make an article of 3 sections with the first and the last sections containing 1 figure, 1 equation and 1 table. In the second section, write a text and refer the figures, sections, tables and equations. Use both \autoref and \ref to see the difference.

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

24 / 33

Use \autoref Include the package “hyperref” in the preamble \usepackage{hyperref} Make sure \usepackage{hyperref} is used after \usepackage[spanish,mexico]{babel}. Use \autoref{key} instead of \ref{key}.

Exercise (15 min maximum) Make an article of 3 sections with the first and the last sections containing 1 figure, 1 equation and 1 table. In the second section, write a text and refer the figures, sections, tables and equations. Use both \autoref and \ref to see the difference.

Result For the result look into the project sample003. S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

24 / 33

Making reference equations

Different ways to refer an “equation” Command \ref{} \autoref{} \eqref{}

Required package None hyperref amsmath

Expected output 1 Equation 1 (1)

Practice: Observe the difference Compile the project sample004.

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

25 / 33

Citing articles with the help of BIBTEX

Creating a BIBTEX database BIBTEX database is nothing but a text file with the extension .bib and the BIBTEX content. More information on: https://en.wikipedia.org/wiki/BibTeX http://www.bibtex.org/ https://en.wikibooks.org/wiki/LaTeX/Bibliography_Management https://en.wikibooks.org/wiki/LaTeX/More_Bibliographies

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

26 / 33

BIBTEX content Sample BIBTEX content @article{einstein1905electrodynamics, title={On the electrodynamics of moving bodies}, author={Einstein, Albert and others}, journal={Annalen der Physik}, volume={17}, number={10}, pages={891--921}, year={1905} } In the above sample entry the tern “einstein1905electrodynamics” is the BIBTEX key for the entry. BIBTEX key should be unique. We will use this key to cite the corresponding entry. S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

27 / 33

How to obtain BIBTEX content

Sources of BIBTEX content Make yourself with the guidelines of https://en.wikipedia.org/wiki/BibTeX Google scholar Endnote allows to exporting all entries in the BIBTEX format

Exercise (15 min maximum) Create a new project folder with following files. Create a BIBTEX database with 10 entries. Name it refs.bib Create an article with 5 paragraphs.

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

28 / 33

Using the BIBTEX content in LATEX Insert the following code at the end of your LATEX just before “\end{document}” \bibliographystyle{unsrt} \bibliography{refs}

How to cite? \cite{}

Exercise (10 min maximum) To the previous project, insert 2 citations per paragraph and compile to see the result.

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

29 / 33

Using the BIBTEX content in LATEX Insert the following code at the end of your LATEX just before “\end{document}” \bibliographystyle{unsrt} \bibliography{refs}

How to cite? \cite{}

Exercise (10 min maximum) To the previous project, insert 2 citations per paragraph and compile to see the result.

Result Compile the project sample005. S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

29 / 33

Show the bibliography in the APA format.

Add the following to the preamble \usepackage{apacite}

Replace “unsrt” with “apacite” \bibliographystyle{apacite}

Exercise Convert the IEEE style to APA for the previous exercise’s document.

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

30 / 33

Very important LATEX commands Search for these commands over the Internet Type Command Environment Environment Package Command Package

Command \maketitle itemize enumirate siunitx \mbox fullpage

Associated commands \author, \title, \date, etc. \item \item \si, \SI, \num, \SIrange, etc. None Options cm, in etc.

Sample code The above mentioned commands are used in the sample project sample005. Compile and look for yourself.

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

31 / 33

Interesting stuff

Some of the interesting stuff, we can do with LATEX Make a template to suit our needs. Mail-merge application.

Sample code The above mentioned applications are demonstrated in the sample projects sample007 and sample008.

S. K. Gadi (FIME-UT, UAdeC)

LATEX workshop

June 14, 2016

32 / 33

Thank you for your attention.