latex for linguists

67
mitcho (Michael 貴 Erlewine) http://mitcho.com February 13, 2010 MIT / $ 7 ( ; IRU /LQJXLVWV

Upload: michael-yoshitaka-erlewine

Post on 05-Dec-2014

4.183 views

Category:

Technology


4 download

DESCRIPTION

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

TRANSCRIPT

Page 1: LaTeX for Linguists

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

February 13, 2010MIT

/$7(; IRU /LQJXLVWV

Page 2: LaTeX for Linguists

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

Today

Page 3: LaTeX for Linguists

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

Today

Page 4: LaTeX for Linguists

• 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?

Page 5: LaTeX for Linguists

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

• Extensible

Why LaTeX?

Page 6: LaTeX for Linguists

Better typesetting

Word LaTeX

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

Page 7: LaTeX for Linguists

• 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?

Page 8: LaTeX for Linguists

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

I use LaTeX for...

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

Page 9: LaTeX for Linguists

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

Today

Page 10: LaTeX for Linguists

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...

Page 11: LaTeX for Linguists

The simplest document

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

let’s try it!

Page 12: LaTeX for Linguists

Hello world! This is LATEX.

1

Page 13: LaTeX for Linguists

• Commands• with and without arguments

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

Basic syntax

Page 14: LaTeX for Linguists

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

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

Commands

Page 15: LaTeX for Linguists

• Look like “intransitive” commands:• \em

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

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

Declarations

Page 16: LaTeX for Linguists

• 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

Page 17: LaTeX for Linguists

• 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

Page 18: LaTeX for Linguists

Try this

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

x =−b±

√b2 − 4ac

2a

Page 19: LaTeX for Linguists

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

Syntax notes

Page 20: LaTeX for Linguists

• 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

Page 21: LaTeX for Linguists

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

Today

Page 22: LaTeX for Linguists

• 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

Page 23: LaTeX for Linguists

• Section headings:• \section{Quadratic formula}

• also try \section*{Quadratic formula}

• Also, subsections, subsubsections...

Document semantics

Page 24: LaTeX for Linguists

• \footnote{some text}

Footnotes

Page 25: LaTeX for Linguists

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.

Page 26: LaTeX for Linguists

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

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

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

Useful environments

Page 27: LaTeX for Linguists

• tabular

• Demarcate columns with &, rows with \\,

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

Useful environments

Page 28: LaTeX for Linguists

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

tabular

English Chinese FrenchIE Sino-Tibetan IE

Page 29: LaTeX for Linguists

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

tabular

English Chinese FrenchIE Sino-Tibetan IE

Page 30: LaTeX for Linguists

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

Local formatting

Page 31: LaTeX for Linguists

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

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

• \onehalfspacing, \doublespacing,

\singlespacing declarations

Global formatting

Page 32: LaTeX for Linguists

• 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 33: LaTeX for Linguists

Page margins

Page 35: LaTeX for Linguists

• 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

Page 36: LaTeX for Linguists

• 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

Page 37: LaTeX for Linguists

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

Today

Page 38: LaTeX for Linguists

• linguex etc.• qtree• OTtablx

• We should probably install these...

Packages for ling

Page 39: LaTeX for Linguists

• 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

Page 40: LaTeX for Linguists

linguex

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

Page 41: LaTeX for Linguists

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

Page 42: LaTeX for Linguists

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.

Page 43: LaTeX for Linguists

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.

Page 44: LaTeX for Linguists

linguex

\ex. *? this is a weird example

(1) *?this is a weird example

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

Page 45: LaTeX for Linguists

linguex

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

(1’) *?this is a similar example

Add labels in [] right after the command.

Page 46: LaTeX for Linguists

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

Page 47: LaTeX for Linguists

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

Page 48: LaTeX for Linguists

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

qtree

NPV NP

Page 49: LaTeX for Linguists

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

S

NP VP

V NP

qtree

Page 50: LaTeX for Linguists

• 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

Page 51: LaTeX for Linguists

• Unfortunately arrows are tricky with PDFLaTeX

• I just strike out items• ask me for code

• Possible motivation for a copy theory of movement

qtree

Page 52: LaTeX for Linguists

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 *!**

Page 53: LaTeX for Linguists

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 *!

Page 54: LaTeX for Linguists

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 *!

Page 55: LaTeX for Linguists

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 *!

Page 56: LaTeX for Linguists

• 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...

Page 57: LaTeX for Linguists

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

Page 58: LaTeX for Linguists

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}}}}

Page 59: LaTeX for Linguists

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

Today

Page 60: LaTeX for Linguists

• 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

Page 61: LaTeX for Linguists

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

References

Page 62: LaTeX for Linguists

• 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

Page 63: LaTeX for Linguists

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

Today

Page 64: LaTeX for Linguists

• 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

Page 65: LaTeX for Linguists

• 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

Page 66: LaTeX for Linguists

• 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日本語.

Page 67: LaTeX for Linguists

Thank you!Questions?

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