Jump to content

LaTeX/Linguistics

From Wikibooks, open books for an open world

LaTeX

Getting Started
  1. Introduction
  2. Installation
  3. Installing Extra Packages
  4. Basics
  5. How to get help

Common Elements

  1. Document Structure
  2. Text Formatting
  3. Paragraph Formatting
  4. Colors
  5. Fonts
  6. List Structures
  7. Special Characters
  8. Internationalization
  9. Rotations
  10. Tables
  11. Title creation
  12. Page Layout
  13. Customizing Page Headers and Footers‎
  14. Importing Graphics
  15. Floats, Figures and Captions
  16. Footnotes and Margin Notes
  17. Hyperlinks
  18. Labels and Cross-referencing
  19. Initials

Mechanics

  1. Errors and Warnings
  2. Lengths
  3. Counters
  4. Boxes
  5. Rules and Struts

Technical Text

  1. Mathematics
  2. Advanced Mathematics
  3. Theorems
  4. Chemical Graphics
  5. Algorithms
  6. Source Code Listings
  7. Linguistics

Special Pages

  1. Indexing
  2. Glossary
  3. Bibliography Management
  4. More Bibliographies

Special Documents

  1. Scientific Reports (Bachelor Report, Master Thesis, Dissertation)
  2. Letters
  3. Presentations
  4. Teacher's Corner
  5. Curriculum Vitae
  6. Academic Journals (MLA, APA, etc.)

Creating Graphics

  1. Introducing Procedural Graphics
  2. MetaPost
  3. Picture
  4. PGF/TikZ
  5. PSTricks
  6. Xy-pic
  7. Creating 3D graphics

Programming

  1. Macros
  2. Plain TeX
  3. Creating Packages
  4. Creating Package Documentation
  5. Themes

Miscellaneous

  1. Modular Documents
  2. Collaborative Writing of LaTeX Documents
  3. Export To Other Formats

Help and Recommendations

  1. FAQ
  2. Tips and Tricks

Appendices

  1. Authors
  2. Links
  3. Package Reference
  4. Sample LaTeX documents
  5. Index
  6. Command Glossary

edit this boxedit the TOC

There are a number of LaTeX packages available for writing linguistics papers. Various packages have been created for enumerated examples, syntactic trees, OT tableaux, feature matrices, IPA fonts, and many other applications. Some packages such as the tipa package are effectively standard within the field, while others will vary by author preference.

Some recommended packages:[1]

  • Glosses: gb4e or Covington;
  • IPA symbols: tipa;
  • OT Tableaux: OTtablx;
  • Syntactic trees: qtree + tree-dvips (for drawing arrows);
  • Alternatively, xyling is very powerful but not as user friendly as qtree;
  • The xy package itself has a steep learning curve, but allows a lot of control; for simplest trees use the xymatrix feature and arrows;
  • tikz-qtree has the same syntax as qtree, but uses PGF/TikZ, which allows more options for drawing arrows, etc.
  • Dependency trees and bubble parses:
  • The TikZ-dependency package provides a high-level, convenient interface to draw dependency graphs. It is based on PGF/TikZ but does not require prior knowledge of TikZ in order to be used productively.
  • Attribute-Value Matrices (AVMs): avm
  • John Frampton's expex: expex

Enumerated examples

[edit | edit source]

There are several commonly used packages for creating the kinds of numbered examples that are used in linguistics publications.

The gb4e package

[edit | edit source]

The gb4e package[2], last updated in 2010, is called with:

\usepackage{gb4e}

IMPORTANT: If you use gb4e package, let it be the last \usepackage call in the document's preamble. Otherwise you may get exceeded parameter stack size error.

Examples for this package are placed within the exe environment, and each example is introduced with the \ex command.

\begin{exe}
	\ex This is an example.
\end{exe}


Multiple examples can be included within the environment, and each will have its own number.

\begin{exe}
	\ex This is the first example.
	\ex This is the second example.
	\ex This is the third.
\end{exe}


To create nested lists of examples, the xlist enviroment is used.

\begin{exe}
    \ex \begin{xlist}
        \ex This is a sub-example.
        \ex This is a second sub-example.
        \ex \begin{xlist}
            \ex This is a sub-sub-example.
            \ex This is a second sub-sub-example.
        \end{xlist}
    \end{xlist}
\end{exe}


For notating acceptability judgments, the \ex command can take an optional argument. When including a judgment marker, the corresponding sentence must be surrounded by braces.

\begin{exe}
	\ex This sentence is grammatical English.
	\ex[*] {This sentence English in ungrammatical is.}
\end{exe}


Referencing examples in text works as it does in normal LaTeX documents. See the labeling and cross-referencing section for more details.

\begin{exe}
	\ex\label{ex1} Godzilla destroyed the city.
	\ex\label{ex2} Godzilla roared.
\end{exe}
Sentence (\ref{ex1}) contains two arguments, but (\ref{ex2}) contains only one.


Further details can be found in the full documentation available here.

The ling-macros package

[edit | edit source]

The ling-macros package[3] created by Emma Pease and last updated in 2016, is an alternate method for example numbering. This package uses two main commands, \enumsentence and \eenumsentence. The former is used for singleton examples, while the latter command is used for nested examples.

\enumsentence{This is an example.}


\enumsentence{This is the first example.}
\enumsentence{This is the second example.}
\enumsentence{This is the third.}


Multiply nested examples make use of the normal LaTeX list environments.

\eenumsentence{\item This is a sub-example.
		\item This is a second sub-example.
		\item \begin{enumerate}
			\item This is sub-sub-example.
			\item This is a second sub-sub-example.
			\end{enumerate}
                 }


Full documentation can be found here.

Syntactic trees

[edit | edit source]

Often, linguists will have to illustrate the syntactic structure of a sentence. One device for doing this is through syntactic trees. Unfortunately, trees look very different in different grammar formalisms, and different LaTeX packages are suited for different formalisms.

Constituent trees

[edit | edit source]

While there are several packages for drawing syntactic trees available for LaTeX, this article focuses on the qtree and xyling packages.

The qtree package

[edit | edit source]

Drawing trees with qtree is relatively straightforward. First, the qtree package, last updated in 2006, has to be included in the document's preamble:

\usepackage{qtree}

A new tree is started using the \Tree command, each (sub-)tree is indicated by brackets [ ]. The root of a (sub-)tree is always preceded by a ., leaf nodes are simply expressed by their labels. Note that the spaces before the closing brackets are mandatory.

\Tree [.S [.NP LaTeX ] [.VP [.V is ] [.NP fun ] ] ]

By default, qtree centers syntactic trees on the page. This behaviour can be turned off by either specifying the behaviour when loading the package

\usepackage[nocenter]{qtree} % do not center trees

or via the command

\qtreecenterfalse % do not center trees from here on

anywhere in the document. The effect of the latter can be undone by using the command

\qtreecentertrue % center trees from here on

IMPORTANT: If you use gb4e package, let it be the last \usepackage call in the document's preamble. Otherwise you may get exceeded parameter stack size error.

tikz-qtree

[edit | edit source]

Using the same syntax as qtree, tikz-qtree, last updated in 2009, is another easy-to-use alternative for drawing syntactic trees.

For simple trees, tikz-qtree is completely interchangable with qtree. However, some of qtree's advanced features are implemented in a different way, or not at all. On the other hand, tikz-qtree provides other features such as controlling the direction of the tree's growth (top to bottom, left to right etc.) or different styles for edges.

To use the tikz-qtree package for drawing trees, put the following into the document's preamble:

\usepackage{tikz}
\usepackage{tikz-qtree}

The syntax of tikz-qtree and result when drawing a simple tree is the same as for qtree.

\Tree [.S [.NP LaTeX ] [.VP [.V is ] [.NP fun ] ] ]

Note that, other than for qtree, trees are not centered by default. To center them, put them into a centered environment:

\begin{center}
\Tree [.S [.NP LaTeX ] [.VP [.V is ] [.NP fun ] ] ]
\end{center}

For setting the style of trees, tikz-qtree provides the \tikzset command. For example, to make a tree grow from left to right instead of from top to bottom, use the following code:

\tikzset{grow'=right} % make trees grow from left to right
\tikzset{every tree node/.style={anchor=base west}} % align nodes of the tree to the left (west)
\Tree [.S [.NP LaTeX ] [.VP [.V is ] [.NP fun ] ] ]

The above code changes the default orientation for all trees that are defined after \tikzset commands. To only change the direction of a single tree, it has to be put into a \tikzpicture environment:

\begin{tikzpicture} % all changes only affect trees within this environment
\tikzset{grow'=right} % make trees grow from left to right
\tikzset{every tree node/.style={anchor=base west}} % align nodes of the tree to the left (west)
\Tree [.S [.NP LaTeX ] [.VP [.V is ] [.NP fun ] ] ]
\end{tikzpicture}


Dependency Trees

[edit | edit source]

Dependency trees can take multiple visual forms. Commonly, they quite resemble phrase structure trees. Alternatively, they can be captured by brackets drawn above running text.


Two-dimensional Dependency Trees

[edit | edit source]

These can be either achieved using the fairly universal drawing package tikz or the package xyling, last updated in 2006:

% In the preamble:
\usepackage{tikz}

% In the document:
\begin{tikzpicture}
	\node (is-root) {is}
		[sibling distance=3cm]
		child { node {this} }
		child {
			node {tree}
				[sibling distance=1.5cm]
				child { node {an} }
				child { node {example} }
				child { node {.} }
				child[missing]
		};
	\path (is-root) +(0,-2.5\tikzleveldistance)
		node {\textit{This is an example tree.}};
\end{tikzpicture}
A dependency tree created using TikZ

TikZ has the advantage that it allows for generating PDF directly from the LaTeX source, without need for any detour of compiling to DVI using latex, and then converting to PDF probably via PS using tools such as dvips and ps2pdf.

An alternative to tikz is the package xyling, which is in turn based on the package xy.

% In the preamble:
\usepackage{xyling}

% In the document:
\Tree{	& \K{is}\B{dl}\B{drr} \\
        \K{this} &&& \K{tree}\B{dll}\B{dl}\B{dr} \\
        & \K{an} & \K{example} && \K{.} }

\medskip
\textit{This is an example tree.}
A dependency tree created using xyling

Dependency Trees as Brackets above Text

[edit | edit source]

One way to typeset dependency brackets above running text is using the package xytree. It gives you fairly good control of how the brackets are typeset, but requires compiling the LaTeX code to DVI (and perhaps converting to PDF using the tools dvips and ps2pdf later).

% In the preamble:
\usepackage{xytree}

% In the document:
\xytext{
  \xybarnode{Peter} &~~~&
  \xybarnode{and}
    \xybarconnect(UL,U){-2}"_{\small conj}"
    \xybarconnect(UR,U){2}"^{\small conj}"
    &~~~&
  \xybarnode{Mary} &~~~&
  \xybarnode{bought}
    \xybarconnect[8](UL,U){-4}"_{\small subj}"
    \xybarconnect[13]{6}"^{\small punct}"
    \xybarconnect[8](UR,U){4}"^{\small obj}"
    &~~~&
  \xybarnode{a} &~~~&
  \xybarnode{car}
    \xybarconnect(UL,U){-2}"_{\small det}"
    &~~~&
  \xybarnode{.}
}

A dependency tree above running text created using xytree

Dependency Trees using the tikz-dependency package

[edit | edit source]

The tikz-dependency package, last updated in 2012, provides high level commands to design and style dependency graphs. To draw a graph, you only need to create a dependency environment, write the text of the sentence within the deptext environment and use \depedge commands to draw the edges. Global and local optional parameters can be used to style and fine tune the looks of the graph, as shown in the following example:

% In the preamble:
\usepackage{tikz-dependency}

% In the document:
\begin{dependency}[theme = simple]
   \begin{deptext}[column sep=1em]
      A \& hearing \& is \& scheduled \& on \& the \& issue \& today \& . \\
   \end{deptext}
   \deproot{3}{ROOT}
   \depedge{2}{1}{ATT}
   \depedge[edge start x offset=-6pt]{2}{5}{ATT}
   \depedge{3}{2}{SBJ}
   \depedge{3}{9}{PU}
   \depedge{3}{4}{VC}
   \depedge{4}{8}{TMP}
   \depedge{5}{7}{PC}
   \depedge[arc angle=50]{7}{6}{ATT}
\end{dependency}

A dependency tree drawn with TikZ-dependency

For more details see the TikZ-dependency documentation

Glosses

[edit | edit source]

Below is how to make glossed examples with different packages.

With gb4e

[edit | edit source]

To create a glossed example with gb4e, last updated in 2010, use the normal exe environment. But after the \ex tag, introduce the example and its gloss using \gll and the translation after it with \trans tag.

\begin{exe}
\ex 
\gll Кот ест сметану\\
cat.NOM eat.3.SG.PRS sour-cream.ACC\\
\trans `The cat eats sour cream'
\end{exe}


Vertically aligned glosses are separated by spaces, so if it's necessary to include a space in part the gloss, simply enclose the connected parts inside braces.

\begin{exe}
\ex	
\gll Pekka pel\"astyi karhusta.\\
     Pekka {became afraid} bear.ELA\\
\trans `Pekka became afraid because of the/a bear.'
\end{exe}

With ling-macros

[edit | edit source]

The ling-macros package, last updated in 2016, uses the \shortex command to introduce glossed examples inside the \enumsentence and \eenumsentence commands. This command takes four arguments and builds off the normal tabular environment. Its first argument specifies the number of columns in the gloss. The second and third arguments give the text and its gloss respectively, and items within each column are divided by the usual & tabular separator. The fourth argument is the translation.

\enumsentence{\shortex{3}
		{Pekka & pel\"astyi & karhu-sta.}
		{Pekka & became afraid & bear.ELA}
		{`Pekka became afraid because of the/a bear.'}
		}

IPA characters

[edit | edit source]

The tipa package, last updated in 2004, was the standard LaTeX package for International Phonetic Alphabet symbols before the widespread adoption of Unicode. Now, however, IPA symbols in Unicode can be used directly in LaTeX in combination with Template:XeLaTeX and Template:LuaLaTeX, greatly improving readability.

\usepackage{tipa}

There are two methods for getting IPA symbols into a document. The first way is to use the IPA environment.

\begin{IPA}
text in IPA format here
\end{IPA}

This method is useful for long stretches of text that need to be in IPA. Alternatively, there is the \textipa command that will format the text in its argument into IPA. This command is similar to other font typesetting commands.

\textipa{text in IPA format here}

Basic symbols

[edit | edit source]

The IPA format works by translating ASCII characters into corresponding IPA symbols. Lower case letters are rendered as usual,

\textipa{abcdefghijklmnopqrstuvwxyz}

however capital letters are rendered differently.

\textipa{ABCDEFGHIJKLMNOPQRSTUVWXYZ}

Punctuation marks that are normally used in LaTeX are also rendered faithfully in the IPA environment.

\textipa{! * + = ? . , / [ ] ( ) ` ' | ||}

Numerals and @ also have variants in the IPA environment.

\textipa{1234567890 @}

In addition, there are a number of special macros for representing symbols that don't have other associations, some of which are listed here. For a complete list see the official TIPA Manual[4].

The \; macro preceding a capital letter produces a small caps version of the letter.

\textipa{\;A \;B \;E \;G \;H \;I \;L \;R \;Y}

The \: macro produces retroflex symbols.

\textipa{\:d \:l \:n \:r \:s \:t \:z}

The \! macro produces implosive symbols and the bilabial click.

\textipa{\!b \!d \!g \!j \!G \!o}

XeLaTeX

[edit | edit source]

The modern way of inputting IPA symbols in a document is to use XeTeX as the compiler and insert the symbols directly, using a character map or an IPA keyboard.[5]

You can type [fəˈnɛtɪk] symbols in a straightforward manner.

Phonological rules

[edit | edit source]

Typesetting phonological rules can be done with the help of the phonrule package, last updated in 2017.[6]

Following is an example of what you can achieve with the package:

\phonb{\phonfeat{+stop \\ +consonant \\ +alveolar} }{[ɾ]}{\phonfeat{+vowel \\ +stressed} }{\phonfeat{+vowel \\ +stressed} }

References

[edit | edit source]
  1. [1] LaTeX for Linguists presentation
  2. [2] The gb4e package on CTAN
  3. [3] The ling-macros package on CTAN
  4. TIPA manual
  5. For more information on IPA keyboards, see SIL [4].
  6. [5] The package on CTAN.
[edit | edit source]


Previous: Source Code Listings Index Next: Indexing