LaTeX for Linguists

Post on 05-Dec-2014

4,170 views 4 download

description

Slides from a workshop I led for some of my colleagues on typesetting lingustics in LaTeX.

transcript

mitcho (Michael 芳貴 Erlewine)http://mitcho.com

February 13, 2010MIT

/$7(; IRU /LQJXLVWV

• Intro & Why LaTeX?• Basic syntax and math• Document structure• Some packages for ling• References• Fonts, foreign languages, IPA

Today

• Intro & Why LaTeX?• Basic syntax and math• Document structure• Some packages for ling• References• Fonts, foreign languages, IPA

Today

• Typesetting• not “word processing,” WYSIWYG• edit a source in LaTeX (language) and “typeset” a PDF

• A language• based on TeX by Don Knuth

What is LaTeX?

• Better typesetting (esp. math)• Separating content and styling• easy to make global changes• easier to move things around• encourages content reuse

• Extensible

Why LaTeX?

Better typesetting

Word LaTeX

The Beauty of LaTeX, http://www.tug.org/texshowcase/

• Some people think it’s hard• steep learning curve

• Not WYSIWIG• absolute spacing/positioning is tricky

• fonts are hard, foreign languages are hard

Why not LaTeX?

• assignments;• papers;• my thesis;• my vita, resume

I use LaTeX for...

not for...• my website;• most slides (including this).

• Intro & Why LaTeX?• Basic syntax and math• Document structure• Some packages for ling• References• Fonts, foreign languages, IPA

Today

Mac:1. Go to http://www.tug.org/mactex/2009/. Download

MacTeX.mpkg.zip . Warning: the file is huge.2. Double click the download and you'll get an installer

"package" file. Double click that and install it.

Windows:1. Download this file: http://mirror.ctan.org/systems/texlive/

tlnet/install-tl.zip2. Extract (unzip) the archive. Go in the install-tl folder,

and double click on the item called install-tl.bat. This will start the installation. Follow the steps. Warning: this installation can take an hour or two.

but first...

The simplest document

\documentclass{article}\begin{document}Hello world! {\em This} is \LaTeX.\end{document}

let’s try it!

Hello world! This is LATEX.

1

• Commands• with and without arguments

• “Declarations”• Environments• We’ve already seen them all!

Basic syntax

• With argument:• \documentclass{article}• arguments are in {}, optional arguments in []• \documentclass[a4paper]{article}

• Without argument: \LaTeX• * often gives you a variant (later)

Commands

• Look like “intransitive” commands:• \em

• Changes the “environment”: in this case, italicization

• Scope delimited by {}, with the declaration inside:• {\em This}

Declarations

• Block off a section of your text which will be rendered using special formatting rules

• Always \begin and \end• \begin{document} ... \end{document}• May license new commands or declarations within

Environments

• Put inline math in dollar signs $• Find the value of $x$.

• Put centered formula in double dollar signs, $$...$$

• Use the symbol cheat sheet• http://www.stdout.org/̃ winston/latex/latexsheet.pdf

Math mode

Try this

To solve for roots of the expression ax2 + bx + c = 0, use the followingformula:

x =−b±

√b2 − 4ac

2a

• % can be used for comments• Clearly, then, {, }, $, and % can’t be used normally• If we want to print these characters, escape with \

Syntax notes

• LaTeX syntax is pretty strict, but your editor can help you (maybe).

• If you haven’t already, make a syntax error now.

• Look for typos, unclosed braces, missing arguments, unclosed environments...

Common syntax pitfalls

• Intro & Why LaTeX?• Basic syntax and math• Document structure• Some packages for ling• References• Fonts, foreign languages, IPA

Today

• Recall: LaTeX separates content and formatting1. use semantic organization in the

content2. use minimal inline formatting3. set global formatting in the

“preamble” or towards the top

Document structure

• Section headings:• \section{Quadratic formula}

• also try \section*{Quadratic formula}

• Also, subsections, subsubsections...

Document semantics

• \footnote{some text}

Footnotes

Try this1 Quadratic formula

To solve for roots of the expression ax2 + bx+ c = 0, use the following formula:

x =−b±

√b2 − 4ac

2a

2 Next section

This is complicated.1

2.1 New subsection

Aside

This is an aside, so don’t number me.

1really.

1 Quadratic formula

To solve for roots of the expression ax2 + bx+ c = 0, use the following formula:

x =−b±

√b2 − 4ac

2a

2 Next section

This is complicated.1

2.1 New subsection

Aside

This is an aside, so don’t number me.

1really.

• Recall: \begin{} ... \end{}• center

• enumerate and itemize• Introduce each item with \item• \begin{enumerate}

\item Item 1\item Item 2\end{enumerate}

Useful environments

• tabular

• Demarcate columns with &, rows with \\,

• Confusing syntax... see cheat sheet for column specs

Useful environments

\begin{tabular}{ccc}English&Chinese&French\\IE&Sino-Tibetan&IE\\\end{tabular}

tabular

English Chinese FrenchIE Sino-Tibetan IE

\begin{tabular}{¦c¦c¦c¦}\hlineEnglish&Chinese&French\\\hlineIE&Sino-Tibetan&IE\\\hline\end{tabular}

tabular

English Chinese FrenchIE Sino-Tibetan IE

• All on the cheat sheet...• \textbf{}, \textit{}, \underline{}...• \large, \small declarations• \begin{center} ... \end{center}

Local formatting

• Paragraphs• \parskip = 0.1in• \parindent = 0.0in

• Set spacing with setspace• \usepackage{setspace} in preamble (before \begin{document})

• \onehalfspacing, \doublespacing,

\singlespacing declarations

Global formatting

• Packages are .sty• Get it online• search, or go straight to CTAN:• http://www.ctan.org

• Place together with source or find your texmf/tex/latex directory

Aside: getting packages

Page margins

• Declare \pagestyle{}, \thispagestyle{} with empty, plain• Search pagestyle for more

• Check out the fancyhdr package• http://www.ctan.org/tex-archive/macros/latex/contrib/fancyhdr/

Headers and footers

• Good, very detailed slides “LaTeX for linguists” from Tromsø:• http://uit.no/getfile.php?SiteId=50&PageId=874&FileId=303

• Learn about reformatting section headings, enumerate formatting, etc.

More global formatting

• Intro & Why LaTeX?• Basic syntax and math• Document structure• Some packages for ling• References• Fonts, foreign languages, IPA

Today

• linguex etc.• qtree• OTtablx

• We should probably install these...

Packages for ling

• Today we’ll try linguex, which a few people recommended.• I personally normally use gb4e.• I think linguex’s syntax is weird and non-TeX-y, but people think it’s easy to use.

Glossed examples

linguex

• In the preamble, \usepackage{linguex}• Requires xspace, cgloss4e

linguex

\ex. this is an example \a. next level \b. another level of example

\a. another level

(1) this is an example

a. next levelb. another level of example

(i) another level

linguex

\ex. this is an example\a. next level\b. another level of example\a. another level

(1) this is an example

a. next levelb. another level of example

(i) another level

As with most of TeX, whitespace doesn’t matter. \a. is just special.

linguex

\ex. this is an example \a. next level \b. another level of example

\a. another level\z.

\c. back down

(1) this is an example

a. next levelb. another level of example

(i) another levelc. back down

Go back down with \z.

linguex

\ex. *? this is a weird example

(1) *?this is a weird example

Add judgments right after the command with a space in between.

linguex

\ex.[(1')] *? this is a similar example

(1’) *?this is a similar example

Add labels in [] right after the command.

linguex

\exg. Zhangsan xihuan ziji\\ Zhangsan like self\\ `Zhangsan likes himself'

(1) ZhangsanZhangsan

xihuanlike

zijiself

‘Zhangsan likes himself’

Add g to any command to get aligned glosses

TreesS

∃s1∃s2(like(TOM, s1) ∧ Exp(JOHN, s1)∧like(TOM, s2) ∧ Exp(MARY, s2) ∧ s1 ≫ s2)

TnonpastλP��,t�∃�P

λs1.∃s2(like(TOM, s1) ∧ Exp(JOHN, s1)∧like(TOM, s2) ∧ Exp(MARY, s2) ∧ s1 ≫ s2)

DP

JohnJOHN

λxλs1.∃s2(like(TOM, s1) ∧ Exp(x, s1)∧like(TOM, s2) ∧ Exp(MARY, s2) ∧ s1 ≫ s2)

DP

MaliMARY

vλyλxλs1.∃s2(like(TOM, s1) ∧ Exp(x, s1)∧

like(TOM, s2) ∧ Exp(y, s2) ∧ s1 ≫ s2)

v

biλG�e,��,t��λyλxλ�1.∃�2

(G(x, �1) ∧ G(y, �2) ∧ �1 ≫ �2)

vλxλs.like(TOM, s) ∧ Exp(x, s)

predicate ofcomparison

• Basic syntax is straightforward:• \Tree [ NP [ V NP ] ]

qtree

NPV NP

• Add node labels...• \Tree [.S NP [.VP V NP ] ]

S

NP VP

V NP

qtree

• Add triangles...• \Tree [.S \qroof{my car}.NP [.VP V

NP ] ]

• For some reason \qroof’s always need node labels... :/

S

NP

my car

VP

V NP

qtree

• Unfortunately arrows are tricky with PDFLaTeX

• I just strike out items• ask me for code

• Possible motivation for a copy theory of movement

qtree

Tableau

/in, tapiq/ Onset Alignasp-L

a. ☞ t-i.n-a.piq *

b. in.-ta.piq *!

c. ta.pi.q-in *!****

d. ta.p-in.-iq *!**

In preamble, \usepackage[notipa]{OTtablx}

OTtablx

\begin{OTtableau}{2}\OTtoprow*[/in, tapiq/]{Onset, Align}\OTcandrow{t-i.n-a.piq}{,*}\OTcandrow{in.-ta.piq}{*!,}\end{OTtableau}

/in, tapiq/ Onset Align

a. t-i.n-a.piq *

b. in.-ta.piq *!

Also, \OTdashes{}

OTtablx

\begin{OTtableau}{2}\OTsolids{1}\OTtoprow*[/in, tapiq/]{Onset, Align}\OTcandrow{t-i.n-a.piq}{,*}\OTcandrow{in.-ta.piq}{*!,}\end{OTtableau}

/in, tapiq/ Onset Align

a. t-i.n-a.piq *

b. in.-ta.piq *!

OTtablx

\begin{OTtableau}{2}\OTsolids{1}\OTtoprow*[/in, tapiq/]{Onset, Align}\OTcandrow[\OThand]{t-i.n-a.piq}{,*}\OTcandrow{in.-ta.piq}{*!,}\end{OTtableau}

/in, tapiq/ Onset Align

a. ☞ t-i.n-a.piq *

b. in.-ta.piq *!

• I highly recommend TikZ• Tricky syntax, but anything is possible.• http://www.texample.net/tikz/examples/

• Use for crazy trees, finite state automata, Hasse diagrams, etc.

Any other diagram...

TikZ

\begin{tikzpicture}[auto] \node (I) at (0,2.5) [shape=circle,draw,label=left:{input:}] {I}; \node (R) at (-1.7,0) [shape=circle,draw,label=left:{output:}] {R}; \node (B) at (1.7,0) [shape=circle,draw] {B};

\draw[<->,dashed] (I) to node [swap] {I-R} (R); \draw[<->] (R) to node [swap] {B-R} (B); \draw[<->] (B) to node [swap] {I-O} (I);\end{tikzpicture}

.

.I.input:

.R.output: .B

.I-R

.B-R

.I-O

Extras

• I’ll send out code later

\usepackage{stmaryrd} % for \sem\newcommand{\Sem}[2][]{\ensuremath{\llbracket #2\rrbracket^{#1}}}%\newcommand{\sem}[2][M\!,g]{\mbox{ $[\![ #2 ]\!]^{#1}$}}

%Define \Bracket{}, for Type Theory or algebraic ideals.\newcommand{\Bracket}[1]{\ensuremath{\langle #1\rangle}}

%Define \xbar{}, a bar-level command\newcommand{\xbar}[1]{\ensuremath{\overline{\mathrm{#1}}}}

• Intro & Why LaTeX?• Basic syntax and math• Document structure• Some packages for ling• References• Fonts, foreign languages, IPA

Today

• Refer to numbered things• Sections, footnotes, list items, examples...

• Use \label{marker name} in the numbered thing

• Refer to it using \ref{marker name}

References

• \label, \ref• Make sure to run LaTeX a couple times, else you’ll get ?

References

• Do citations and bibliographies• EX: \cite{chomsky1977}• Automagically creates bibliography!• Requires a separate file format :/• On the Mac, use BibDesk! :D• Again, run a couple times.

BibTeX

• Intro & Why LaTeX?• Basic syntax and math• Document structure• Some packages for ling• References• Fonts, foreign languages, IPA

Today

• Fonts used to be a pain...• Really. I won’t even tell you how ugly it was.

• Foreign languages and IPA was also kind of painful.

• ...until XeTeX/XeLaTeX• By Jonathan Kew at SIL

Fonts

• XeLaTeX is LaTeX rebuilt for unicode and system fonts• enter foreign scripts directly

• Made even better with fontspec• Just choose to typeset with XeLaTeX and \usepackage{fontspec}

• \setmainfont{Palatino}

XeLaTeX + fontspec

• Define other fonts in the preamble:• \newfontinstance\Japanese{Hiragino

Mincho Pro W3}

• Use it like {\Japanese 日本語}

• Use a font like Gentium (SIL) for IPA

XeLaTeX + fontspec

This is日本語.

Thank you!Questions?

mitcho (Michael 芳貴 Erlewine)mitcho.com; @mitchoyoshitaka