introduction to l a t ex
play

Introduction to L A T EX Writing papers the right way Cheng XU - PowerPoint PPT Presentation

This work is licensed under a Creative Commons Attribution 4.0 International license. Get source of this slides and example document from https://github.com/xu-cheng/latex-tutorial . Introduction to L A T EX Writing papers the right way


  1. This work is licensed under a Creative Commons “Attribution 4.0 International” license. Get source of this slides and example document from https://github.com/xu-cheng/latex-tutorial . Introduction to L A T EX Writing papers the right way Cheng XU September 26, 2019 cb

  2. Contents 1. Getting Started with L A T EX 2. A Basic Document 3. Typesetting Text 4. Advanced Usages 1/55

  3. Getting Started with L A T EX

  4. Introduction • L A T EX is a document preparation system and document markup language. • It can be used to typeset articles, books, slides, posters, even graphics. • It separates presentation/format from contents. • Since the source codes are plaintext, it works well with version control system such as git. • Highly customizable through various of packages. • There is no graphic interface to support WYSIWYG style editing. • Not suitable to produce unstructured documents. 2/55 • Pros: • Cons:

  5. Installation • MacTeX http://www.tug.org/mactex/ It is recommended to uninstall the old version and install the new version annually. • TeXLive/MacTeX release major updates around May each year. brew cask install mactex # Install MacTeX ruby -e " $( curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install ) " # Install Homebrew • Or install through Homebrew ( https://brew.sh ) • Mac • Windows/Linux • Offmine ISO fjle: http://mirror.ctan.org/systems/texlive/Images/ http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz • Linux http://mirror.ctan.org/systems/texlive/tlnet/install-tl-windows.exe • Windows • Online installer: • TeXLive https://www.tug.org/texlive/ 3/55

  6. L • Grammarly https://github.com/znck/grammarly • https://www.texstudio.org • TeXstudio • AUCTeX https://www.gnu.org/software/auctex • https://www.gnu.org/s/emacs • Emacs • Vimtex https://github.com/lervag/vimtex • https://www.vim.org | https://neovim.io • Vim/Neovim • Code Spell Checker https://github.com/streetsidesoftware/vscode-spell-checker A • LaTeX Workshop https://github.com/James-Yu/LaTeX-Workshop • https://code.visualstudio.com EX source codes are plaintext. So you can use any editor you like. T A • L EX editor T 4/55 • Visual Studio Code [Recommend]

  7. Overleaf • Overleaf ( https://www.overleaf.com/ ) is a online, collaborative LaTeX editor • Free for personal use • $15/month to share project among up to 10 collaborators 5/55

  8. A Basic Document

  9. Hello, L A EX Project in VSCode A T Compile L • Open hello.pdf to preview the result latexmk -pdf hello • OR using command line: EX editor/IDE T • Click the build button in your L A T • Compile it \end {document} Hello, \LaTeX ! \begin {document} \documentclass {article} % this is hello.tex • Create hello.tex fjle with following content. EX! 6/55

  10. Example of A Complex Document • Download the source code from https://github.com/xu-cheng/latex-tutorial/archive/master.zip • main.tex The main tex source • preamble.tex A subfjle to store format defjnitions • tikz-example.tex A fjgure drawn using tikz • ref.bib A database of references • Access the same example in Overleaf: https://www.overleaf.com/read/qsthqbjphhrz 7/55 • The example document is located in the example folder. It contains: • Use latexmk -pdf main to compile the document

  11. Comment, Command and Environment • \begin {envname}[opt arg]{arg} \end {envname} \begin {envname}{arg} \end {envname} % LaTeX environment can take arguments \end {envname} inside the environment \begin {envname} \begin {} ... \end {} denotes an environment \command [opt arg]{arg} % [] is for optional argument • \command {arg1}{arg2} % a command with multiple arguments \command {arg} % a command with an argument \command {} % also a command \command % a command \ starts a command. • % starts a comment. e.g. % this is hello.tex 8/55

  12. Source File Structure fleqn Makes chapters begin either only on right hand pages or on the next page available. openright, openany Changes the layout of the document to print in landscape mode. landscape Specifjes whether double or single sided output should be generated. twoside, oneside Typeset the document in one column or two columns. onecolumn , twocolumn Specifjes whether a new page should be started after the document title or not. titlepage , notitlepage Places the numbering of formulae on the left hand side instead of the right. leqno Typesets displayed formulae left-aligned instead of centred. Defjnes the paper size. • A document starts with \documentclass {...} command to specify the template a4paper , letterpaper , … Set font size. 10pt , 11pt , 12pt Class Options for article , report , book , letter • IEEEtrans (IEEE template) • acmart (ACM template) • standalone (graphics) • beamer (slides) • letter • report • book • article • Common templates include: 9/55 • Template class can accept options, e.g. \documentclass [a4paper,10pt]{article}

  13. Source File Structure • The region after \documentclass and before \begin {document} is called preamble. • You can load packages and defjne format of the document here, • Package can be loaded with options, e.g. \usepackage [style=ieee]{biblatex} • To fjnd the package document: • http://www.texdoc.net • Finally, \end {document} denotes the end of the document. 10/55 e.g. \usepackage {amsmath} • Run texdoc <pkg_name> in command line • You start the body of the text with \begin {document} .

  14. Typesetting Text

  15. Syntax after a word. \\ or \newline starts a new line without starting a new paragraph. • graph. An empty line starts a new para- word. enter one or several spaces after a It does not matter whether you paragraph. An empty line starts a new spaces • The main body of L you enter one or several It does not matter whether It starts a new paragraph after empty lines. EX treats contiguous spaces or a single linebreak as a single space. T A • L EX code is plain text. A T 11/55

  16. Special Characters and Symbols • Certain characters are reserved, you need to use escape command to typeset them. • Use \ldots instead of ... to typeset ellipsis, e.g. a, b, c, … • minus sign : --- , e.g. yes—or no? • em-dash : -- , e.g. Pages 1–10 • en-dash : - , e.g. part-time • hyphen : • There are four kinds of dashes `text' and ``text'' typeset ‘single quoted text’ and “double quoted text” • # $ % ^ & _ { } ~ \ \textbackslash \# \$ \% \^ {} \& \_ \{ \} \~ {} 12/55 - inside math environment, e.g. − 1

  17. Font Face & Size italic • Put the text inside the above commands to change the font face. Font Face Commands document font \textnormal {...} emphasized \emph {...} small caps \textsc {...} slanted \textsl {...} \textit {...} \textrm {...} upright \textup {...} bold face \textbf {...} medium \textmd {...} typewriter \texttt {...} sans serif \textsf {...} roman 13/55 e.g. \textbf {this text will be in bold face}

  18. Font Face & Size \tiny the following text • These commands will afgect font size in Font Size Commands largest \Huge huge \huge very large font \LARGE large font \Large large font \large normal font \normalsize small font \small quite small font \footnotesize very small font \scriptsize tiny font 14/55 • Use { ... } to limit its efgect range e.g. { \small small size text}

  19. Spacing • Use package geometry to change the paper margin • Fill space using \hfill or \vfill • Create a line break and insert vertical spaces using \\ [1ex] (breakable) for two-sided printing \cleardoublepage : In addition to \clearpage , it makes the next page a right-hand page • \clearpage : create a new page and fmush all the fmoats • \newpage : create a new page • • To force a new page, use: \usepackage [top=3cm,bottom=3cm,left=2.5cm,right=2.5cm]{geometry} 15/55 • Force a space using ~ (unbreakable) or \ • Insert horizontal/vertical spaces with \hspace {1em} or \vspace {1ex}

  20. Length Unit in L inch EX A T Length Unit in L math unit equal to 1/18 em mu roughly the width of an ‘M’ (uppercase) in the current font em roughly the height of an ‘x’ (lowercase) in the current font ex in A T a centimeter cm a millimeter mm a point is approximately 1/72.27 inch pt meaning unit EX 16/55

  21. Alignment \begin {center} text to be centered \end {center} \begin {flushleft} text to be flushed left \end {flushleft} \begin {flushright} text to be flushed right \end {flushright} text to be centered text to be fmushed left text to be fmushed right 17/55

  22. Hyphenation • L soon. It will be 0116 291 2319. My phone number will change My phone number will change soon. \mbox {...} causes its argument to be kept together under all circumstances • ticexpialidocious I think this is: supercalifragilis- al \- i \- do \- cious i \- frag \- i \- lis \- tic \- ex \- pi \- % I think this is: su \- per \- cal \- % • Allow “hyphenation” to be hyphenated as well as “Hyphenation” • Prevents “FORTRAN”, “Fortran” and “fortran” from being hyphenated • For example, \hyphenation {FORTRAN Hy-phen-a-tion} instructs: • You can custom the hyphenation using \hyphenation {<word list>} in the preamble EX hyphenates words whenever necessary T A 18/55 • Or use \- inserts a discretionary hyphen into a word It will be \mbox {0116 291 2319}.

Recommend


More recommend