Intro to LaTeX Made in LaTeX

36
Intro to L A T E X Made in L A T E X Bennett Petzold LUG @ NC State October 19, 2021

Transcript of Intro to LaTeX Made in LaTeX

Page 1: Intro to LaTeX Made in LaTeX

Intro to LATEXMade in LATEX

Bennett Petzold

LUG @ NC State

October 19, 2021

Page 2: Intro to LaTeX Made in LaTeX

Outline

Background

Why LATEX?

Engines

Basic Input

Packages

Installation and Tools

latexmk

Tips and Tricks

Resources

Bennett Petzold LATEX 1 / 35

Page 3: Intro to LaTeX Made in LaTeX

BackgroundPronunciationHistory

Bennett Petzold LATEX 2 / 35

Page 4: Intro to LaTeX Made in LaTeX

Pronunciation (Background)

• Pendants care• The ”X” in TEX is chi.

• Technically a ”voiceless velar fricative”• Correct: ”tech” as in ”technology”• Incorrect: ”tex” as in ”Texas”

• LATEX• Correct: ”Ell A tech”• Correct: ”Lah tech”

Bennett Petzold LATEX 3 / 35

Page 5: Intro to LaTeX Made in LaTeX

History (Background)

• TEX• Donald E. Knuth• Started in 1977• Completed 1989

• LATEX• Lesile Lamport• Manual published in 1986• Given to Frank Mittelbach in 1989• LaTeX2e released 1994

Bennett Petzold LATEX 4 / 35

Page 6: Intro to LaTeX Made in LaTeX

Why LATEX?Text FilesFOSSAestheticsFlaws

Bennett Petzold LATEX 5 / 35

Page 7: Intro to LaTeX Made in LaTeX

Text Files (Why LATEX?)

• Written in plaintext .tex files• Your favorite utilities work

• Scriptable• Declared via text, not menu• Inline comments• Split lines for easy editing• Multiple files

Bennett Petzold LATEX 6 / 35

Page 8: Intro to LaTeX Made in LaTeX

FOSS (Why LATEX?)

• Free• Can contribute/modify• Syntax always valid• Clearly documented

Bennett Petzold LATEX 7 / 35

Page 9: Intro to LaTeX Made in LaTeX

Aesthetics (Why LATEX?)

• Looks nice• Can micromanage• Can just trust default

Bennett Petzold LATEX 8 / 35

Page 10: Intro to LaTeX Made in LaTeX

Flaws (Why LATEX?)

• Niche• Have to read the manual• Syntax errors• Compilation time

Bennett Petzold LATEX 9 / 35

Page 11: Intro to LaTeX Made in LaTeX

EnginespdfTexXeTeXLuaTeX

Bennett Petzold LATEX 10 / 35

Page 12: Intro to LaTeX Made in LaTeX

pdfTex (Engines)

• Hàn Thế Thành• August 2001• Extended from e-TeX• Direct PDF output• Typesetting improvement• Needs fontenc and inputenc packages for Unicode

Bennett Petzold LATEX 11 / 35

Page 13: Intro to LaTeX Made in LaTeX

XeTeX (Engines)

• Jonathan Kew• 2004 on MacOS X• UTF-8• Any fonts installed on OS• More font control• Reliant on OS

Bennett Petzold LATEX 12 / 35

Page 14: Intro to LaTeX Made in LaTeX

LuaTeX (Engines)

• Oriental TeX project• 2006 start• 1.0 released 2016• Internals accessible from Lua• UTF-8• System fonts• Default for ConTeXt

Bennett Petzold LATEX 13 / 35

Page 15: Intro to LaTeX Made in LaTeX

Basic InputSyntaxPreambleTextMath

Bennett Petzold LATEX 14 / 35

Page 16: Intro to LaTeX Made in LaTeX

Syntax (Basic Input)

• Every macro starts with \• Free space after a macro is ignored• % is for comments• Commands: macros, made up of TeX syntax and/or other

macros• Some have parameters, some don’t

• Environments: commands in two halves

\command[optional parameters]{required parameter}

\begin{environment}[optional parameters]{required parameter}

% Inside environment

\end{environment}

Bennett Petzold LATEX 15 / 35

Page 17: Intro to LaTeX Made in LaTeX

Preamble (Basic Input)

\documentclass[options]{type}

% Package Declarations

% (Optional) Command and Environment Declarations

% (Optional) Setting Declarations

\begin{document}

% Text

\end{document}

• Document Options• 10pt, 11pt, 12pt• a4paper, letterpaper• draft• oneside, twoside• notitlepage, titlepage

• Document Types• article• report• book

Bennett Petzold LATEX 16 / 35

Page 18: Intro to LaTeX Made in LaTeX

Text (Basic Input)\\

\textbackslash

\ % space afterwards

\vspace{[amount]}

\hbar

\emph{text}

\textbf{text}

\title{}

\author{}

\maketitle

\section{}

\subsection{}

\tableofcontents

\begin{center} \emph{Words}

Extra words

\textbf{more words} \end{center}

Words extra wordsmore words

Bennett Petzold LATEX 17 / 35

Page 19: Intro to LaTeX Made in LaTeX

Math (Basic Input)

$ $ % TeX In-line

\( \) % LaTeX In-line

\[ \] % LaTeX Displayed Math

\begin{equation} \end{equation} % amsmath

^ % Caret/Circumflex

_ % Underscore

\big % Also \Big, \bigg, and \Bigg

\left( \right)

\frac{numerator}{denominator}

\omega

\[ \left[ \frac{\omega}{2} \right] \Big\vert_{10}^{26} \][ω2

] ∣∣∣2610

Bennett Petzold LATEX 18 / 35

Page 20: Intro to LaTeX Made in LaTeX

PackagesGeneralFontsSpecialized

Bennett Petzold LATEX 19 / 35

Page 21: Intro to LaTeX Made in LaTeX

General (Packages)

\usepackage[options]{name}

• microtype• amsmath• TikZ• minted• graphicx

\includegraphics[width=\textwidth]{filename}

• biblatex

\addbibresource{file}

\cite{name}

Bennett Petzold LATEX 20 / 35

Page 22: Intro to LaTeX Made in LaTeX

Fonts (Packages)

\usepackage[options]{name}

• lmodern, etc• fontspec

• Only LuaTeX or XeTeX• main, mono, and sans fonts

\setmainfont[options]{name}

\setmonofont[options]{name}

\setsansfont[options]{name}

Bennett Petzold LATEX 21 / 35

Page 23: Intro to LaTeX Made in LaTeX

Specialized (Packages)

\usepackage[options]{name}

• geometry• nopageno• pdfpages• tabularx• CircuiTikZ• Almost anything you can think of…

Bennett Petzold LATEX 22 / 35

Page 24: Intro to LaTeX Made in LaTeX

Installation and ToolsTeX LiveEditorsCompiling

Bennett Petzold LATEX 23 / 35

Page 25: Intro to LaTeX Made in LaTeX

TeX Live (Installation and Tools)

• Sebastian Rahtz and TEX users groups• 1996• Free software• Everything you need for LATEX• LaTeX2e, pdfTex, XeTeX, LuaTeX, packages, latexmk• In most package managers at various sizes

Bennett Petzold LATEX 24 / 35

Page 26: Intro to LaTeX Made in LaTeX

Editors (Installation and Tools)• Overleaf

• Online, like a Google Doc• TexStudio

• Word-like• LyX

• WYSIWYM• TeXworks

• auto-sync PDF Viewer• Vim

• latex-suite• Graphical and monolithic

• vimtex• Minimal, use snippets engine

• Emacs• AUCTeX

Bennett Petzold LATEX 25 / 35

Page 27: Intro to LaTeX Made in LaTeX

Compiling (Installation and Tools)

pdftex file.tex

make

latexmk file.tex

• Direct Engine Calls• May need multiple calls• Not very automated• When called without argument, compiles every tex file

• Make• Wrap around engine calls• If using -j, make sure files aren’t shared• Clean target!

• latexmk• Perl wrapper script• Runs as many times as necessary; calls auxiliary programs• -pdf, -pdflua, -pdfxe

Bennett Petzold LATEX 26 / 35

Page 28: Intro to LaTeX Made in LaTeX

latexmklatexmk optionslatexmkrclatexmkrc Example

Bennett Petzold LATEX 27 / 35

Page 29: Intro to LaTeX Made in LaTeX

latexmk options (latexmk)• -pvc compiles continuously and previews• -outdir=[dir] outputs to directory dir

• N.B. Output goes to directory latexmk is run in, by default.• -c cleans all created files but output• -C cleans all created files• -deps gives a list of dependent files• -jobname=[name] uses a different job name• -pdflatex=”[command]” sets pdflatex to that command

• e.g. -pdflatex=”pdflatex -shell-escape”• -lualatex=”[command]”• -xelatex=”[command]”

• -quiet/-silent• -time• -shell-escape• Exit on the command line is ”X<CR>”

Bennett Petzold LATEX 28 / 35

Page 30: Intro to LaTeX Made in LaTeX

latexmkrc (latexmk)• $preview_mode = [number];

• 0 = no pdf, 2 = ps2pdf, 3 = dvipdf• 1 = pdflatex• 4 = lualatex• 5 = xelatex

• $pdftex = [command]• $lualatex = [command]• $xelatex = [command]

• @default_files = ([files])• $dvi_previewer = ”start [program]”• $emulate_aux = [0 or 1]• $out_dir$ = [dir]• $aux_dir$ = [dir]• $preview_continuous_mode = [0 or 1]

Bennett Petzold LATEX 29 / 35

Page 31: Intro to LaTeX Made in LaTeX

latexmkrc Example (latexmk)

Global latexmkrc

$pdf_previewer = 'start zathura';

$pdf_mode = 1;

Project latexmkrc

$pdf_mode = 4;

$lualatex = "lualatex --shell-escape";

Bennett Petzold LATEX 30 / 35

Page 32: Intro to LaTeX Made in LaTeX

Tips and TricksCustom MacrosCustom Macro ExamplesMultiple Files

Bennett Petzold LATEX 31 / 35

Page 33: Intro to LaTeX Made in LaTeX

Custom Macros (Tips and Tricks)• Commands

• The name must be \name, not name• 9 parameters max• parameters used as #1, #2, etc.• default is optional. Provides default value for #1.• Calling the command inserts the code in braces

\newcommand{\name}[num arguments][default]{#1 text}

\renewcommand{\name}[num arguments][default]{#1 text}

• Environment• The name cannot have a backslash• Same parameter rules as commands• Inserts first braces at \begin• Inserts second braces at \end

\newenvironment{name}[num arguments][default]{#1 text}{ending text}

\renewenvironment{name}[num arguments][default]{#1 text}{ending text}

Bennett Petzold LATEX 32 / 35

Page 34: Intro to LaTeX Made in LaTeX

Custom Macro Examples (Tips and Tricks)

\newenvironment{slide}[1]

{ \begin{frame}[fragile, environment=slide]

\frametitle{#1}

\vfill }

{ \vfill

\end{frame} }

\renewenvironment{slide}[1]

{ \subsection{#1}

\begin{frame}[fragile, environment=slide]

\frametitle{\subsecname \hfill (\secname )}

\vfill }

{ \vfill

\end{frame} }

\newcommand{\newsec}[1]

{ \section{#1}

\begin{frame}

\vfill

\begin{Large}

\tableofcontents[sectionstyle=show/hide, subsectionstyle=show/show/hide]

\end{Large}

\vfill

\end{frame} }

Bennett Petzold LATEX 33 / 35

Page 35: Intro to LaTeX Made in LaTeX

Multiple Files (Tips and Tricks)

• \include{file}• \includeonly{files}

• Preamble or command line• Starts a new page and processes file contents• Independent .aux files (auxillary information)• Cannot be nested

• \input{file}• Directly processes file contents

Bennett Petzold LATEX 34 / 35

Page 36: Intro to LaTeX Made in LaTeX

Resources

• TeX Live: http://tug.org/texlive/• Math Symbols (OEIS): https://oeis.org/wiki/List_of_LaTeX_mathematical_symbols

• Overleaf Documentation:https://www.overleaf.com/learn

• CTAN: https://www.ctan.org/• LATEX Wikibooks:https://en.m.wikibooks.org/wiki/LaTeX

• TEX FAQ: https://texfaq.org/• TEX Stack Exchange: https://tex.stackexchange.com/• Latexmk:http://personal.psu.edu/~jcc8/software/latexmk/

Bennett Petzold LATEX 35 / 35