LATEX for Methodologists
Lecture 1: Introducton
        Sacha Epskamp
       University of Amsterdam
 Department of Psychological Methods
           02/04/2013
Contact Details
   Course website:
     I   http://sachaepskamp.com/latex-course
   E-mail:
     I   sacha.epskamp@gmail.com
Introduction
    I LAT
          EX is a completely different way of writing assignments,
        papers, articles and even presentation slides and books
    I   This course is a brief introduction to using LATEX for
        creating scientific documents
    I   It is specifically aimed at psychological researchers and
        methodologists
          I   Relatively little focus on mathematical formulae
          I   APA style documents
          I   Incorperating statistical anayses with R and
              Sweave/knitr
Course Outline
      April 2: Introduction
     April 10: Basics of writing in LATEX
     April 16: Writing APA style articles
     April 23: Advanced topics
Course Outline
      April 2: Introduction
                 I What is LAT X?
                              E
                 I Why use LAT X?
                               E
                 I How to obtain a LAT X distribution?
                                      E
                 I How to obtain a LAT X editor?
                                      E
                 I General outline of a LAT X document
                                           E
     April 10: Basics of writing in LATEX
     April 16: Writing APA style articles
     April 23: Advanced topics
Course Outline
      April 2: Introduction
     April 10: Basics of writing in LATEX
                I Document Structure
                I Sectioning
                I Writing text
                I Environments
                I Special text
                I Mathematical formulae
     April 16: Writing APA style articles
     April 23: Advanced topics
Course Outline
      April 2: Introduction
     April 10: Basics of writing in LATEX
     April 16: Writing APA style articles
                I The apa document class
                I Header information
                I Writing the body
                I Citations using BibT X and apacite
                                        E
     April 23: Advanced topics
Course Outline
      April 2: Introduction
     April 10: Basics of writing in LATEX
     April 16: Writing APA style articles
     April 23: Advanced topics
                I Incorperating statistics using R and
                   Sweave/knitr
                I Making presentation slides with beamer
Today’s lecture
   Introduction
   What is LATEX?
     History of LATEX
   Why use LATEX?
     LATEX vs WYSIWYG
   Obtaining LATEX
   Making a first LATEX document
Hello world example
What is LATEX?
   LATEX is. . .
      I A program that takes a plain text file with codes as input
        and produces a output document
           I   This process is usually called compiling
           I   The input is a plain text file with .tex extension
           I   The output is a multipage vector based image file. In the
               past this was .DVI but nowadays mostly pdf and
               postscript are used
           I   We will use .pdf, which can be created with the pdfLATEX
               program
     I   The programming language in which the input file is written
What is LATEX?
   LATEX refers to the programming language used to write the
   input file and the program used to interpret this file and compile
   the output file. It does not refer to an editor in which you write
   the input file.
What is LATEX?
   Simple representation:
                  .tex      / pdfLAT X    / .pdf
                                    E
                                 
                            other files
What is LATEX?
   More advanced representation including Sweave and citations.
    .Rnw       / Sweave      / .tex      / pdfLAT X      / .pdf
                  ;                       5   J E
                                                
     data        figures                 other files
                                             J
                              .bib        / BIBT X
                                                E
What is LATEX?
   For now, only consider:
                  .tex       / pdfLAT X    / .pdf
                                     E
                                  
                             other files
History of TEX
    I   In 1969, computer scientist Donald Knuth published the
        book “The Art of Computer Programming”. It was typeset
        using 19th century techniques.
    I   8 years later, in 1977, Knuth received proofs of the second
        edition. By this time the typesetting technology were
        largely replaced photography and he found the proofs awful
    I   With computers on the rise, Knuth saw a future in digital
        typesetting and decided that a long term stable system for
        digital typesetting was needed.
    I   This lead Knuth to devellop TEX
TEX
      I   TEX is a low-level markup and programming language
          (because it has if-else statements)
      I   Its name comes from the greek word τ χνoλoγια
          (technologìa), which translates to “technology”.
      I   TEX is meant to be very stable, so that it is a platform that
          produces the same documents for many years.
      I   Its current version is 3.1415926. Future version numbering
          will asymptotically approach π
TEX
  Donald Knuth on the future of TEX:
      absolutely final change (to be made after my death),
      will be to change the version number to π, at which
      point all remaining bugs will become features.
History of LATEX
    I   TEX is a very low-level language, meaning you have to
        specify many settings to control the way your document
        looks
    I   In the early 1980s, Leslie Lamport wrote a system of
        macros to automate most things of TEX, this resulted in
        LATEX
    I LAT
          EX is based on the idea that authors should be able to
        focus on the content of what they are writing without being
        distracted by its visual presentation
    I   The current version of LATEX is LATEX 2ε , a new version is
        being developed for over 20 years now
LATEX now
    I   Almost all use of TEX is through LATEX.
    I LAT
           EX is free as in “free speech“ an free beer
    I   LATEX is used especially by many researchers as main
        method of producing documents
    I   There is a large active and supportive community behind
        LATEX that produce many packages for extending LATEX
    I   There is an abundance of good software for editing LATEX
        files
WYSIWYG programs
   I LAT
         EX is completely different from What You See Is What
       You Get programs (WYSIWYG) you are used to
   I   For example:
         I   Microsoft Word
         I   Openoffice.org
         I   LibreOffice
   I   The main difference between the the two is that in
       WYSIWYG programs you directly edit the output file while
       with LATEX you edit the input file
Disadvantages of LaTeX vs. WYSIWYG
    I LAT
          EX comes with a different learning curve. Anyone can
        write something in WYSIWYG programs, while it takes
        some time to even produce basic documents in LATEX
    I   It can be hard to see what the document will look like
    I   You need to know a lot of commands to use LATEX (but, as
        we will see later, LATEX editors greatly reduce this)
    I   It can be harder to make very specific changes in LATEX
    I LAT
          EX can be very frustrating when it is not clear why your
        document does not look the way you want it to look
    I   Collaboration on LATEX documents is harder, but Google
        comes to the rescue
Advantages of LATEX vs. WYSIWYG
    I   In LATEX your documents will look very professional with
        minimal effort
    I   Produce your documents in PDF
          I   Your audience reads your document in a lightweight reader
              instead of an editor
          I   Your documents do not require special software to view
          I   Your documents will always look the same
    I   Your files are all in plain text. No binary documents that
        can break causing you to lose what you have written
    I   You do not have to spend time on specifying the layout,
        placing the figures, writing the reference list and making
        sure the fonts are all correct
    I   Mathematical formulae can easily be included.
    I   Your document is very flexible. Need to add a figure? All
        references to later figures are automatically corrected!
Ambiguities in LATEX vs. WYSIWYG
    I LAT
          EX forces you to properly section your article
    I   Some journals require LATEX format, and others do not
        accept LATEX format
    I LAT
          EX takes a long time to learn
    I   While you can do marvelous things with WYSIWYG
        editors, this takes even longer to learn and is usually not
        wanted in scientific reports
Obtaining LATEX
   To use LATEX you need three things:
     I   A plain text editor
     I   A LATEX distribution
     I   A program to view PDF files
           I   Adobe Reader
LATEX editors
     I   A LATEX distribution supplies you with the programs needed
         to compile LATEX documents
     I   But you also need an editor to write these documents
     I   As is the same with all programming languages, LATEX
         documents are written in plain text
     I   Because of this, any plain text editor can be used
     I   Editors come in all sorts of sizes with highly different levels
         of complexity. In general the complexer an editor the more
         you can do with it
     I   Which editor is the best is a highly debated subject!
   A good editor for LATEX has syntax highlighting, bracket
   matching, included log output and shortcuts for compiling and
   viewing your document
plain text editors
   Typically a programmer wants to use a single editor for all
   languages. These so called plain text editors can differ strongly.
   Some examples of such editors that can be used for LATEX
   Notepad++ A very nice and clean editor for Windows. Very
             lightweight, not much functionality besides writing
             code
         Gedit The default text editor for Linux. Very lightweight
               and can be extended with many plugins
        Emacs The editor of choice for many programmers. Very
              hard to learn but very useful in the end. Is an IDE
              for many programming languages. Some consider
              it to be an operating system
           Vim Another editor of choice of many programmers
   Even if you don’t use it for LATEX, you want a good plain text
   editor!
LATEX editors
   Other editors are specialized for LATEX:
       Rstudio If you did not use this IDE yet for R then do so.
               Has especially good support for Sweave and
               knitr
   TEXniccenter Has a menu very similar to WYSIWYG editors
               with shortcuts for common pieces of codes
    TEXmaker Similar to TeXniccenter with less functionality but
             cross platform
     TEXworks A very basic LATEX editor which does what you
              want it to do and not much else. Comes default
              with most distributions
Which editor to use?
   Depends on your needs, writing style and preferences
    Need to write?                            Use:
    Short note, abstract, outline, any text   Don’t use LATEX, use a good lightweight
    that does not need formatting             plain text editor (notepad++, Gedit,
                                              etcetera.)
    A lot of text while New to LATEX and      Use TEXnicCenter or TEXmaker
    used to WYSIWYG editors
    Text in which R code is included or run   Use RStudio or Emacs (with knitr)
    in the background                         package)
    LATEX texts often and programming in      Learn a powerfull editor such as
    multiple languages                        Emacs
TEXworks
  In this course we will be using TEXworks because it is very
  basic and comes default with MiKTEX and MacTEX and is
  available for Linux as well.
  Important to note is that TEXworks is not the only choice.
  Indeed it isn’t even metioned on the previous slide.
LATEX distributions
     I LAT
           EX is distributed through distributions
     I   A good distribution has a package manager that allows you
         go install and update packages with relative ease
     I   In this course we will be using:
           Windows: MikTEX
                 Mac: MacTEX
                Linux: TEXlive
   Detailed instructions to install these distributions can be found
   on the course website.
PATH variable
    I   The instruction guide will ask you to set something called a
        PATH variable
    I   This is a small list of paths to directories that tells your
        computer where it can find programs
    I   This enables you to run pdfLATEX from commandline
    I   In some editors, this is the only way to make a shortcut to
        LATEX
    I   Might not be needed now but useful to have set right
        lateron
A first LATEX document
   Open TEXworks, make a file with the following code:
   \documentclass{article}
   \begin{document}
   Hello World!
   \end{document}
   Save this file in an empty folder. Then select “pdfLaTeX” from
   the drop down menu and press the play button.
Templates
    I   Often it can be hard to start from scratch
    I   Many templates exist to help you get started, find them on
        Google!
    I   Often in these comments are used to say what you need to
        do
          I   A comment is preceded by a % sign
Tips
  Learning LATEX can take a while, and even after that you often
  encounter problems with compiling. Here are some tips to help
  when you get stuck:
       I   Compile your document often!
       I   Comments are a very useful debugging tool
       I   Use line numbering in your editor. the output of pdfLATEX
           will mention the line number where things went wrong
       I   Use templates
       I   Really stuck? Try to identify the problem look online:
             I   http://google.com/
             I   http://tex.stackexchange.com/
For next week, try the following:
  I   Install a LATEX distribution for your operating system using
      the instructions in the instructions on my website
  I   Install TEXworks
  I   Try to compile the hello world template aboce
  I   Try some templates. What works? What errors do you get
      if it doesn’t?