\documentclass[12pt,letterpaper,hidelinks]{article}

\usepackage{tikz} % one of the general packages for creating diagrams in latex; needed for tikz-qtree (next line)
\usepackage{tikz-qtree} % draws syntax trees
\usepackage{amsmath} % a pretty standard package to enlarge your inventory of symbols
\usepackage{amssymb} % another common package for symbols
\usepackage[hidelinks]{hyperref} % enables hyperlinks in your document (no worries -- they show up only on the screen. When you print a hard copy, the colored boxes aren't there)
\usepackage{url} % helps typeset URLs properly, typically with the command \url
\usepackage[margin=1in]{geometry} % page layout
\usepackage{tipa} % IPA symbols
\usepackage{booktabs} % creates beautiful and professional tables
\usepackage{bussproofs} % easily creates logical proof trees
\usepackage{linguex} % for examples and morpheme glossing
\usepackage{natbib} % for bibliography management



%% ----------------------------------------------------------------------------%`
%% ----------------------------------------------------------------------------%


\begin{document}


%\newcommand{\sref}[1]{\S\red{#1} %the 1 calls up one argument



\title{A \LaTeX\ Tutorial for Linguists
\author{Original author:\\
Jackson Lee, University of Chicago\\
\url{jsllee@uchicago.edu} \and
Updated and expanded by:\\ 
Adam Roth Singerman, University of Chicago\\
\url{adamsingerman@uchicago.edu} \and
Daniel Puthawala, The Ohio State University, University of Chicago \\
\url{puthawala.1@osu.edu} \and
Christian Clark, The Ohio State University\\
\url{clark.3664@osu.edu}}}

\maketitle


\begin{abstract}
This is a \LaTeX\ template for linguists who are new to \LaTeX\ and who would like to learn how it can be used to create professional documents. This tutorial goes over the basics of \LaTeX\ document formatting and shows you some basic tools that are extremely important for linguistics scholarship, including automatically aligned interlinear glossing and fancy shmancy trees. Since this tutorial is always a work in progress, please feel free to send e-mails to any of the authors listed above. Compliments should be reserved for Jackson, who authored the original version; criticisms should go to Adam, Daniel, and Christian.
\end{abstract}

%\tableofcontents


%% ----------------------------------------------------------------------------%

\section{Introduction}

Welcome to the world of \LaTeX! The learning curve is fairly steep, but your efforts will pay off as you gradually get the hang of this amazing tool. As you move along, there may be moments when things don't quite work as intended and you get frustrated. Google usually has answers to the questions you have (search by ``latex xxx'').\footnote{Also: \url{http://en.wikibooks.org/wiki/LaTeX}. By the way, this is a footnote. To introduce it, just use \texttt{\textbackslash footnote\{\}}, with whatever text your note is to contain in between the curly brackets.}

%% ----------------------------------------------------------------------------%

\section{The Five Commandments of \LaTeX}

\begin{enumerate}
    \item Start with a template and adapt
    
    \item Compile often (every other sentence, or more often for equations, tables, etc.)
    
    \item Ask someone if you get stuck. Google, Stack Exchange, and Detexify are your friends!
    
    \item If you have an error, check for balanced \{\ \}, [\ ], \$\ \$
    
    \item If you have an error, comment out what you just wrote and see if it fixes itself; then you know where the problem is
\end{enumerate}

%% ----------------------------------------------------------------------------%

\section{Packages}

\subsection{What are packages?}

Packages add new capabilities to your \LaTeX\ system, so to speak. They define new commands that do something you need. Quite often, different packages can do the same thing.

\subsection{How do we tell \LaTeX which packages we are using?}

In the .tex file, the code preceding \texttt{\textbackslash begin\{document\}} is called the preamble. You call the packages using the \texttt{\textbackslash usepackage} command in the preamble. Side track: By now, probably you've noticed that all commands begin with the backslash symbol \texttt{ \textbackslash}. (Then how do we actually type and show a backslash?  See the \LaTeX\ code for the answer.  This will happen a lot during this tutorial.)

\subsection{Where do packages come from?}

There are packages that are useful for \LaTeX\ users in general, as well as those more specific for linguists. Most of them are available on one of the repositories readily accessible by your \LaTeX\ distribution. So if you are trying to use a new package that your computer hasn't downloaded yet, it should be downloaded automatically when you hit ``Typeset'' (assuming correct configurations).

\subsection{How do we learn to use particular packages?}

Packages come with their documentation. If you want to try out or learn how to use a package X, google ``latex X documentation'' and a .pdf file is usually located -- it should be the documentation, or manual, of that package.


%% ----------------------------------------------------------------------------%


\section{Formatting}


\subsection{Comments}

One of the wonderful things about \LaTeX\ is that you can include content in the .tex file that doesn't show up in the output .pdf. We call these \textsc{comments}. In your .tex file, anything that comes on a line of text after the \texttt{\%} symbol is ignored in compiling the .pdf file. This is useful for making notes as well as making your .tex much more readable. For several examples, just take a look at the code of this file. You'll notice, for example, that each of the packages called up in the preamble has a helpful summary following the \texttt{\%}. These summaries have absolutely zero impact on the .pdf that gets produced.

\subsection{Indentation and spacing}

This is a paragraph. Take note of its indentation.

This is another paragraph. Also take note of its indentation here. In the .tex document, you separate two paragraphs by a blank line.

\noindent This is a third paragraph. Here we used the \texttt{\textbackslash noindent} command to get rid of the usual indentation!

\vspace{5mm}

This is a fourth paragraph. We added some vertical space before this one with \texttt{\textbackslash vspace\{\}}. You can also use \texttt{\textbackslash hspace\{\}} to add horizontal space \hspace{10mm} like \hspace{10mm} so.

\subsection{Another subsection!}

Basic stuff: \textbf{bold}, \textit{italic}, \textsc{small caps}, \underline{underlined}

\subsubsection{WOW -- a subsubsection}

Quotation marks. Compare the \LaTeX\ code and the quotation marks displayed here very carefully: ``hello'', `hello', 'hello', "hello".


%% ----------------------------------------------------------------------------%


\section{Symbols}

Accents. Vous \^{e}tes... Tr\`{e}s bien !
% Full list of these escaped diacritics: https://en.wikibooks.org/wiki/LaTeX/Special_Characters#Escaped_codes

IPA symbols? Package: \texttt{tipa} Examples: \textipa{@abcdeABCDE12345}



%% ----------------------------------------------------------------------------%

\section{Tables}

Bare minimum to create tables:\\ % see the two backslashes just here? They force a blank line just below them.

\noindent Table 1:\\

\begin{tabular}{lll}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{tabular}\\

\vspace{5mm}

\noindent Table 2:\\

\begin{tabular}{|l|l|l|}
\hline
1 & 2 & 3 \\
\hline
4 & 5 & 6 \\
\hline
7 & 8 & 9 \\
\hline
\end{tabular} \\


Check out the package \texttt{booktabs} for more professional tables.


%% ----------------------------------------------------------------------------%

\section{Morpheme glossing and in-text referencing} \label{glossing}

We will use the \texttt{Linguex} package for several important tasks, such as inserting examples, and doing glosses.  Look a how we can easily make multiply embedded examples below!

\ex. This is the first level of embedding
	\a. This is the second level %Each 'a' increases the level of embedding
	\b. This is still the second level, but:
		\a. This is the third level
		\b. This is not the end.
		\b. This is the end of the innermost embedding
	\z. %this command reduces the level of embedding by one
\b. and this is the next item in the second level

%note how we left an open space above.  The blank line ends the \ex environment.
\ex. This is the next example/table/figure


We can also use the \texttt{Linguex} package to do easily do glosses, and we can use the regular label and refer to examples and glosses in the following manner.  Check out the text in the .tex file here and in \ref{Apple}, \ref{Orange}, and \ref{Grapes}, as well as in \ref{Easy} and \ref{Peasy}. 


%If we use \exg. it will auto-match the spacing
\exg. Dies ist eine Glosse\\  
This is a gloss\\	\label{Apple}


%Remember to include and empty line to end the example!
%If we just use \ex., it works fine for monolingual exampes, but glossing will not work, see?
\ex.  Dies ist nicht eine Glosse\\ 
This is not a gloss\\	\label{Orange}

%You can also easily add acceptability judgment flags, like this, which is unacceptable to any speaker of English, Yoda notwithstanding.
\ex. $\%$*This English not is. \label{Grapes}\\


%Here's some more complicated examples of glossing, using IPA characters
\exg. \textipa{vajaSav} \textipa{josef} \textipa{mi\t{ts}eKajima}\\
return.\textsc{perf}.3.\textsc{pl}.\textsc{masc} Joseph Egypt.ward\\
`Joseph returned to Egypt' (Genesis 50:14)\label{Easy}


\exg. \textipa{vajEmahEK} \textipa{aveKaham} \textipa{haPohela}\\
hurry.\textsc{perf}.3.\textsc{sg}.\textsc{masc} Abraham \textsc{def}.tent.ward\\
`Abraham hurried (in)to the tent' (Genesis 18:6)\label{Peasy}

%It's possible to do glosses with more than two space-matched lines, but the syntax changes a bit. Uncomment the next few lines to see an example:
%
%\ex. \glll Dies ist eine Glosse\\  
%This is a gloss\\
%Esta es una glosa\\

 As with regular labeling and referring, you can even drag labeled things around, and \LaTeX\ will automatically renumber the examples appropriately and keep the reference numbers connected to the same example as before.  More on this below in Section \ref{labeling}. %See what I did there?


%%% ----------------------------------------------------------------------------%
%
\section{Making glossing even easier}



\exg. The students all adore me.\\
The student-s all adore-$\emptyset$ me.\\
\textsc{art} student-\textsc{pl} all adore-\textsc{pl} \textsc{1sg.acc}\\
The students all adore me.
\label{thestudentsalladoreme}\\

It is a major waste of time to have to rewrite \textsc{1sg.acc} every time you need to gloss the pronoun `me.' So we can just write a command that stores this gloss for us:

\newcommand{\megl}[0]{\textsc{1sg.acc}}

\begin{itemize}

	\item \texttt{\textbackslash newcommand\{\textbackslash megl\}[0]\{\textbackslash textsc\{1sg.acc\}\}}  %This complicated looking part is just to make the text for the new command pop up as a bullet in the PDF.  There are no working parts here, so don't freak out!

\end{itemize}

This tells LaTeX to make a new command with the name \texttt{\textbackslash megl} (for `me-gloss', though you could call it anything you want). This command will take zero arguments. It will automatically produce the text \textsc{1sg.acc}, formatted in the small caps traditionally used for glossing.

You can make new commands to automate all kinds of glosses:

\begin{itemize}

	\item plural: \texttt{\textbackslash newcommand\{\textbackslash pl\}[0]\{\textbackslash textsc\{pl\}\}}
    \item singular: \texttt{\textbackslash newcommand\{\textbackslash sg\}[0]\{\textbackslash textsc\{sg\}\}}
	\item dative: \texttt{\textbackslash newcommand\{\textbackslash dat\}[0]\{\textbackslash textsc\{dat\}\}}
	\item nominalizer: \texttt{\textbackslash newcommand\{\textbackslash nmlz\}[0]\{\textbackslash textsc\{nmlz\}\}}
    \item and so on and so forth.
    
\end{itemize}

Check the \LaTeX\ code here for one more super-useful custom command!\\

\newcommand{\hidethis}[1]{}
\hidethis{This is one more extremely useful custom command.  It takes a block of text delineated with {} as its argument, and then does nothing.  In effect it hides that entire section of text from the compiler, meaning you can easily hide entire sections of text (or chapters in a dissertation and then unhide them with 1 line of code and a lonesome squiggly bracket, rather than commenting our each line.  As you can see, none of this text shows up in the PDF}


With \LaTeX, it becomes easy to implement industry standards like the Leipzig Glossing Rules (\url{http://www.eva.mpg.de/lingua/resources/glossing-rules.php}).


%% ----------------------------------------------------------------------------%

\section{Labeling and referencing} \label{labeling}

One of the best things about \LaTeX\ is the ability to label and then refer back to examples, sections, subsections, and so on. The trick to making this happen are the following commands:

\begin{itemize}
	\item \texttt{\textbackslash label\{\}}
	\item \texttt{\textbackslash ref\{\}}	
	\item \texttt{\textbackslash eqref\{\}}
\end{itemize}	
%	
Here's how it works. When you write an example, you can add in a \texttt{\textbackslash label\{\}} command, with the label of your choosing inside the brackets. Take a look at the code for the following examples (which also introduce the useful \texttt{\textbackslash hfill} command):


\ex. Names of birds in Hungarian: \label{birds}
	\a. mad\'ar \hfill `bird' \label{bird}
	\b. papag\'aj \hfill `parrot' \label{parrot}
	\b. s\'olyom \hfill `hawk' \label{hawk}
	\b. varj\'u \hfill `crow' \label{crow}
	\b. f\'ac\'an \hfill `pheasant' \label{pheasant}

If you take a look at the code, you'll notice that I have placed a \texttt{\textbackslash label\{\}} command for each example. I can use \texttt{\textbackslash eqref\{\}} or \texttt{\textbackslash ref\{\}} to refer back to these labels.\footnote{The difference is that \texttt{\textbackslash eqref\{\}} adds a parentheses around the example number. However, \texttt{linguex} example numbers seem to already have parentheses by default, so \texttt{\textbackslash ref\{\}} works fine for them.} \LaTeX\ takes care of the numbering automatically. These labels can nest, as in \ref{birds} versus \ref{bird}, \ref{parrot}, \ref{hawk}, \ref{crow}, and \ref{pheasant}.


I can also label and refer to sections of the document. Take another look at the code: there's a \texttt{\textbackslash label\{labeling\}} command right at the beginning of this section. I can refer back to the number of this section painlessly with \texttt{\textbackslash eqref\{\}} or \texttt{\textbackslash ref\{\}}: \eqref{labeling}. Ta-da!


%% ----------------------------------------------------------------------------%

\section{Syntax trees} \label{syntax}

The best and easiest package for making beautiful and (hopefully) convincing syntax trees is with the packages \texttt{tikz-qtree} and \texttt{tikz}. (You will need \textit{both} packages for tree-drawing!)

If you're going to draw a tree that doesn't have any movement arrows, the easiest means is to use the \texttt{\textbackslash Tree} command within the \texttt{tikzpicture} environment. Here's an example:\\

\begin{tikzpicture}
\Tree [.S [.NP \edge[roof]; {Linguistics} ] [.VP [.V is ] 
                [.NP \edge[roof]; {the coolest subject} ] ] ]
\end{tikzpicture}


Make sure you put a space before every closing square bracket in your code when you're working with the \texttt{\textbackslash Tree} command. If you don't do so, the tree won't work!

Slightly more complicated (but considerably more powerful) is the \texttt{\textbackslash node} command. Take a look at the following code to see how the magic happens.\\

\begin{tikzpicture} 
	[ sibling distance = 9 em, %specifies how far about nodes on the tree should be, in terms of em-spaces;
	level distance = 4 em %ditto, but for vertical distances, i.e. between levels on the tree
	]

	\node at (0,0) {CP}
	child { node {NP} 
	child { node (specCP) {Linguistics} } }
	child { node {TP}
	child { node {T}
	child { node (T) {\textsc{be} + \textsc{pres} } } }
	child { node {VP}
	child { node {NP}
	child { node (specVP) {$\langle$Linguistics$\rangle$} } }
	child { node {V$'$}
	child { node {V}
	child { node (be) {$\langle$\textsc{be}$\rangle$ } } }
	child { node {DP}
	child { node {D}
	child { node {the} } }
	child { node {NP}
	child { node {A}
	child { node {coolest} } } 
	child { node {N}
	child { node {subject} } } } } } } };

	\draw (be) [->] to[out=260,in=280] (T);
	\draw (specVP) [->] to[out=260,in=280] (specCP);

\end{tikzpicture}

With the \texttt{\textbackslash node} command, you can draw trees by specifying their nodes and the children of those nodes and so on and so forth. %For more details, see \citep[10]{ladefoged2003}.

%% ----------------------------------------------------------------------------%

\section{Logic Trees} \label{logic}

A common and straightforward way to make logical proof trees is with the package \texttt{bussproofs}.



\begin{prooftree}
\AxiomC{$\Gamma\vdash A$} \AxiomC{$A\to B\vdash A\to B$} %This is the first line, where we introduce axioms and the like.  Remember, the '$' is simply used to make the in-line math environment, be cause commands like \Gamma and \vdash only work in math mode
\RightLabel{$\to$E} %Right labels are your rule labels that go in between lines on the right
\BinaryInfC{$\Gamma,A\to B\vdash B$}
\RightLabel{$\to$I}
\UnaryInfC{$\Gamma\vdash(A
\to B)\to B$}
\end{prooftree}


%% ----------------------------------------------------------------------------%

\section{Other assorted resources}

\begin{itemize}
    \item Anke Himmelreich's \LaTeX\ for Linguists (very extensive!): \url{https://www.ankehimmelreich.de/downloads/skript_latex.pdf}
    \item Explanation about the difference between \LaTeX\, MiKTeX, TeXWorks, etc.: \url{https://www.tug.org/levels.html}
    \item Overleaf, like Google Docs for \LaTeX: \url{https://www.overleaf.com/}
    \item LyX, a graphical \LaTeX\ editor: \url{https://www.lyx.org/}
    \item Full list of \LaTeX\ diacritics: \url{https://en.wikibooks.org/wiki/LaTeX/Special_Characters#Escaped_codes}
    \item IPA chart for textipa: \url{https://jon.dehdari.org/tutorials/tipachart_mod.pdf}
    \item Microsoft Excel--style \LaTeX\ table generator: \url{https://www.tablesgenerator.com/}
    \item Online TikZ figure editor: \url{https://tikzmaker.com/}
    \item Some general \LaTeX\ resources: \url{https://web02.gonzaga.edu/faculty/kearney/latex.html}
    \item Bonus: how to use \LaTeX\ to take your lecture notes: \url{https://castel.dev/post/lecture-notes-1/}
\end{itemize}

%% ----------------------------------------------------------------------------%

\section{The End!}

We hope that you've found this document helpful and easily understandable.  Feel free to use it as a template for your own documents.  An easy way to get started is to copy over the .tex file to a new location and rename it.  Then open it as usual, and comment out the actual content (and delete the stuff you absolutely don't need).  Use the old parts as patterns and examples to build your own fancy shmancy papers, homework assignments, squibs, QPs, and maybe even theses/dissertations!\hidethis{(we can dream)} We sincerely wish you the best of luck and happy \TeX ing!

%\bibliography{tutorial}
%\bibliographystyle{apa}

\end{document}

When the compiler read's the code and compiles the final PDF document and support documents, it will stop when it reaches the end document command above.  This means that it will not read anything that comes after, so use this space for optional notes or things you don't want to delete but don't want to just comment out, perhaps because it would leave your text too garbled to be easily understood.

You basically have infinite scrap paper space beneath the end document command to store all that stuff!

As an example, Below I have some of the old tutorial content on the package gb4e, which functions similarly to Linguex, and is favored in some departments, but tends to cause more bugs when used in conjunction with other packages, so we recommend you use Linguex instead.  On the off chance that you need or want to use gb4e instead, all the old tutorial material is below here.  You can also contact Daniel Puthawala for an older version of this tutorial that used gb4e.

%% ----------------------------------------------------------------------------%


%\usepackage{gb4e} % This package functions like linguex above, so you have additional options, but it has a tendency to play badly with other packages and BibTeX, so we recommend using Linguex

%Package: \texttt{gb4e}. Three tasks here. First, check out the code to see what makes the examples (\ref{apple}), (\ref{orange}), and (\ref{banana}) different.
%
%\begin{exe}
%
%
%\ex Marie aime la danse.\\
%Marie like.\textsc{3sg} the.\textsc{fem} dance.\textsc{fem}\\
%`Marie likes dancing.' \label{apple}
%
%
%\ex \gll Marie aime la danse.\\
%Marie like.\textsc{3sg} the.\textsc{fem} dance.\textsc{fem}\\
%\glt `Marie likes dancing.' \label{orange}
%
%
%\ex[*]{ \gll Marie aime \textbf{le} danse.\\
%Marie like.\textsc{3sg} the.\textsc{mas} dance.\textsc{fem}\\
%\glt Intended: `Marie likes dancing.'} \label{banana}
%
%\end{exe}
%
%Finally, the following example shows sub-items within one numbered item.
%
%\begin{exe}
%\ex Word order difference between English and French
%
%\begin{xlist}
%\ex[]{ 
%\gll Marie va toujours \`{a} l'\'{e}cole.\\
%Marie go always to {the school}\\
%\glt `Marie always goes to school'}
%
%\ex[*]{ 
%\gll Marie toujours va \`{a} l'\'{e}cole.\\
%Marie always go to {the school}\\
%\glt Intended: `Marie always goes to school'}
%\end{xlist}
%\end{exe}
%
%Here's are some more intricate examples (drawn from Hungarian), showing how to gloss morphologically complex words.
%
%\begin{exe}
%
%\ex Bagoly mondja ver\'ebnek, hogy nagyfej\H u.
%\gll bagoly-$\emptyset$ mond-ja ver\'eb-nek, hogy nagy-fej-\H u\\
%owl-\textsc{nom} say-3\textsc{sg}.\textsc{def} sparrow-\textsc{dat} \textsc{comp} big-head-\textsc{adj}\\
%\glt `The owl_{i} tells the sparrow_{j} that it_{j} has a big head.'\\(An idiom, roughly equivalent to `the pot calling the kettle black.')
%
%\ex megszents\'egtelen\'ithetetlens\'eg
%\gll meg-szent-s\'eg-telen-\'it-het-etlen-s\'eg\\
%\textsc{perf}-holy-\textsc{nmlz}-\textsc{priv}-\textsc{trans}-\textsc{modal}-\textsc{priv}-\textsc{nmlz}\\
%\glt the property of being unable to be religiously defiled (`undefiliability' ?)
%
%\end{exe}
%
%For clitics, the standard is to use equal signs rather than hyphens or dashes (reserved for `true' affixes):
%
%\begin{exe}
%
%\ex \begin{xlist}
%
%\ex my brother's house
%\gll my brother ='s house\\
%1\textsc{sg.poss} brother =\textsc{poss} house\\
%\glt `my brother's house'
%
%\ex the girl who lives next door's brand new car
%\gll the girl who live-s next door ='s brand new car\\
%\textsc{art} girl who live-\textsc{sg} next door =\textsc{poss} brand new car\\
%\glt (need I, really?)
%
%\end{xlist}
%
%\end{exe}
%



%\begin{exe}
%\ex Names of birds in Hungarian: \label{birds}
%
%	\begin{xlist}
%
%	\ex mad\'ar \hfill `bird' \label{bird}
%	
%	\ex papag\'aj \hfill `parrot' \label{parrot}
%	
%	\ex s\'olyom \hfill `hawk' \label{hawk}
%
%	\ex varj\'u \hfill `crow' \label{crow}
%	
%	\ex f\'ac\'an \hfill `pheasant' \label{pheasant}
%
%	\end{xlist}
%
%\end{exe}
