%%%% If using TeXworks, compile with BibTeX twice, then with pdfLaTeX 3 times (need extra times to compile the bibliography and table of contents properly). You may not have to go through these steps if you are using another editor. Questions email griffin@bu.edu \documentclass[letterpaper,12pt]{article} \usepackage[utf8x]{inputenc} \usepackage{hyperref} \usepackage{fullpage} \usepackage{fancyhdr} \usepackage{enumerate} \usepackage{graphicx} \usepackage{amsmath} \usepackage{float} \usepackage{fancyvrb} \usepackage{lastpage} \usepackage{color} \usepackage{multirow} \usepackage{todonotes} \usepackage{natbib} \title{Introduction to \LaTeX} \author{Paula Griffin} %\date{} \begin{document} \maketitle \hrulefill \tableofcontents \hrulefill \clearpage %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Basics} This is what a paragraph looks like by default in article style. The first paragraph is not indented, but later paragraphs are not. This is what the second paragraph looks like. You can change these settings by using different page styles-- in particular, try manipulating the settings for \texttt{\textbackslash pagestyle\{fancy\}} %%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Sections} By default, sections and subsections are numbered. If you do not want a section/subsection numbered, you need to use * before the curly braces-- write it as \texttt{\textbackslash section$^*$\{Section Name\}} instead of \texttt{\textbackslash section\{Section Name\}} %%%%%%%%%%%%%%%%%%%%%%%%%% \subsection*{An unnumbered subsection} Note that this will section will not appear in the table of contents by default. %%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Text manipulation} Putting in a single \\ line break \textbf{Bold face text}, \textit{italics}, \texttt{typewriter text} 1 centimeter of horizontal space between before \hspace{1cm} and after. -1 centimeter of horizontal space between before \hspace{-1cm} and after. %%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Special characters} Special characters you might want to know how to print. \# \$ \% \textasciicircum{} \& \_ \{ \} \~{} \textbackslash{} Some symbols can only be included in a math environment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Adding other elements} %%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Equations} Example equations: If you want to say $c=299,792,458$ m/s in the middle of a sentence, then you use single dollar signs. But if you want it to be centered on a separate line, you want to use:$$c=299,792,458 \mbox{ m/s}$$ Sometimes you want to number your equations: \begin{equation} \lambda= \sqrt{\frac{r_m}{(r_i+r_0)}} \end{equation} And sometimes you don't: \begin{equation*} N_A=6.02\times10^{23} \end{equation*} If you want all of the steps of your derivation to line up: \begin{align} \hat{\beta} &=(X'X)^{-1}X'Y \\ &= HY \end{align} Matrices are annoying to type: \[ \mathbf{M} = \left( \begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} \right)\] Piecewise definitions: \begin{displaymath} x = \left\{ \begin{array}{ll} 1 & \mbox{male} \\ 0 & \mbox{female} \end{array} \right. \end{displaymath} %%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Figures} General syntax for including an image: \begin{figure}[H] % H means HERE, where ht would mean this page, at the top \caption{Cat, unimpressed.} \centering \includegraphics[width=.5\linewidth]{images/cat.jpg} \end{figure} %%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Tables} Tables are just as much as a pain in \TeX as they are in HTML. Basic structure \begin{table}[H] \centering \caption{An unmatched study} \begin{tabular}{|c|cc|} \hline & Cases & Controls \\ \hline Exposed & 40 & 52 \\ Unexposed & 2 & 89 \\ \hline \end{tabular} \end{table} For more complicated structures, it may be helpful to use a program called LYX, which offers a GUI for making tables. (You can actually make a whole \TeX document in LYX, but it kind of defeats the point!) \begin{figure}[H] \centering \caption{Screenshot of LYX program} \includegraphics[width=.6\linewidth]{images/lyx.png} \end{figure} \begin{table}[H] \centering \caption{A matched study} \begin{tabular}{|c|c|c|c|} \hline \multicolumn{1}{|c}{} & & \multicolumn{2}{c|}{Controls}\tabularnewline \cline{3-4} \multicolumn{1}{|c}{} & & Exposed & Unexposed\tabularnewline \hline \multirow{2}{*}{Cases} & Exposed & 45 & 12\tabularnewline \cline{2-4} & Unexposed & 31 & 152\tabularnewline \hline \end{tabular} \end{table} %%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Incorporating code} For small parts, use a verbatim environment: \begin{verbatim} verbatim text $% \end{verbatim} When Use the package \texttt{fancyvrb} and make Verbatim environments. Different settings are available for which lines get numbered, if you include a border, and how big you want the text to be. \fvset{numbers=left,numbersep=3pt, stepnumber=5, fontsize=\small, frame=single} \begin{Verbatim} fancy verbatim text skip a few lines line 5 numbered \end{Verbatim} You can also port text from other files as verbatim \VerbatimInput{simpleExample.R} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Bonuses!} %%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{URLs} URLs are easy you just need to use a simple command \url{http://blogs.bu.edu/bubsa/} %%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Integration with R} The package \texttt{xtable} ports R output to text. You know that code I had in the last section? It makes this: \begin{table}[H] \include{womenRegression} \end{table} Isn't that so much better than copy/paste? %%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Detexify} Nifty little webapp to help when you forget what symbols are called. Available at \url{http://detexify.kirelabs.org/} \begin{figure}[H] \centering \caption{Used primarily to settle bets about the Greek alphabet} \includegraphics[width=.5\linewidth]{images/detexify2.png} \end{figure} %%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{todonotes} My favorite bonus package is todonotes \todo{todo: tell them why}. A very helpful package for those of us who have turned in homeworks with the sentence FINISH THIS QUESTION LATER still in the text. \missingfigure{You can also remind yourself to include a figure later on} %%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Bibliographies} \TeX can also handle your bibliography for you. Bibliography source code looks something like this: \begin{Verbatim} @ARTICLE{de2005efficiency, author = {De Bakker, P.I.W. and Yelensky, R. and Pe'er, I. and Gabriel, S.B. and Daly, M.J. and Altshuler, D.}, title = {Efficiency and power in genetic association studies}, journal = {Nature genetics}, year = {2005}, volume = {37}, pages = {1217--1223}, number = {11}, publisher = {Nature Publishing Group} } \end{Verbatim} You can get this using Google Scholar (just go to Scholar Preferences $\rightarrow$ Bibliography Manager $\rightarrow$ Show links to import citations into BibTeX). Copy/paste the source into a bibliography manager like JabRef (\url{http://jabref.sourceforge.net/}) or make a separate .bib file on your own. \begin{figure}[H] \centering \caption{Jabref} \includegraphics[width=.5\linewidth]{images/jabref.png} \end{figure} This is how you cite the \LaTeX wikibook \cite{wikibooks2010latex}. There are also other citation styles you can find there. Use package \texttt{natbib}, and include code to pull the bibliography into your document, following a template like included in the source below here. With TexWorks, you will need to compile the bibliography (switch to BibTeX mode, compile) and then go back to compiling to PDF. \bibliographystyle{plain} % or any other valid style \bibliography{texdemo_bibliography.bib} \nocite{*} % if you want even non-cited sources included \end{document}