Latex workshop

57
Text Editing Using LaTeX Dr. Aisha Abdulahi 02/24/2022 1

Transcript of Latex workshop

05/02/2023 1

Text Editing Using LaTeX

Dr. Aisha Abdulahi

05/02/2023 2

Outlines

■ Introduction■Writing the First Document■Text Formatting■Figures■Tables■Bibliography■Arabic Text■References

05/02/2023 3

What is LaTeX?

■TeX is a computer program created by Donald E. Knuth, 1979.

■Last update was released on 12/01/2014, version number = 3.14159265

■ ‘Technology’ stems from a Greek root Tex; and this same Greek word means art as well as technology.

05/02/2023 4

What is LaTeX?

■LaTeX is a macro package that enables authors to typeset and print their work at the highest typographical quality, using a predefined, professional layout using TeX engine.

■Originally written by Leslie Lamport.

■LaTeX is pronounced in English as “Lay-tek” or “Lah-tek”.

05/02/2023 5

Installing LaTeX■ LaTeX-Core, in windows MiKTeX is one of the most commonly used.

http://ctan.mirror.garr.it/mirrors/CTAN/systems/win32/miktex/setup/basic-miktex-2.9.6161-x64.exe■ Basic installation, you need to install packages as you go (e.g. the above link).■ Complete installations, installs everything, all at once.■ The editor, where you write your document

we will use, TeXstudio

https://sourceforge.net/projects/texstudio/files/texstudio/TeXstudio%202.11.2/texstudio-2.11.2-osx-qt5.6.zip/download■ There are similar software for Mac, and Linux based OS.

05/02/2023 6

Why LaTeX? Advantages

■Separation of formatting and content■Free, and Open Source■Made for scientists■Built-in referencing capability■Speed■Portable■Reliability

05/02/2023 7

First Document in LaTeX

\documentclass{article}

\begin{document}

Hello World! Hello \LaTeX.

\end{document}

Latex Output

05/02/2023 8

Files in LaTeX

Input.tex Latex input file. Can be compiled with latex

.sty Style Macros in LaTeX, can be loaded using \usepackage

System

.log Gives a detailed account of the last compiler run.

.aux Transports information from one compiler run to the next, and stores cross-references information.

Output

.dvi Device Independent File, viewed DVI previewer

.ps .pdf

05/02/2023 9

Files in LaTeX

05/02/2023 10

LaTeX Document Structure\documentclass To define the document type

preamble

\author{},\title{},\date{} To store the author, the title, and the date

\usepackage To extend latex beyond its basic functionality.

New command To write document\begin{document}\frontmatter Before the real content, Latin numbering\mainmatter The content, and in Arabic numbering\backmatter Contains appendices, bibliography, letter

numbering, \end{document}

article For articles in scientific journals, presentations, short reports, program documentation, invitations, ...

IEEEtran For articles with the IEEE Transactions format.

proc A class for proceedings based on the article class.

report For longer reports containing several chapters, small books, thesis, ...

book For real books.

slides For slides. The class uses big sans serif letters.

memoir For changing sensibly the output of the document. It is based on the book class, but you can create any kind of document with it.

letter For writing letters.

beamer For writing presentations.

05/02/2023 11

\documentclass[options]{class}

05/02/2023 12

\documentclass[options]{class}

10pt, 11pt, 12pt size of the main font, default is 10pt.

a4paper,.. Defines the paper size.

twocolumn two columns instead of one.

twoside, oneside Specifies whether double or single sided output should be generated.

landscape Changes the layout of the document to print in landscape mode.

Example\documentclass[12pt,a4paper,oneside, lanscape]{report}

05/02/2023 13

Document Title

\documentclass{article}\author{Aisha Abdulahi}\title{Text Editing using \LaTeX Workshop}\date{December 13, 2016}\begin{document}\maketitleHello World! Hello \LaTeX.\end{document}

Latex Output

Use \maketitle command

05/02/2023 14

Packages

■\usepackage[options]{package}■Options are additional information to the package

Package Usagegraphicx Allows you to insert graphic files within a document.

xcolor Adds support for colored text.listings To insert programming code within the document.

arabtex,babel

For Arabic language support.

05/02/2023 15

Parts, Chapters, Sections, and the Table of Contents

\section{…} Heading 1

\subsection{…} Heading 1.1

\subsubsection{…} Heading 1.1.1

\parts{…} To split the document in parts without influencing the section or chapter numbering

\chapter{…} With the report or book document classes, adds additional top-level sectioning.

To generate the Table of Contents, use \tableofcontents command!

05/02/2023 16

Abstract

\documentclass{article}

\begin{document}

\begin{abstract}

Your abstract goes here...

\end{abstract} ...

\end{document}

Latex

05/02/2023 17

Units in LaTeX

Unit Description

pt A point, is the default length unit. About 0.3515mm

mm a millimetre cm a centimetre in an inch ex the height of an x in the current font em the width of an m in the current font

05/02/2023 18

Units in LaTeX - Relative

Relative Unit Description

\columnwidth width of the column

\linewidth width of the line in the current environment

\paperwidth width of the page

\paperheight height of the page

\textwidth width of the text

\textheight height of the text

05/02/2023 19

Font Sizes

\tiny{text} \normalsize{text} \huge{text}

\scriptsize{text} \large{text} \Huge{text}

\footnotesize{text} \Large{text}

\small{text} \LARGE{text}

Latex chooses the appropriate font and font size based on the logical structure. In some cases, you may want to set fonts and sizes by hand.

05/02/2023 20

Font Families

Font Family Command

Serif (roman) \textrm{text}

Sans Serif \textsf{text}

Typewriter \texttt{text} Serif (Left), Sans (Right), while typewriter is the font similar to code fonts and typewriters.

05/02/2023 21

Font Styles

Format CommandItalic \textit{text}.Bold \textbf{text}.Underline \underline{text}Emphasized \emph{text}

05/02/2023 22

Paragraph

■A paragraph is specified in LaTeX using– Blank line– \par– \begin{paragaraph}

paragraph text \end{paragraph}

05/02/2023 23

Paragraph Formatting –Line Spacing

■ \baselineskip minimum space between two successive lines in a paragraph; may be changed (in the preamble) using\setlength{\baselineskip}{value}

■ \linespread{value}

Value Line spacing1.0 single spacing

1.3 one-and-a-half spacing

1.6 double spacing

05/02/2023 24

Paragraph Formatting

■ \setlength{\parindent}{4em}

■ \setlength{\parskip}{1em}

■Both in the preamble area before \begin{document}

05/02/2023 25

Paragraph Formatting – Text Alignment

Alignment

Command Commnd 2

Left \begin{flushleft} paragraph \end{flushleft} \raggedright

Right \begin{flushright} paragraph \end{flushright} \raggedright

Centre \begin{center} paragraph \end{center} \centering

Justified It’s the default in LaTeX \justify

05/02/2023 26

Lists in LaTeX

Bullet points

\begin{itemized} \item \item \item\end{itemized}

Numbering

\begin{enumerate} \item \item \item\end{enumerate}

05/02/2023 27

Footnotes

■ \footnote{text in the footnote}■ To change the default number– \footnote[10]{text in the footnote}■ To separate the footnote mark, and the text– \footnotemark– \footnotetext{text}■ Multiple references for the same footnote– \footnotemark[\value{footnote}]

05/02/2023 28

Footnotes – Numbering Style

■ \renewcommand{\thefootnote}{\roman{footnote}}

Style Descriptionarabic Arabic numerals.

roman Upper case Roman numerals.

alph Alphabetic lower case.

Alph Alph Alphabetic upper case.

fnsymbol A set of 9 special symbols.

05/02/2023 29

Page Header/Footer

■ It is mostly used in \documentclass{book}■ To change the style

\pagestyle{myheadings}plain Both the header and footer are cleared (blank) in this page

style.

myheadings footer is empty, header contains the page number on right side (on even pages) or on left side (on odd pages) + user-supplied information; first page of each chapter, footer contains centred page number, header is blank.

empty This is the default style. The header is empty and the footer contains page numbers in the centre.

05/02/2023 30

Page Header/Footer

■ \usepackage{fancyhdr}

\pagestyle{fancy} Sets the fancy header style.

\fancyhf{} clears the header and footer.

\rhead, \chead, \lhead Prints the text included inside the braces on the (right, center, left) side of the header.

\rfoot, \cfoot, \lfoot Prints the text included inside the braces on the (right, center, left) side of the footer.

05/02/2023 31

Figures in LaTeX

■\usepackage{graphicx}■For a separate images directory\graphicspath{ {images/} } makes referencing easier.■ More than one path \graphicspath{{images1/}{images2/}}■ If no path is set LATEX will look for pictures in the folder where

the .tex file is saved.

05/02/2023 32

Figures in LaTeX

■ \includegraphics[options]{imagefile}

width=xx width of the imported image to xx.height=xx height of the imported image to xx.

keepaspectratio scale the image according to both height and width [true/false]

scale=xx Scales the image by the desired factor. angle=xx rotates the image by xx degrees

trim=l b r t crops the image [left, bottom, right, top]

resolution=x Specify image resolution in dpi

05/02/2023 33

Figure Caption & Position

■ To add a caption to the figure or to change the alignment

\begin{figure}[h] \includegraphics[options]{image filename} \caption{text} \end{figure}■ To specify the alignment of the image use \centering, \

raggedright, \raggedleft

05/02/2023 34

Wrapping a Figure

■ To insert your figure within the text, \usepackage{wrapfig}\begin{wrapfigure}{x}{y}

\includegraphics[options]{logo}\caption{text}

\end{wrapfigure}■ x: defines the alignment of the figure, (l: left, r: right, etc.)■ y: the width of the figure box. It's not the width of the image itself!

05/02/2023 35

Referencing Figures, List of Figures

■Add \label{fig:figurename} to the previous figure command.

■\ref{fig:figurename} within the referring text.

■Finally, to generate the list of figures, use \listoffigures.

05/02/2023 36

Tables in LaTeX\begin{tabular}{||c c c c||}

\hlineCol1 & Col2 & Col2 & Col3 \\ [0.5ex] \hline\hline1 & 6 & 87837 & 787 \\ 2 & 7 & 78 & 5415 \\5 & 88 & 788 & 6344 \\ [1ex] \hline

\end{tabular}

No of columns, and Vertical borders

Horizontal Borders

Cell height

05/02/2023 37

Table Caption, Referencing, and List of Tables

\begin{table}[h]<Table Design>\caption{text}

\end{table}■Add \label{table:1} to the previous command.■\ref{table:1}, within the referring text.■ \listoftables command to generate the list of table for

the document.

05/02/2023 38

Mathematical Expressions

05/02/2023 39

Mathematical Expressions

05/02/2023 40

Mathematical Expressions

MathematicalEnvironments Inline

\( \), $ $ \begin{math}

\end{math}

Display Numbered \begin{equation}

\end{equation}

Unnumbered \[ \], $$ $$, \begin{displaymath} \end{displaymath}

05/02/2023 41

Subscript & Superscript

■The underscore, _, is used to indicate a subscripted text.

■^ is used to indicate a superscripted text.

■If the expression is of more than one letter, use {} to enclose it.

05/02/2023 42

Brackets and Parentheses

Dynamic Resizing■ \[

\left\{ \begin{tabular}{ccc} 1 & 5 & 8 \\0 & 2 & 4 \\3 & 3 & -8 \end{tabular}\right \} \]

Manual Resizing

05/02/2023 43

Fractions and Bionomials

■ \frac{numerator}{denominator}for fractions

■ \bionom{n}{k}, for bionomials■ You need to \usepackages{amsmath}■ Example\[\binom{n}{k} = \frac{n!}{k!(n-k)!}\]

05/02/2023 44

Bibliography in LaTeX

■Embedded System

Writing few documents

Not planning to write more on the same subject.

No need then to create a database of references you are never going to use.

■BibTex best way to manage references in LaTeX

05/02/2023 45

Embedded System

■The bibliography environment\bibliographystyle{plain}\begin{thebibliography}[n]\bibitem{citekey} the list of information\end{thebibliography}

N: pattern for no. of references, [9] means 9 references or less.■There are many other styles in latex, see the next Table.

05/02/2023 46

Bibliography Styles in LaTeX

Style Name Author Name Format

Reference Format Sorting

unsrt Homer Jay Simpson #ID# as referenced

plain Homer Jay Simpson #ID# by author

alpha Homer Jay Simpson Sim95 by author

acm Simpson, H. J. #ID#

abbrv H. J. Simpson #ID# by author

There other styles in BibTex, and with NatBib package

05/02/2023 47

Bibliography Styles in LaTeX

■To cite a reference use \cite{citekey}citekey has to be unique

■Usually set to the author's surname, followed by the year of publication

■\nocite, \nocite{*}

05/02/2023 48

Embedded System

Citation

Instead of WYSIWYG editors, typesetting systems like \TeX or \LaTeX \cite{lamport94} can be used.

Bibliography

\bibliographystyle{plain}\begin{thebibliography}{9}

\bibitem{lamport94} Leslie Lamport, Document preparation system, Addison Wesley,Massachusetts,2nd edition,1994.

\end{thebibliography}

Latex

05/02/2023 49

Embedded System

Output

05/02/2023 50

BibTeXBook Conference Paper Journal Article@book{Xbook, author = "", title = "", publisher = "", volume = "", number = "", series = "", address = "", edition = "", year = "XXXX", month = "", note = "", }

@conference{Xconference, author = "", title = "", booktitle = "", editor = "", volume = "", pages = "", address = "", year = "XXXX", month = "", publisher= "", note = "", }

@article{Xarticle, author = "", title = "", journal = "", volume = "", number = "", pages = "", year = "XXXX", month = "", note = "", }

There are other standard templates such as, @phdthesis, @misc., and othersRefer to https://en.wikibooks.org/wiki/LaTeX/Bibliography_Management

05/02/2023 51

Using the .bib File

■ For a bib file named: file.bib■ Use \bibliography{file, file2, …}■ You shouldn’t include the file extension■ If it is in different folder use:

use \bibliography{/some/where/file}

or \bibliography{../file} if it is in the parent directory.■ Adding the bib file adds an extra complexity to the latex document,

now you need to clean the directory, and execute the code twice.

05/02/2023 52

BibTeX Referencing Software

■There are many applications that simplify the work of BibTeX, such as JabRef.

■You can download it from herehttps://www.fosshub.com/JabRef.html

■Tutorial for using JabRefhttp://www.cs.rpi.edu/~tayloj/JABREF.TUTORIAL/

05/02/2023 53

Arabic Text in LaTeX

\usepackage[utf8]{inputenc} Input encoding, allows for many different languages.

\usepackage[LFE,LAE]{fontenc} Supports specific characters for Arabic language.

\usepackage{arabtex} Supports right-to-left writing.

\usepackage[arabic]{babel} Proper hyphenation and translating the names of the document elements.

05/02/2023 54

الاليتاك باستخدام بالعربية عنوان صفحة\documentclass[11pt,a4paper]{report}\usepackage{arabtex}\usepackage[utf8]{inputenc}\usepackage[LFE,LAE]{fontenc}\usepackage[arabic]{babel}\title{ النصوص تحرير في تدريبية دورة

الاليتاك {باستخدام\author{ الله. عبد عائشة {د \begin{document}\maketitle\end{document}

Latex

Output

05/02/2023 55

A Published Paper – An Example

■Show the different document classes– \documentclass{article}– \documentclass{report}– \documentclass{proc}

■References, styles

05/02/2023 56

References

■https://en.wikibooks.org/wiki/LaTeXAn ebook that is featured on Wikibooks because it contains substantial content, it is well-formatted, and it is regularly updated.

■https://www.sharelatex.com/learnA great LaTeX knowledge base, the website is home for a great online editor.

05/02/2023 57

CONVERTING?I hope you so!