SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Downloaden Sie, um offline zu lesen
A
                              LTEX for beginners

                                 Stéphane Péchard


                                September 22, 2009




Stéphane Péchard (spechard)       A
                                  L TEX for beginners v1.0   published under GNU FDL   1 / 43
Outline

1                               A
     Introduction (or Why using LTEX?)

2    First document
       Document structure
       Form-content separation
       Basic commands

3    Mathematics and code

4    Playing with content

5    Going further

6    Resources


    Stéphane Péchard (spechard)   A
                                  L TEX for beginners v1.0   published under GNU FDL   2 / 43
Some terminology

TEX. . .
    is a low-level markup and programming language
     was created by Donald Knuth between 1977 and 1989!
     is very stable and powerful but time-consuming and difficult to learn

A
LTEX. . .
     is a package of macros based on TEX to make a document
     preparation system
     created by Leslie Lamport and still actively maintained
     easier to code and extendable (classes, packages, styles)

                                         A
                               but TEX = LTEX


 Stéphane Péchard (spechard)    A
                                L TEX for beginners v1.0   published under GNU FDL   3 / 43
Pros and cons of a non-WYSIWYG approach

Pros
    style is consistent (layout, fonts, tables, maths, etc.)
     mathematics are easily typeset
     indexes, footnotes and references are easily generated
     the author is forced to correctly structure your documents

Cons
   the final result is not visible straight away
                   A
     the necessary LTEX commands have to be learned
     customization can sometimes be difficult

  A
  LTEX uses a WYSIWYM-approach: What You See Is What You Mean


 Stéphane Péchard (spechard)   A
                               L TEX for beginners v1.0   published under GNU FDL   4 / 43
A
Simplified overview of the TEX/LTEX system


    additionnal data (fmt
                                                                 transcript (log)
    cls sty ldf tfm fd def)

                                                                                               printer

            document                                               formatted
                                          TEX                                                  screen
           input (tex)                                          output (dvi pdf)

                               internal files (aux toc lof)                                      web




                                            A
    Mittelbach Frank & Goossens Michel, The LTEX Companion, Second
    Edition, 2004.


 Stéphane Péchard (spechard)              A
                                          L TEX for beginners v1.0          published under GNU FDL      5 / 43
Outline

1                               A
     Introduction (or Why using LTEX?)

2    First document
       Document structure
       Form-content separation
       Basic commands

3    Mathematics and code

4    Playing with content

5    Going further

6    Resources


    Stéphane Péchard (spechard)   A
                                  L TEX for beginners v1.0   published under GNU FDL   6 / 43
Document structure



 d o c u m e n t c l a s s { report } % o r a r t i c l e , book , e t c .

% t h i s part i s the preamble
% i t c o n t a i n s commands t h a t a f f e c t t h e e n t i r e document .

 b e g i n { document }

% t h i s p a r t i s t h e body o f y o u r document
% t h i s i s w h e r e you w r i t e y o u r t e x t

 end { document }

Comments start with             %   and ends at the end of the line.




  Stéphane Péchard (spechard)              A
                                           L TEX for beginners v1.0           published under GNU FDL   7 / 43
Preamble – document class


 d o c u m e n t c l a s s [ 1 1 pt , a 4 paper , oneside ] { report }
                                 % global options               class

First line of code, it defines the type of document and some global options.
Common classes are:
      article    for articles, presentations, short reports, documentation. . .
      report    for reports containing several chapters, small books, thesis. . .
      book   for real books. . .
      letter    for writing letters.

For more classes and options: http://en.wikibooks.org/wiki/LaTeX/Basics



  Stéphane Péchard (spechard)              A
                                           L TEX for beginners v1.0       published under GNU FDL   8 / 43
Preamble – package inclusion, with options


 u s e p a c k a g e [ utf 8 ] { inputenc }

A lot of packages exist, the most important are:
      amsmath, amssymb          and   amsthm    for mathematical symbols
      babel   for the internationalization of LaTeX, mandatory
      fontenc    to choose the font encoding of the output text
      geometry     for easy management of document margins
      graphicx     to manage external pictures
      inputenc     to choose the encoding of the input text, mandatory

For more packages: http://en.wikibooks.org/wiki/LaTeX/Packages



  Stéphane Péchard (spechard)                  A
                                               L TEX for beginners v1.0   published under GNU FDL   9 / 43
Once the form is fixed for the whole document. . .


A simple document:              exemple.tex

 d o c u m e n t c l a s s [ a 4 paper , 1 2 pt ] { article }

 u s e p a c k a g e [ utf 8 ] { inputenc }
 u s e p a c k a g e [ T 1 ] { fontenc }
 u s e p a c k a g e { lmodern } % f o n t
 u s e p a c k a g e { amsmath , amssymb , amsfonts } % maths

 u s e p a c k a g e [ english ] { babel } % b a b e l

% content begins here
 t i t l e { Some explanations about stuff } % t h e                   title
 a u t h o r { Philip J . Fry } % y o u r name
 d a t e { t o d a y } % q u i t e e x p l i c i t !




  Stéphane Péchard (spechard)                A
                                             L TEX for beginners v1.0     published under GNU FDL   10 / 43
. . . the author may concentrate on the content!


 b e g i n { document }
 maketitle % g e n e r a t e s t h e   title

 b e g i n { abstract } % t o sum t h i n g s up
This document is destined to help you understand things .
 end { abstract }

 s e c t i o n { Introduction } % t o c r e a t e a new s e c t i o n
Lorem ipsum dolor sit amet , consectetur adipiscing elit .
Maecenas pretium urna ut nisl semper sed mattis erat interdum .
Vestibulum eget massa nisi .
Donec feugiat consequat leo , a vehicula est imperdiet at .

 s e c t i o n { Do you know I can do that ?}
I like maths : $ f o r a l l x  neq 0 ,  f r a c { x ^2}{ x } = x $

 end { document }




  Stéphane Péchard (spechard)           A
                                        L TEX for beginners v1.0   published under GNU FDL   11 / 43
Compiling the source



                                                                    Some explanations about stuff
                                                                                      Philip J. Fry
                                                                                  September 17, 2009
   pdflatex exemple . tex
                                                                                         Abstract
                                                                This document is destined to help you understand things.


                                                        1    Introduction
                                                        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas pretium
                               and voilà!               urna ut nisl semper sed mattis erat interdum. Vestibulum eget massa nisi.
                                                        Donec feugiat consequat leo, a vehicula est imperdiet at.


                                                        2    Do you know I can do that?
                                                                              2
                                                        I like maths: ∀x = 0, x = x
                                                                              x




see it: http://spechard.dgplug.org/LaTeXForBeginners/exemple.pdf


 Stéphane Péchard (spechard)                A
                                            L TEX for beginners v1.0                      published under GNU FDL                   12 / 43
Sectioning commands


Code is organized depending on the logical structure of the content:

                                      Command                               Level
                                  part{this is a part}                      -1
                               chapter{this is a chapter}                    0
                               section{this is a section}                    1
                         subsection{this is a subsection}                    2
                     subsubsection{this is a subsubsection}                  3
                           paragraph{this is a paragraph}                    4
                      subparagraph{this is a subparagraph}                   5

Note:   chapter{}     only exists for    book    and    report     classes.



 Stéphane Péchard (spechard)             A
                                         L TEX for beginners v1.0         published under GNU FDL   13 / 43
Font size

Ten local environment are available by default to change font size:

                                Command                                    Size
                          begin{tiny}tinyend{tiny}                         tiny

             begin{scriptsize}scriptsizeend{scriptsize}                scriptsize
         begin{footnotesize}footnotesizeend{footnotesize}            footnotesize
                        begin{small}smallend{small}                      small
             begin{normalsize}normalsizeend{normalsize}              normalsize
                        begin{large}largeend{large}                      large
                        begin{Large}Largeend{Large}                    Large
                        begin{LARGE}LARGEend{LARGE}                 LARGE
                          begin{huge}hugeend{huge}                    huge
                          begin{Huge}Hugeend{Huge}                  Huge
You can also use it with like this:         tiny{tiny test}.

 Stéphane Péchard (spechard)          A
                                      L TEX for beginners v1.0   published under GNU FDL   14 / 43
Font styles


As styles are not all available for this this presentation font, examples here
are shown in classic Computer Modern.

                                Command                           Style
                                textit {italic}            italic
                                textsl {slanted}          slanted
                           emph{emphasize}               emphasize
                            textbf {boldface}            boldface
                           texttt {typewriter}          typewriter
                           textsc {small caps}          small caps




 Stéphane Péchard (spechard)               A
                                           L TEX for beginners v1.0       published under GNU FDL   15 / 43
Positioning



 b e g i n { center }
This text is centered .
 end { center }                                     This text is centered.

 b e g i n { flushright }
This text is flushright .
 end { flushright }                                         This text is flushright.

 b e g i n { flushleft }
This text is flushleft .
 end { flushleft }                  This text is flushleft.




 Stéphane Péchard (spechard)   A
                               L TEX for beginners v1.0      published under GNU FDL   16 / 43
Outline

1                               A
     Introduction (or Why using LTEX?)

2    First document
       Document structure
       Form-content separation
       Basic commands

3    Mathematics and code

4    Playing with content

5    Going further

6    Resources


    Stéphane Péchard (spechard)   A
                                  L TEX for beginners v1.0   published under GNU FDL   17 / 43
Donec feugiat consequat leo, a
Do the maths!

We need:                 A L TEX showcase for beginners
               usepackage{amsmath}

                                 2             Do you know I
                                         Stéphane Péchard
Inline with      begin{math}...end{math},      or      (...)      or   $...$   like:
                                        September 18, 2009                                         2
                                 I like maths: ∀x = 0, x = x
$ f o r a l l x  neq 0 ,  f r a c { x ^2}{ x } = x $
                                                       x
                                                Abstract
                    This (short) document is destined to show beginners how L TEX
                                                                            A
                 can make things pretty! Not always easy though :-)
or separate      from the text with begin{displaymath}...end{displaymath}                              or
                                          or               , which gives:
          1      Mathematics
begin{equation}...end{equation}              [...]


          This is an exemple of equation separate from the text:
                                                           tε
                                 fh,ε (x, y) = εEx,y            Lx,yϕ (εu) ϕ(x) du                      (1)
                                                       0
              Here is how to produce powers and indices:

                                         kn+1 = n2 + kn − kn−1
                                                      2
   Stéphane Péchard (spechard)             A
                                           L TEX for beginners v1.0                  published under GNU FDL   18 / 43
A lot of symbols. . . and as many commands!

    ∝∝             ∴ ==≡≈∼         ∼
                                   =                           ⊥
                         |=   |
                         ≤≥
                                ⊂⊃⊆⊇
                                ± ×÷∗ ◦• ⊕⊗          ·
                                       ∩∪          ∧∨               †‡
                                           ··· cos sin lim lim lim lim
                                                               − ←
                                                                → −
←↔→→←−←→−→                          ↑   ←→       ⇑ =⇒⇐⇒⇐=⇒⇔
⇐ ⇓
      .      .               √
· : . . · · · . . . . . ¬∞ ∅∅
      .                            ∠
     ♥♦♦♦     ♠♣∀∃         ℘ℵ                     ∈∈
                                                  /
                        √
ık    ⊥ ∂ ð ¨˙.......←
                      −  f f
αβγδ εζηθϑικλµνπ ρ σςτ υφϕχψω


 Stéphane Péchard (spechard)   A
                               L TEX for beginners v1.0   published under GNU FDL   19 / 43
Maths are easy to type


Powers and indices:
  [
  k_{n+1} = n ^2 + k_n ^2 − k_{n−1}                              kn+1 = n2 + kn − kn−1
                                                                              2
  ]

Fractions and binomials:
[
                                                                          n!            n
  f r a c { n ! } { k ! ( n−k ) ! } =  binom { n }{ k }              k!(n−k)!    =    k
]

Roots:
[                                                                     √
                                                                       n
 s q r t [ n ]{1+ x+x^2+x^3+ l d o t s }                                 1 + x + x2 + x3 + . . .
]




  Stéphane Péchard (spechard)               A
                                            L TEX for beginners v1.0              published under GNU FDL   20 / 43
You can do almost anything you want!

Sums:
[
                                                                          10
                                                                          i=1 ti
 sum_{i =1}^{10} t_i
]

Integrals:
[
                                                                          ∞ −x
  i n t _0^ i n f t y e^{−x }  , dx                                    0 e      dx
]

Automatic bracket sizing:
[
 l e f t (  f r a c { x ^2}{ y ^3} r i g h t )                         x2
                                                                          y3
]




  Stéphane Péchard (spechard)                  A
                                               L TEX for beginners v1.0            published under GNU FDL   21 / 43
And sometimes more. . .
Matrices and arrays:
[
A_{m , n } =
 b e g i n { pmatrix }
   a _{1 ,1} & a _{1 ,2}         &    cdots   &   a _{1 , n } 
   a _{2 ,1} & a _{2 ,2}         &    cdots   &   a _{2 , n } 
    vdots &  vdots             &    ddots   &    v d o t s 
   a_{m , 1 } & a_{m , 2 }       &    cdots   &   a_{m , n }
 end { pmatrix }
]


                                                                          
                                          a1,1        a1,2      ···    a1,n
                                        
                                         a2,1        a2,2      ···    a2,n 
                                                                            
                                Am,n   = .
                                         .                             . 
                                         .
                                                       .
                                                       .
                                                       .
                                                                ..
                                                                   .    . 
                                                                        . 
                                             am,1 am,2 · · · am,n


     http://en.wikibooks.org/wiki/LaTeX/Mathematics
  Stéphane Péchard (spechard)              A
                                           L TEX for beginners v1.0       published under GNU FDL   22 / 43
Print the code!
 We need:      usepackage{listings}

 b e g i n { lstlisting }
        [ language =[ GNU ] C++]
                                                          Here is my code:
#include <iostream>
                                                       b e g i n { lstlisting } [ language=C++]
using namespace std ;                                 #include <iostream>
                                                      using namespace std ;
int main ( ) {                                        int main ( ) {
    int N = 4 2 ;                                         int N = 4 2 ;
                                                          for ( int i = 0 ; i < N ; ++i )
    for ( int i =0; i < N ; ++i )                               cout << i << endl ;
          cout << i << endl ;
                                                            return 0 ;
                                                      }
      return 0 ;                                       end { lstlisting }
}
 end { lstlisting }                                  2     Labels and cross-reference

 Many languages: Ada, Assembler, bash,Example label{ssec:example}
                                                      2.1
                                           C, C++, Caml, Cobol, Delphi,
                                  In this section, I put
 Fortran, HTML, Java, Logo, Matlab, Perl, Pascal, PHP, Prolog, Python,
                                  2.2 Referencing
 R, Ruby, SQL, TeX, VHDL, XML, XSLT, etc.
                                  Now, I can do ref{ssec:example} to print the number of the previous sec-
                                                      tion, which is 2.1.
       http://www.ctan.org/tex-archive/macros/latex/contrib/listings/
                                                      2.3    Referencing a table
                                                      Here, I make a reference and the table 1 of the following section.
   Stéphane Péchard (spechard)              A
                                            L TEX for beginners v1.0                  published under GNU FDL              23 / 43
Outline

1                               A
     Introduction (or Why using LTEX?)

2    First document
       Document structure
       Form-content separation
       Basic commands

3    Mathematics and code

4    Playing with content

5    Going further

6    Resources


    Stéphane Péchard (spechard)   A
                                  L TEX for beginners v1.0   published under GNU FDL   24 / 43
Lists and enumeration
Three environments:
  b e g i n { itemize }
     i t e m first stuff                       first stuff
     i t e m second thing
  end { itemize }                              second thing

  b e g i n { enumerate }
     i t e m first stuff                   1   first stuff
     i t e m second thing
  end { enumerate }                        2   second thing

 b e g i n { description }
 i t e m [ itemize ]
        list with bullet points                        itemize list with bullet points
 i t e m [ enumerate ]
        numbered list                           enumerate numbered list
 i t e m [ description ]
        list with definitions                   description list with definitions
 end { description }

  Stéphane Péchard (spechard)     A
                                  L TEX for beginners v1.0      published under GNU FDL   25 / 43
Labels and cross-referencing
Three commands:
      label {marker}   to make an object reference a marker, mostly like a name
               to reference the object marked before, it prints the
      ref {marker}
     number assigned to the object
     pageref{marker}      will print the number of the page where the object is


Important!
This is a two-step process: first the compiler stores the labels, then it
replaces the  ref with the right number. Then, several compilation are
necessary to see the proper output.


   A
If LTEX uses deprecated labels information, you get a warning:

                LaTeX Warning: There were undefined references.

 Stéphane Péchard (spechard)         A
                                     L TEX for beginners v1.0   published under GNU FDL   26 / 43
Tables: a tough one!
The      tabular   environment:   begin{tabular}[pos]...{table spec}end{tabular}:



    pos:    vertical position        table spec: column alignment and vertical lines
            h     here                       l      left-justified column
            b   bottom                       c      centered column
            c    center                      r      right-justified column
            t     top                     p{width}  paragraph column with text
                                                    vertically aligned at the top
 ... :content management                      |     vertical line
   &     column separator                    ||     double vertical line
         start new row
 hline    horizontal line
 cline      partial line


                                                         A
                         One of the most difficult part of LTEX!

  Stéphane Péchard (spechard)         A
                                      L TEX for beginners v1.0   published under GNU FDL   27 / 43
Tables: exemples, please!

 b e g i n { tabular }{ l c r }
   1 & 2 & 3  h l i n e                                      1     2    3
   4 & 5 & 6  h l i n e
   7 & 8 & 9 
                                                                4     5    6
 end { tabular }                                               7     8    9

 b e g i n { tabular } { | r | l | }
   hline
   7 C 0 & hexadecimal                                        7C0       hexadecimal
   3700 & octal   c l i n e {2−2}
   11111000000 & binary                                      3700       octal
   hline hline                                        11111000000       binary
   1984 & decimal 
   hline                                                      1984       decimal
 end { tabular }


     http://en.wikibooks.org/wiki/LaTeX/Tables


  Stéphane Péchard (spechard)      A
                                   L TEX for beginners v1.0    published under GNU FDL   28 / 43
Floats

A float is an unbreakable box containing text, images, etc.
    to deal with objects that won’t fit on the current page
     to help when you really don’t want the object here just now
     not part of the normal stream of text, they’re separate entities
     may disturb beginners because it breaks they’re WYSIWYG mind!


The author specifies placement with:

     h           here (in fact as soon as possible in the text flow)
     t          at the top of the page (the current or the following)
     b       at the bottom of the page (the current or the following)
     p               on a special page for floats only (far away)
     H     precisely here (requires the float package, to be used wisely)


 Stéphane Péchard (spechard)    A
                                L TEX for beginners v1.0   published under GNU FDL   29 / 43
Figures and tables may be floats

 b e g i n { figure } [ placement specifier ]
. . . figure contents . . .
 end { figure }



This way, you can specify a      caption{}    for your table:
 b e g i n { table } [ h ]
 c a p t i o n { simple showcase . }
 b e g i n { tabular } { | r | l | }
   hline                                                     Table: simple showcase.
   7 C 0 & hexadecimal 
    3700 & octal   c l i n e {2−2}                           7C0          hexadecimal
    11111000000 & binary 
   hline hline                                               3700          octal
    1984 & decimal                                    11111000000          binary
   hline
 end { tabular }                                              1984          decimal
 end { table }



  Stéphane Péchard (spechard)      A
                                   L TEX for beginners v1.0         published under GNU FDL   30 / 43
#include <iostream>
                                                             using namespace std ;
Remember labels?                                              int main ( ) {
                                                                  int N = 4 2 ;
                                                                  for ( int i = 0 ; i < N ; ++i )
                                                                        cout << i << endl ;

Floats are always numbered, so they can be referred to
                                            return 0 ;
                                      }
                                       end { lstlisting }
    use  label {} to create a marker
        always put the label after the caption, inside the float environment!
                                           2 Labels and cross-reference

        again, (at least) two compilations are Example label{ssec:example}
                                           2.1
                                                    needed!
                                           In this section, I put

                                                              2.2    Referencing
 b e g i n { table } [ h ]                                   Now, I can do ref{ssec:example} to print the number of the previous sec-
                                                              tion, which is 2.1.
 b e g i n { tabular } { | r | l | }
    hline                                                    2.3    Referencing a table
    7 C 0 & hexadecimal                                     Here, I make a reference and the table 1 of the following section.
    3700 & octal   c l i n e {2−2}
    11111000000 & binary                                    3     Tables
    hline hline                                                      7C0    hexadecimal
    1984 & decimal                                                  3700    octal
                                                               11111000000    binary
    hline                                                            1984    decimal
 end { tabular }                                                                      Table 1: simple showcase.
 c a p t i o n { simple showcase . }
 l a b e l { tab : 1 9 8 4 r ep re se n ta ti on s }
                                                                                                    2
 end { table }


   Stéphane Péchard (spechard)                 A
                                               L TEX for beginners v1.0                   published under GNU FDL                  31 / 43
Graphics
We need:       usepackage{graphicx}

The magical command
    use includegraphics[options]{name} to insert a extern graphic document
      there is a lot of options (height, width, trim, page, etc.): read the
      doc!
      you can insert         png, jpg    and   pdf   format images
      make it a float!


 b e g i n { figure } [ t ]                                                       Figure 1: Saint-Nazaire’s bridge.
 c a p t i o n { Saint−Nazaire ’ s bridge . }
 l a b e l { fig : S a i n t N a z a i r e B r i d g e }
 centering
 i nc lu de g ra ph ic s [ width= t e x t w i d t h ,
trim =400px 100 px 0 px 400 px , clip ]
{ Pont_de_Saint−Nazaire }                                           4   Graphics
 end { figure }

  Stéphane Péchard (spechard)                A
                                             L TEX for beginners v1.0          published under GNU FDL                 32 / 43
Page Layout

Everything is under control!                                                   4
                                                                                    5
                                                                                                         2



                                                                                            Header
    default page size: US letter format
                                                                                        6

     A4 format (21x29.7cm):
     documentclass[a4paper]{article}

     everything is a parameter (header,
     footer, margins, body sizes)
                                                               Margin notes                  Body
                                                                                                     7




Package geometry to define margins,                                        9

                                                                     10
orientation, etc.                                                3



     landscape (portrait is default):
                                                                                              8

     usepackage[landscape]{geometry}                                          11


                                                                                            Footer
     margins:      usepackage[hmargin=3cm,
                                                                1

     vmargin=2cm]{geometry}

    http://en.wikibooks.org/wiki/LaTeX/Page_Layout
 Stéphane Péchard (spechard)        A
                                    L TEX for beginners v1.0                  published under GNU FDL    33 / 43
Headers and footers content
We need:      usepackage{fancyhdr}
% page h e a d e r s / f o o t e r s f o r a t w o s i d e document
 p a g e s t y l e { fancy } % m a n d a t o r y
 fancyhf {} % c l e a r d e f a u l t s
 fancyhead [ RO ] {  nouppercase {emph{ r i g h t m a r k }}} % RO=r i g h t −odd
 fancyhead [ LE ] {  nouppercase {emph{ l e f t m a r k }}} % LE=l e f t −e v e n

 fancy pagestyl e { plain }{ % f o r c h a p t e r p a g e s
 fancyhf {} % c l e a r d e f a u l t s
 renewcommand { headrulewidth }{0 pt }} % remove t h e l i n e


using:
      thepage    the current page number
      leftmark   the current chapter name
      rightmark    the current section name
      thesection     current section number

     http://en.wikibooks.org/wiki/LaTeX/Page_Layout
  Stéphane Péchard (spechard)         A
                                      L TEX for beginners v1.0   published under GNU FDL   34 / 43
Useful things

    http://en.wikibooks.org/wiki/LaTeX/Useful_Measurement_Macros

Measurement units and macros
   A
   LTEX knows a lot of measurement units (pt, bp, mm, cm, in, ex, em)
     and a lot of macros:  baselineskip ,  baselinestretch , columnsep, columnwidth,
     evensidemargin,  linewidth , oddsidemargin, paperwidth paperheight, parindent ,
     parskip tabcolsep ,  textheight , textwidth topmargin,  unitlength , etc.

     you can change their values:         setlength{textwidth}{0.5paperwidth}

     or make a slight change:      addtolength{itemsep}{0.5 baselineskip }

                                     Contents
  Tables of interest:                1 Mathematics                                                               1

                                     2 Labels and cross-reference                                                2
   tab le of c on te nt s             2.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   2
   listoffigures                      2.2 Referencing . . . . . . . . . . . . . . . . . . . . . . . . . . . .   2
   listoftables                       2.3 Referencing a table . . . . . . . . . . . . . . . . . . . . . . . .   2

                                     3 Tables                                                                    2

                                     4 Graphics                                                                  3


 Stéphane Péchard (spechard)       A
                                   L TEX for beginners v1.0                    published under GNU FDL               35 / 43
Outline

1                               A
     Introduction (or Why using LTEX?)

2    First document
       Document structure
       Form-content separation
       Basic commands

3    Mathematics and code

4    Playing with content

5    Going further

6    Resources


    Stéphane Péchard (spechard)   A
                                  L TEX for beginners v1.0   published under GNU FDL   36 / 43
A
Guidelines to make LTEX coding easier

Split the document into multiple files
     to avoid writing in one giant document ;
     input{file}      inserts content as it in file ;
     include{file}       is more flexible thanks to                  includeonly {file1, file2}          ;

Create and recreating new commands
    using newcommand{name}[num]{definition} with name the name of the new
    command, num number of arguments taken, up to 9 (default=0),
    definition the command itself

     newcommand { note } [ 1 ] {  m a r g i n p a r {% n o t e s i n m a r g i n
          v s k i p − b a s e l i n e s k i p %r a i s e t h e m a r g i n p a r a b i t
          r a g g e d r i g h t  f o o t n o t e s i z e  color { red }
         { i t s h a p e  h r u l e  s m a l l s k i p #1} p a r  s m a l l s k i p  h r u l e }}
     newcommand { nonotes }{ renewcommand { note } [ 1 ] { } }



 Stéphane Péchard (spechard)                  A
                                              L TEX for beginners v1.0            published under GNU FDL     37 / 43
A bit of debugging: DON’T PANIC!

Everybody makes error like:
    mistype or mis-spell commands
     forget curly braces
     type a forward slash / instead of a backslash 
     use a special character by mistake

But happily:
                                          A
    errors and warning are well defined in LTEX log
     ! Undefined control sequence .
     l . 6  t ab le of c on te nt s


     an editor may help you locate or even avoid them
     an erroneous document is not what you want, so don’t let them!


 Stéphane Péchard (spechard)   A
                               L TEX for beginners v1.0   published under GNU FDL   38 / 43
A bit of debugging: What can I do?

                          A
On the command line, when LTEX finds an error, you have to specify it
what to do about it:

         Key                             Meaning
            x                                      A
                                    stop and exit LTEX
            q      carry on as best as possible and stop showing errors
            e      stop and position the editor at error line (if possible)
            i          correct here (not in the editor) and carry on
            r            non-stop mode, ignore errors (up to 100)
            h                    try to give me more help

Some editors run in non-stop mode and analyze log to show errors and
warnings.
    http://en.wikibooks.org/wiki/LaTeX/Errors_and_Warnings


 Stéphane Péchard (spechard)       A
                                   L TEX for beginners v1.0   published under GNU FDL   39 / 43
Going local :-)

                               Want to print pretty bengali?


Use XeTEX:
                       A
    a variation around LTEX
    (component of TeXLive)
      based on unicode and
      modern fonts systems
      specific syntax for new
      features and own binary
      xelatex sample . tex




    http://methopath.wordpress.com/2008/06/26/writing-unicode-
    bengali-in-latex/
 Stéphane Péchard (spechard)          A
                                      L TEX for beginners v1.0   published under GNU FDL   40 / 43
Many (many!) packages


     bibtex   bibliography management ;
     makeidx    indexes management ;
     pstricks    low-level and hitoric graphic package ;
     pgf   modern, nice and simple graphics (preferred) ;
     beamer   presentation class, like this one ;
     hyperref    PDF hyperlinks management (use with caution) ;
     color   to make colored text (use wisely) ;
     pdfpages    to insert PDF or PS pages in a PDF ;
     verbatim              A
                 to insert LTEX code ;
     minipage    to create a page in a page ;



 Stéphane Péchard (spechard)      A
                                  L TEX for beginners v1.0   published under GNU FDL   41 / 43
Editors
                           A
 Both ViM and Emacs have a LTEX edition mode.
     http://vim-latex.sourceforge.net/
     http://www.gnu.org/software/auctex/


         A
Kile – a LTEX Environment (for KDE)
   http://kile.sourceforge.net/




  Stéphane Péchard (spechard)   A
                                L TEX for beginners v1.0   published under GNU FDL   42 / 43
Many resources to learn even more

Books:
                                             A
     Mittelbach Frank & Goossens Michel, The LTEX Companion, Second
     Edition, 2004.
     Donald E. Knuth, The TeX book, 1986.
     The Comprehensive LaTeX Symbol List (pdf)
     LaTeX Reference Card (pdf)

Websites:
     http://www.latex-project.org/ – official website
     http://www.ctan.org/ – where you can find everything!
     http://www.tug.org/ – The TeX Users Group
     http://www.tex.ac.uk/cgi-bin/texfaq2html – The UK TeX FAQ
     http://en.wikibooks.org/wiki/LaTeX/ – a book being written online

 Stéphane Péchard (spechard)   A
                               L TEX for beginners v1.0   published under GNU FDL   43 / 43

Weitere ähnliche Inhalte

Was ist angesagt?

System Programming Unit III
System Programming Unit IIISystem Programming Unit III
System Programming Unit III
Manoj Patil
 
Software Reengineering
Software ReengineeringSoftware Reengineering
Software Reengineering
Abdul Wahid
 
1.1 The nature of software.ppt
1.1 The nature of software.ppt1.1 The nature of software.ppt
1.1 The nature of software.ppt
JAYAPRIYAR7
 

Was ist angesagt? (20)

System Programming Unit III
System Programming Unit IIISystem Programming Unit III
System Programming Unit III
 
Lexical analysis-using-lex
Lexical analysis-using-lexLexical analysis-using-lex
Lexical analysis-using-lex
 
Introduction to Latex
Introduction to LatexIntroduction to Latex
Introduction to Latex
 
Lex
LexLex
Lex
 
Introduction to Latex
Introduction to Latex Introduction to Latex
Introduction to Latex
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Web Engineering
Web EngineeringWeb Engineering
Web Engineering
 
Dotnet Frameworks Version History
Dotnet Frameworks Version HistoryDotnet Frameworks Version History
Dotnet Frameworks Version History
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
 
Control structures functions and modules in python programming
Control structures functions and modules in python programmingControl structures functions and modules in python programming
Control structures functions and modules in python programming
 
Editing documents with LaTeX
Editing documents with LaTeXEditing documents with LaTeX
Editing documents with LaTeX
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational Algebra
 
Software Reengineering
Software ReengineeringSoftware Reengineering
Software Reengineering
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
1.1 The nature of software.ppt
1.1 The nature of software.ppt1.1 The nature of software.ppt
1.1 The nature of software.ppt
 
Compiler Construction Course - Introduction
Compiler Construction Course - IntroductionCompiler Construction Course - Introduction
Compiler Construction Course - Introduction
 
Deterministic Finite Automata
Deterministic Finite AutomataDeterministic Finite Automata
Deterministic Finite Automata
 
Latex workshop: Essentials and Practices
Latex workshop: Essentials and PracticesLatex workshop: Essentials and Practices
Latex workshop: Essentials and Practices
 
Problem solving methodology
Problem solving methodologyProblem solving methodology
Problem solving methodology
 
Screaming fast json parsing on Android
Screaming fast json parsing on AndroidScreaming fast json parsing on Android
Screaming fast json parsing on Android
 

Andere mochten auch (8)

Latex for beginner
Latex for beginnerLatex for beginner
Latex for beginner
 
Visualizacion de Imagen Médica con 3D Slicer
Visualizacion de Imagen Médica con 3D SlicerVisualizacion de Imagen Médica con 3D Slicer
Visualizacion de Imagen Médica con 3D Slicer
 
Miniproject report receiver
Miniproject report receiverMiniproject report receiver
Miniproject report receiver
 
AddamsMoring 2009 Getting started with LaTeX in PDF
AddamsMoring 2009 Getting started with LaTeX in PDFAddamsMoring 2009 Getting started with LaTeX in PDF
AddamsMoring 2009 Getting started with LaTeX in PDF
 
ELECTRONICS PROJECT REPORT OF HOME AUTOMATION CUM BUILDING SECUIRITY
ELECTRONICS PROJECT REPORT OF HOME AUTOMATION CUM BUILDING SECUIRITYELECTRONICS PROJECT REPORT OF HOME AUTOMATION CUM BUILDING SECUIRITY
ELECTRONICS PROJECT REPORT OF HOME AUTOMATION CUM BUILDING SECUIRITY
 
Powerpoint Mini Project.Pdf
Powerpoint  Mini Project.PdfPowerpoint  Mini Project.Pdf
Powerpoint Mini Project.Pdf
 
Complete-Mini-Project-Report
Complete-Mini-Project-ReportComplete-Mini-Project-Report
Complete-Mini-Project-Report
 
Mini project ppt
Mini project pptMini project ppt
Mini project ppt
 

Ähnlich wie LaTeX for beginners (20)

Lshort
LshortLshort
Lshort
 
abc12
abc12abc12
abc12
 
popopo
popopopopopo
popopo
 
abc
abcabc
abc
 
latex-workshop Dr: Mohamed A. Alrshah
latex-workshop Dr: Mohamed A. Alrshahlatex-workshop Dr: Mohamed A. Alrshah
latex-workshop Dr: Mohamed A. Alrshah
 
LATEX.ppt
LATEX.pptLATEX.ppt
LATEX.ppt
 
LaTeX Part 1
LaTeX Part 1LaTeX Part 1
LaTeX Part 1
 
Basic Latex Typesetting - Session 1
Basic Latex Typesetting - Session 1Basic Latex Typesetting - Session 1
Basic Latex Typesetting - Session 1
 
Sample pdf
Sample pdfSample pdf
Sample pdf
 
SAMPDF 1
SAMPDF 1SAMPDF 1
SAMPDF 1
 
13p
13p13p
13p
 
sample.pdf
sample.pdfsample.pdf
sample.pdf
 
sample.pdf
sample.pdfsample.pdf
sample.pdf
 
11p2
11p211p2
11p2
 
sample.pdf
sample.pdfsample.pdf
sample.pdf
 
sample.pdf
sample.pdfsample.pdf
sample.pdf
 
Sample pdf
Sample pdfSample pdf
Sample pdf
 
pdf
pdfpdf
pdf
 
sample.pdf
sample.pdfsample.pdf
sample.pdf
 
new.pdf
new.pdfnew.pdf
new.pdf
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

LaTeX for beginners

  • 1. A LTEX for beginners Stéphane Péchard September 22, 2009 Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 1 / 43
  • 2. Outline 1 A Introduction (or Why using LTEX?) 2 First document Document structure Form-content separation Basic commands 3 Mathematics and code 4 Playing with content 5 Going further 6 Resources Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 2 / 43
  • 3. Some terminology TEX. . . is a low-level markup and programming language was created by Donald Knuth between 1977 and 1989! is very stable and powerful but time-consuming and difficult to learn A LTEX. . . is a package of macros based on TEX to make a document preparation system created by Leslie Lamport and still actively maintained easier to code and extendable (classes, packages, styles) A but TEX = LTEX Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 3 / 43
  • 4. Pros and cons of a non-WYSIWYG approach Pros style is consistent (layout, fonts, tables, maths, etc.) mathematics are easily typeset indexes, footnotes and references are easily generated the author is forced to correctly structure your documents Cons the final result is not visible straight away A the necessary LTEX commands have to be learned customization can sometimes be difficult A LTEX uses a WYSIWYM-approach: What You See Is What You Mean Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 4 / 43
  • 5. A Simplified overview of the TEX/LTEX system additionnal data (fmt transcript (log) cls sty ldf tfm fd def) printer document formatted TEX screen input (tex) output (dvi pdf) internal files (aux toc lof) web A Mittelbach Frank & Goossens Michel, The LTEX Companion, Second Edition, 2004. Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 5 / 43
  • 6. Outline 1 A Introduction (or Why using LTEX?) 2 First document Document structure Form-content separation Basic commands 3 Mathematics and code 4 Playing with content 5 Going further 6 Resources Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 6 / 43
  • 7. Document structure d o c u m e n t c l a s s { report } % o r a r t i c l e , book , e t c . % t h i s part i s the preamble % i t c o n t a i n s commands t h a t a f f e c t t h e e n t i r e document . b e g i n { document } % t h i s p a r t i s t h e body o f y o u r document % t h i s i s w h e r e you w r i t e y o u r t e x t end { document } Comments start with % and ends at the end of the line. Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 7 / 43
  • 8. Preamble – document class d o c u m e n t c l a s s [ 1 1 pt , a 4 paper , oneside ] { report } % global options class First line of code, it defines the type of document and some global options. Common classes are: article for articles, presentations, short reports, documentation. . . report for reports containing several chapters, small books, thesis. . . book for real books. . . letter for writing letters. For more classes and options: http://en.wikibooks.org/wiki/LaTeX/Basics Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 8 / 43
  • 9. Preamble – package inclusion, with options u s e p a c k a g e [ utf 8 ] { inputenc } A lot of packages exist, the most important are: amsmath, amssymb and amsthm for mathematical symbols babel for the internationalization of LaTeX, mandatory fontenc to choose the font encoding of the output text geometry for easy management of document margins graphicx to manage external pictures inputenc to choose the encoding of the input text, mandatory For more packages: http://en.wikibooks.org/wiki/LaTeX/Packages Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 9 / 43
  • 10. Once the form is fixed for the whole document. . . A simple document: exemple.tex d o c u m e n t c l a s s [ a 4 paper , 1 2 pt ] { article } u s e p a c k a g e [ utf 8 ] { inputenc } u s e p a c k a g e [ T 1 ] { fontenc } u s e p a c k a g e { lmodern } % f o n t u s e p a c k a g e { amsmath , amssymb , amsfonts } % maths u s e p a c k a g e [ english ] { babel } % b a b e l % content begins here t i t l e { Some explanations about stuff } % t h e title a u t h o r { Philip J . Fry } % y o u r name d a t e { t o d a y } % q u i t e e x p l i c i t ! Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 10 / 43
  • 11. . . . the author may concentrate on the content! b e g i n { document } maketitle % g e n e r a t e s t h e title b e g i n { abstract } % t o sum t h i n g s up This document is destined to help you understand things . end { abstract } s e c t i o n { Introduction } % t o c r e a t e a new s e c t i o n Lorem ipsum dolor sit amet , consectetur adipiscing elit . Maecenas pretium urna ut nisl semper sed mattis erat interdum . Vestibulum eget massa nisi . Donec feugiat consequat leo , a vehicula est imperdiet at . s e c t i o n { Do you know I can do that ?} I like maths : $ f o r a l l x neq 0 , f r a c { x ^2}{ x } = x $ end { document } Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 11 / 43
  • 12. Compiling the source Some explanations about stuff Philip J. Fry September 17, 2009 pdflatex exemple . tex Abstract This document is destined to help you understand things. 1 Introduction Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas pretium and voilà! urna ut nisl semper sed mattis erat interdum. Vestibulum eget massa nisi. Donec feugiat consequat leo, a vehicula est imperdiet at. 2 Do you know I can do that? 2 I like maths: ∀x = 0, x = x x see it: http://spechard.dgplug.org/LaTeXForBeginners/exemple.pdf Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 12 / 43
  • 13. Sectioning commands Code is organized depending on the logical structure of the content: Command Level part{this is a part} -1 chapter{this is a chapter} 0 section{this is a section} 1 subsection{this is a subsection} 2 subsubsection{this is a subsubsection} 3 paragraph{this is a paragraph} 4 subparagraph{this is a subparagraph} 5 Note: chapter{} only exists for book and report classes. Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 13 / 43
  • 14. Font size Ten local environment are available by default to change font size: Command Size begin{tiny}tinyend{tiny} tiny begin{scriptsize}scriptsizeend{scriptsize} scriptsize begin{footnotesize}footnotesizeend{footnotesize} footnotesize begin{small}smallend{small} small begin{normalsize}normalsizeend{normalsize} normalsize begin{large}largeend{large} large begin{Large}Largeend{Large} Large begin{LARGE}LARGEend{LARGE} LARGE begin{huge}hugeend{huge} huge begin{Huge}Hugeend{Huge} Huge You can also use it with like this: tiny{tiny test}. Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 14 / 43
  • 15. Font styles As styles are not all available for this this presentation font, examples here are shown in classic Computer Modern. Command Style textit {italic} italic textsl {slanted} slanted emph{emphasize} emphasize textbf {boldface} boldface texttt {typewriter} typewriter textsc {small caps} small caps Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 15 / 43
  • 16. Positioning b e g i n { center } This text is centered . end { center } This text is centered. b e g i n { flushright } This text is flushright . end { flushright } This text is flushright. b e g i n { flushleft } This text is flushleft . end { flushleft } This text is flushleft. Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 16 / 43
  • 17. Outline 1 A Introduction (or Why using LTEX?) 2 First document Document structure Form-content separation Basic commands 3 Mathematics and code 4 Playing with content 5 Going further 6 Resources Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 17 / 43
  • 18. Donec feugiat consequat leo, a Do the maths! We need: A L TEX showcase for beginners usepackage{amsmath} 2 Do you know I Stéphane Péchard Inline with begin{math}...end{math}, or (...) or $...$ like: September 18, 2009 2 I like maths: ∀x = 0, x = x $ f o r a l l x neq 0 , f r a c { x ^2}{ x } = x $ x Abstract This (short) document is destined to show beginners how L TEX A can make things pretty! Not always easy though :-) or separate from the text with begin{displaymath}...end{displaymath} or or , which gives: 1 Mathematics begin{equation}...end{equation} [...] This is an exemple of equation separate from the text: tε fh,ε (x, y) = εEx,y Lx,yϕ (εu) ϕ(x) du (1) 0 Here is how to produce powers and indices: kn+1 = n2 + kn − kn−1 2 Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 18 / 43
  • 19. A lot of symbols. . . and as many commands! ∝∝ ∴ ==≡≈∼ ∼ = ⊥ |= | ≤≥ ⊂⊃⊆⊇ ± ×÷∗ ◦• ⊕⊗ · ∩∪ ∧∨ †‡ ··· cos sin lim lim lim lim − ← → − ←↔→→←−←→−→ ↑ ←→ ⇑ =⇒⇐⇒⇐=⇒⇔ ⇐ ⇓ . . √ · : . . · · · . . . . . ¬∞ ∅∅ . ∠ ♥♦♦♦ ♠♣∀∃ ℘ℵ ∈∈ / √ ık ⊥ ∂ ð ¨˙.......← − f f αβγδ εζηθϑικλµνπ ρ σςτ υφϕχψω Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 19 / 43
  • 20. Maths are easy to type Powers and indices: [ k_{n+1} = n ^2 + k_n ^2 − k_{n−1} kn+1 = n2 + kn − kn−1 2 ] Fractions and binomials: [ n! n f r a c { n ! } { k ! ( n−k ) ! } = binom { n }{ k } k!(n−k)! = k ] Roots: [ √ n s q r t [ n ]{1+ x+x^2+x^3+ l d o t s } 1 + x + x2 + x3 + . . . ] Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 20 / 43
  • 21. You can do almost anything you want! Sums: [ 10 i=1 ti sum_{i =1}^{10} t_i ] Integrals: [ ∞ −x i n t _0^ i n f t y e^{−x } , dx 0 e dx ] Automatic bracket sizing: [ l e f t ( f r a c { x ^2}{ y ^3} r i g h t ) x2 y3 ] Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 21 / 43
  • 22. And sometimes more. . . Matrices and arrays: [ A_{m , n } = b e g i n { pmatrix } a _{1 ,1} & a _{1 ,2} & cdots & a _{1 , n } a _{2 ,1} & a _{2 ,2} & cdots & a _{2 , n } vdots & vdots & ddots & v d o t s a_{m , 1 } & a_{m , 2 } & cdots & a_{m , n } end { pmatrix } ]   a1,1 a1,2 ··· a1,n   a2,1 a2,2 ··· a2,n   Am,n = .  . .   . . . . .. . .  .  am,1 am,2 · · · am,n http://en.wikibooks.org/wiki/LaTeX/Mathematics Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 22 / 43
  • 23. Print the code! We need: usepackage{listings} b e g i n { lstlisting } [ language =[ GNU ] C++] Here is my code: #include <iostream> b e g i n { lstlisting } [ language=C++] using namespace std ; #include <iostream> using namespace std ; int main ( ) { int main ( ) { int N = 4 2 ; int N = 4 2 ; for ( int i = 0 ; i < N ; ++i ) for ( int i =0; i < N ; ++i ) cout << i << endl ; cout << i << endl ; return 0 ; } return 0 ; end { lstlisting } } end { lstlisting } 2 Labels and cross-reference Many languages: Ada, Assembler, bash,Example label{ssec:example} 2.1 C, C++, Caml, Cobol, Delphi, In this section, I put Fortran, HTML, Java, Logo, Matlab, Perl, Pascal, PHP, Prolog, Python, 2.2 Referencing R, Ruby, SQL, TeX, VHDL, XML, XSLT, etc. Now, I can do ref{ssec:example} to print the number of the previous sec- tion, which is 2.1. http://www.ctan.org/tex-archive/macros/latex/contrib/listings/ 2.3 Referencing a table Here, I make a reference and the table 1 of the following section. Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 23 / 43
  • 24. Outline 1 A Introduction (or Why using LTEX?) 2 First document Document structure Form-content separation Basic commands 3 Mathematics and code 4 Playing with content 5 Going further 6 Resources Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 24 / 43
  • 25. Lists and enumeration Three environments: b e g i n { itemize } i t e m first stuff first stuff i t e m second thing end { itemize } second thing b e g i n { enumerate } i t e m first stuff 1 first stuff i t e m second thing end { enumerate } 2 second thing b e g i n { description } i t e m [ itemize ] list with bullet points itemize list with bullet points i t e m [ enumerate ] numbered list enumerate numbered list i t e m [ description ] list with definitions description list with definitions end { description } Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 25 / 43
  • 26. Labels and cross-referencing Three commands: label {marker} to make an object reference a marker, mostly like a name to reference the object marked before, it prints the ref {marker} number assigned to the object pageref{marker} will print the number of the page where the object is Important! This is a two-step process: first the compiler stores the labels, then it replaces the ref with the right number. Then, several compilation are necessary to see the proper output. A If LTEX uses deprecated labels information, you get a warning: LaTeX Warning: There were undefined references. Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 26 / 43
  • 27. Tables: a tough one! The tabular environment: begin{tabular}[pos]...{table spec}end{tabular}: pos: vertical position table spec: column alignment and vertical lines h here l left-justified column b bottom c centered column c center r right-justified column t top p{width} paragraph column with text vertically aligned at the top ... :content management | vertical line & column separator || double vertical line start new row hline horizontal line cline partial line A One of the most difficult part of LTEX! Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 27 / 43
  • 28. Tables: exemples, please! b e g i n { tabular }{ l c r } 1 & 2 & 3 h l i n e 1 2 3 4 & 5 & 6 h l i n e 7 & 8 & 9 4 5 6 end { tabular } 7 8 9 b e g i n { tabular } { | r | l | } hline 7 C 0 & hexadecimal 7C0 hexadecimal 3700 & octal c l i n e {2−2} 11111000000 & binary 3700 octal hline hline 11111000000 binary 1984 & decimal hline 1984 decimal end { tabular } http://en.wikibooks.org/wiki/LaTeX/Tables Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 28 / 43
  • 29. Floats A float is an unbreakable box containing text, images, etc. to deal with objects that won’t fit on the current page to help when you really don’t want the object here just now not part of the normal stream of text, they’re separate entities may disturb beginners because it breaks they’re WYSIWYG mind! The author specifies placement with: h here (in fact as soon as possible in the text flow) t at the top of the page (the current or the following) b at the bottom of the page (the current or the following) p on a special page for floats only (far away) H precisely here (requires the float package, to be used wisely) Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 29 / 43
  • 30. Figures and tables may be floats b e g i n { figure } [ placement specifier ] . . . figure contents . . . end { figure } This way, you can specify a caption{} for your table: b e g i n { table } [ h ] c a p t i o n { simple showcase . } b e g i n { tabular } { | r | l | } hline Table: simple showcase. 7 C 0 & hexadecimal 3700 & octal c l i n e {2−2} 7C0 hexadecimal 11111000000 & binary hline hline 3700 octal 1984 & decimal 11111000000 binary hline end { tabular } 1984 decimal end { table } Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 30 / 43
  • 31. #include <iostream> using namespace std ; Remember labels? int main ( ) { int N = 4 2 ; for ( int i = 0 ; i < N ; ++i ) cout << i << endl ; Floats are always numbered, so they can be referred to return 0 ; } end { lstlisting } use label {} to create a marker always put the label after the caption, inside the float environment! 2 Labels and cross-reference again, (at least) two compilations are Example label{ssec:example} 2.1 needed! In this section, I put 2.2 Referencing b e g i n { table } [ h ] Now, I can do ref{ssec:example} to print the number of the previous sec- tion, which is 2.1. b e g i n { tabular } { | r | l | } hline 2.3 Referencing a table 7 C 0 & hexadecimal Here, I make a reference and the table 1 of the following section. 3700 & octal c l i n e {2−2} 11111000000 & binary 3 Tables hline hline 7C0 hexadecimal 1984 & decimal 3700 octal 11111000000 binary hline 1984 decimal end { tabular } Table 1: simple showcase. c a p t i o n { simple showcase . } l a b e l { tab : 1 9 8 4 r ep re se n ta ti on s } 2 end { table } Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 31 / 43
  • 32. Graphics We need: usepackage{graphicx} The magical command use includegraphics[options]{name} to insert a extern graphic document there is a lot of options (height, width, trim, page, etc.): read the doc! you can insert png, jpg and pdf format images make it a float! b e g i n { figure } [ t ] Figure 1: Saint-Nazaire’s bridge. c a p t i o n { Saint−Nazaire ’ s bridge . } l a b e l { fig : S a i n t N a z a i r e B r i d g e } centering i nc lu de g ra ph ic s [ width= t e x t w i d t h , trim =400px 100 px 0 px 400 px , clip ] { Pont_de_Saint−Nazaire } 4 Graphics end { figure } Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 32 / 43
  • 33. Page Layout Everything is under control! 4 5 2 Header default page size: US letter format 6 A4 format (21x29.7cm): documentclass[a4paper]{article} everything is a parameter (header, footer, margins, body sizes) Margin notes Body 7 Package geometry to define margins, 9 10 orientation, etc. 3 landscape (portrait is default): 8 usepackage[landscape]{geometry} 11 Footer margins: usepackage[hmargin=3cm, 1 vmargin=2cm]{geometry} http://en.wikibooks.org/wiki/LaTeX/Page_Layout Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 33 / 43
  • 34. Headers and footers content We need: usepackage{fancyhdr} % page h e a d e r s / f o o t e r s f o r a t w o s i d e document p a g e s t y l e { fancy } % m a n d a t o r y fancyhf {} % c l e a r d e f a u l t s fancyhead [ RO ] { nouppercase {emph{ r i g h t m a r k }}} % RO=r i g h t −odd fancyhead [ LE ] { nouppercase {emph{ l e f t m a r k }}} % LE=l e f t −e v e n fancy pagestyl e { plain }{ % f o r c h a p t e r p a g e s fancyhf {} % c l e a r d e f a u l t s renewcommand { headrulewidth }{0 pt }} % remove t h e l i n e using: thepage the current page number leftmark the current chapter name rightmark the current section name thesection current section number http://en.wikibooks.org/wiki/LaTeX/Page_Layout Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 34 / 43
  • 35. Useful things http://en.wikibooks.org/wiki/LaTeX/Useful_Measurement_Macros Measurement units and macros A LTEX knows a lot of measurement units (pt, bp, mm, cm, in, ex, em) and a lot of macros: baselineskip , baselinestretch , columnsep, columnwidth, evensidemargin, linewidth , oddsidemargin, paperwidth paperheight, parindent , parskip tabcolsep , textheight , textwidth topmargin, unitlength , etc. you can change their values: setlength{textwidth}{0.5paperwidth} or make a slight change: addtolength{itemsep}{0.5 baselineskip } Contents Tables of interest: 1 Mathematics 1 2 Labels and cross-reference 2 tab le of c on te nt s 2.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 listoffigures 2.2 Referencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 listoftables 2.3 Referencing a table . . . . . . . . . . . . . . . . . . . . . . . . 2 3 Tables 2 4 Graphics 3 Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 35 / 43
  • 36. Outline 1 A Introduction (or Why using LTEX?) 2 First document Document structure Form-content separation Basic commands 3 Mathematics and code 4 Playing with content 5 Going further 6 Resources Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 36 / 43
  • 37. A Guidelines to make LTEX coding easier Split the document into multiple files to avoid writing in one giant document ; input{file} inserts content as it in file ; include{file} is more flexible thanks to includeonly {file1, file2} ; Create and recreating new commands using newcommand{name}[num]{definition} with name the name of the new command, num number of arguments taken, up to 9 (default=0), definition the command itself newcommand { note } [ 1 ] { m a r g i n p a r {% n o t e s i n m a r g i n v s k i p − b a s e l i n e s k i p %r a i s e t h e m a r g i n p a r a b i t r a g g e d r i g h t f o o t n o t e s i z e color { red } { i t s h a p e h r u l e s m a l l s k i p #1} p a r s m a l l s k i p h r u l e }} newcommand { nonotes }{ renewcommand { note } [ 1 ] { } } Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 37 / 43
  • 38. A bit of debugging: DON’T PANIC! Everybody makes error like: mistype or mis-spell commands forget curly braces type a forward slash / instead of a backslash use a special character by mistake But happily: A errors and warning are well defined in LTEX log ! Undefined control sequence . l . 6 t ab le of c on te nt s an editor may help you locate or even avoid them an erroneous document is not what you want, so don’t let them! Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 38 / 43
  • 39. A bit of debugging: What can I do? A On the command line, when LTEX finds an error, you have to specify it what to do about it: Key Meaning x A stop and exit LTEX q carry on as best as possible and stop showing errors e stop and position the editor at error line (if possible) i correct here (not in the editor) and carry on r non-stop mode, ignore errors (up to 100) h try to give me more help Some editors run in non-stop mode and analyze log to show errors and warnings. http://en.wikibooks.org/wiki/LaTeX/Errors_and_Warnings Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 39 / 43
  • 40. Going local :-) Want to print pretty bengali? Use XeTEX: A a variation around LTEX (component of TeXLive) based on unicode and modern fonts systems specific syntax for new features and own binary xelatex sample . tex http://methopath.wordpress.com/2008/06/26/writing-unicode- bengali-in-latex/ Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 40 / 43
  • 41. Many (many!) packages bibtex bibliography management ; makeidx indexes management ; pstricks low-level and hitoric graphic package ; pgf modern, nice and simple graphics (preferred) ; beamer presentation class, like this one ; hyperref PDF hyperlinks management (use with caution) ; color to make colored text (use wisely) ; pdfpages to insert PDF or PS pages in a PDF ; verbatim A to insert LTEX code ; minipage to create a page in a page ; Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 41 / 43
  • 42. Editors A Both ViM and Emacs have a LTEX edition mode. http://vim-latex.sourceforge.net/ http://www.gnu.org/software/auctex/ A Kile – a LTEX Environment (for KDE) http://kile.sourceforge.net/ Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 42 / 43
  • 43. Many resources to learn even more Books: A Mittelbach Frank & Goossens Michel, The LTEX Companion, Second Edition, 2004. Donald E. Knuth, The TeX book, 1986. The Comprehensive LaTeX Symbol List (pdf) LaTeX Reference Card (pdf) Websites: http://www.latex-project.org/ – official website http://www.ctan.org/ – where you can find everything! http://www.tug.org/ – The TeX Users Group http://www.tex.ac.uk/cgi-bin/texfaq2html – The UK TeX FAQ http://en.wikibooks.org/wiki/LaTeX/ – a book being written online Stéphane Péchard (spechard) A L TEX for beginners v1.0 published under GNU FDL 43 / 43