Classes - Beard

You are here: start » latex_hints » latex_tips_sheet_code


|

Meta

Source code to generate LaTeXTips.pdf

PDF link: LaTeXTips.pdf

\RequirePackage[l2tabu, orthodox]{nag}

\documentclass{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amstext}

\usepackage[margin=.5in]{geometry}

% Use the T1 font encoding (which has more symbols) instead of the default OT1
\usepackage[T1]{fontenc}

\usepackage{multicol}

\usepackage[pdftex]{hyperref}
\hypersetup{
	pdfauthor={Brandon Carroll},
	pdftitle={LaTeX Tips},
	pdfstartview=FitH,
	colorlinks,
	linkcolor=black,
	urlcolor=blue
	}



% Disable page numbering
\thispagestyle{empty}

% Disable right justification
\raggedright

% Disable column length balancing
%\raggedcolumns

% Disable indentation of paragraphs
\setlength{\parindent}{0pt}

% Set the weight of the vertical line between columns and the amount of space between columns for the multicols environment
\setlength{\columnseprule}{1pt}
\setlength{\columnsep}{9pt}

% Set up a length variable for hanging indentation (1st line of paragraph not indented, subsequent lines are)
\newlength{\hangingindent}
\setlength{\hangingindent}{12pt}

% Command to insert a horizontal line with a little extra space
\newcommand{\sectionLine}{\vspace{2pt} \hrule height 1pt \vspace{2pt}}

% Define a shorter command to insert a backslash for convenience
\newcommand{\bs}{\textbackslash}

% Define an environment to keep a block of text together (no column or page breaks allowed in it).
% It takes the title of the block of text as a parameter, sets up a hanging indent, and inserts a line at the end of the block of text.
\newenvironment{noteblock}[1]
	{
		\begin{minipage}{\columnwidth}
			\raggedright
			\setlength{\parindent}{-\hangingindent}
			\setlength{\leftskip}{\hangingindent}
			\fontsize{9}{11}\selectfont
			\textbf{\normalsize #1}
	}
	{
			\sectionLine
		\end{minipage}
	}

% Define an environment that indents its text.
% (The list environment is commonly used for defining more specific environments.)
\newenvironment{indentsection}{%
		\begin{list}{}{%
			\setlength{\leftmargin}{\hangingindent}%
			\setlength{\topsep}{0pt}%
			\setlength{\partopsep}{0in}%
			\setlength{\itemsep}{0in}%
			\setlength{\parsep}{0in}}%
		\item[]%
	}{%
		\end{list}%
	}
	
% Commands to format indefinite and definite integrals
\newcommand{\indefint}[2]{\ensuremath{\int \! #1 \, \mathrm{d} #2}}
\newcommand{\defint}[4]{\ensuremath{\int_{#1}^{#2} \! #3 \, \mathrm{d} #4}}

% Define a limit-in-the-mean operator
\DeclareMathOperator*{\limInMean}{l.\! i.\! m.}



\begin{document}

	\begin{center}
		\textbf{\LARGE \LaTeX{} Tips}
	\end{center}
	
	\begin{multicols}{2}
		
		\begin{noteblock}{Helpful websites}
			
			Beginner tutorials: \url{http://www.andy-roberts.net/writing/latex}
			
			Tutorials and general reference: \url{http://en.wikibooks.org/wiki/LaTeX}
			
			List of commands: \url{http://www.personal.ceu.hu/tex/words.htm}
			
			List of symbols: \url{http://ctan.mackichan.com/info/symbols/comprehensive/symbols-letter.pdf}
			
			Hand-drawn symbol recognition: \url{http://detexify.kirelabs.org/classify.html}
			
			Q \& A Forum: \url{http://tex.stackexchange.com/}
			
			LaTeX source code for this document: \url{svn+ssh://magiccvs.et.byu.edu/home/svnroot/MAGICC/trunk/people/Brandon_Carroll/LatexTips}
			
		\end{noteblock}
		
		
		\begin{noteblock}{Common packages}
			
			Import a package with \texttt{\bs usepackage\{packageName\}}
			
			amsmath -- Math typesetting and environments
			
			amssymb -- Lots of symbol defintions.
			
			amslatex -- Provides the multline environment.
			
			graphicx -- Used to include graphics, images, etc.
			
			hyperref -- Creates bookmarks and clickable links in the pdf.
		
		\end{noteblock}
		
		
		%\begin{noteblock}{Math mode}
			%
			%Inline math mode: \texttt{\$\ldots\$} or \texttt{\bs (\ldots\bs )}
			%
			%Display math mode: \texttt{\$\$\ldots\$\$}, \texttt{\bs{[}\ldots\bs{]}}
			%
			%Useful math environments: equation (for single equation), align (for multiple equations), multline (for equations that are too long to fit on one line)
			%
			%Subscripts and superscripts: 
			%\texttt{\$a\_b\$} gives $a_b$, \texttt{\$a\_\{bc\}\$} gives $a_{bc}$,
			%\texttt{\$a\char`^b\$} gives $a^b$, \texttt{\$a\char`^\{bc\}\$} gives $a^{bc}$
			%
			%Use built in commands for math functions: \texttt{\$\bs sin\bs theta\$} gives $\sin\theta$.  Don't use \texttt{\$sin\bs theta\$}, which gives $sin\theta$.
			%
			%Fractions: \texttt{\$\bs frac\{a+b\}\{c\}\$} gives $\frac{a+b}{c}$.
		%
		%\end{noteblock}
		
		
		\begin{noteblock}{The align environment}
		
			The \texttt{\&} symbol toggles between signaling alignment and signaling column breaks.
			
			A double backslash (\texttt{\bs\bs}) starts a new line.
			
			Put \texttt{\bs label} commands before the \texttt{\bs\bs}.
			
			The \texttt{align$^*$} environment omits the equation numbers.
			
			For example, \\*
			\begin{indentsection}
				\texttt{\bs begin\{align\}} \\*
				\begin{indentsection}
					\texttt{x\_1\&=a+b \ \ \ \ \& \ \ \ \ x\_2\&=c+d \bs label\{eq1\} \bs\bs} \\*
					\texttt{x\_3\&=a+b+c+d \& x\_3-x\_2\&=x\_1 \bs label\{eq2\}} \\*
				\end{indentsection}
				\texttt{\bs end\{align\}}			
			\end{indentsection}
			\vspace{-\baselineskip}
			\begin{align}
				x_1&=a+b     & x_2&=c+d \label{eq1} \\ 
				x_3&=a+b+c+d & x_3-x_2&=x_1 \label{eq2}
			\end{align}
			\vspace{-1.7\baselineskip}
		
		\end{noteblock}
		
		
		\begin{noteblock}{Figures}
			
			Include the graphicx package: \texttt{\bs usepackage{[pdftex]}\{graphicx\}}.
			
			You can specify the folders that the figures are in: \texttt{\bs graphicspath\{\{folder1/\}\{folder2/figs/\}\}}.
			
			Tell it what file types to look for with \texttt{\bs DeclareGraphicsExtensions\{.pdf,.jpg,.png\}}.
		
			Example: \\*
			\begin{indentsection}
				\texttt{\bs begin\{figure\}} \\*
				\begin{indentsection}
					\texttt{\bs centering} \\*
					\texttt{\bs includegraphics{[width=3in]}\{filename.pdf\}} \\*
					\texttt{\bs caption\{Caption text here\}} \\*
					\texttt{\bs label\{fig1\}} \\*
				\end{indentsection}
				\texttt{\bs end\{figure\}}
			\end{indentsection}
			
			The \texttt{\bs label} command must come after the \texttt{\bs caption} command for references to work correctly.
			
			If you put the \texttt{\bs caption} command before the \texttt{\bs includegraphics} command, then the caption will appear above the figure.
		
		\end{noteblock}
		
		
		\begin{noteblock}{Matrices}
			
			Use \texttt{\&} to break columns and \texttt{\bs\bs} to start a new line.
			
			Environments: matrix (no brackets), bmatrix (square brackets), Bmatrix (curly braces), pmatrix (parentheses), vmatrix (vertical bars), and Vmatrix (double vertical bars).
			
			Example:
			
			\begin{minipage}[c]{.7\linewidth}
				\begin{indentsection}
					\texttt{\bs( \bs begin\{bmatrix\}}
					\begin{indentsection}
						\texttt{a \& b \& c \bs\bs} \\
						\texttt{d \& e \& f}
					\end{indentsection}
					\texttt{\bs end\{bmatrix\} \bs)}
				\end{indentsection}
			\end{minipage}
			\begin{minipage}[c]{.25\linewidth}
				\(
					\displaystyle
					\begin{bmatrix}
						a & b & c \\
						d & e & f
					\end{bmatrix}
				\)
			\end{minipage}
			
		\end{noteblock}
		
		
		\begin{noteblock}{Spacing}
			
			The \texttt{\bs !} command produces a small negative horizontal space (so \texttt{a\bs !a} produces a\!a).
			
			The following commands produce increasing amounts of horizontal space: \:	\texttt{\bs,} \: \texttt{\bs:} \: \texttt{\bs;} \: \texttt{\bs quad} \: \texttt{\bs qquad}.
			
			The \texttt{\bs hspace} command produces a specified amount of horizontal space (so \texttt{|\bs hspace\{.5cm\}|} produces |\hspace{.5cm}|).
			
			The \texttt{\bs vspace} command produces a specified amount of vertical space (the amount can be negative).
			
			Units of length that can be used: \texttt{pt}, \texttt{mm}, \texttt{cm}, \texttt{in}, \texttt{ex}, \texttt{em}.
		
		\end{noteblock}
		
		
		\begin{noteblock}{Custom commands}
			
			Define new commands with \texttt{\bs newcommand\{\bs commandName\}\{commandDefinition\}}.
			
			This will cause any instances of \texttt{\bs commandName} to be replaced with \texttt{commandDefinition}.
			
			To define commands that accept parameters, specify the number of parameters and use \texttt{\#N} in the command definition to substitute in the parameter: 
			\texttt{\bs newcommand\{\bs commandName\}{[numParams]}\{definition\}}.
			
			Example (a command to format an indefinite integral): 
			\texttt{\bs newcommand\{\bs indefint\}{[2]}\{\bs ensuremath\{\bs int\bs !\#1 \bs, \bs mathrm\{d\} \#2\}\}}
			
			causes \texttt{\bs indefint\{x(t)\}\{t\}} to be formatted as \indefint{x(t)}{t}.
		
		\end{noteblock}
		
		
		\begin{noteblock}{Custom math operators}
			
			You can use the \texttt{\bs DeclareMathOperator} command to define your own math operators (like the built in \texttt{\bs sin} and \texttt{\bs lim} operators).
			
			The \texttt{\bs DeclareMathOperator$^*$} version of the command will put superscripts and subscripts above and below the operator (like \texttt{\bs lim} does).
			
			Example: \texttt{\bs DeclareMathOperator$^*$\{\bs limInMean\}\{l.\bs !i.\bs !m.\}} causes 
			\texttt{\bs limInMean\_\{x \bs rightarrow 0\}f(x)} to produce 
			\( \displaystyle\limInMean_{x \rightarrow 0}f(x) \).
			
		\end{noteblock}
		
		
		\begin{noteblock}{Miscellaneous tips}
			
			You usually need to compile several times for all the cross references to get resolved (no warnings).
		
			The \texttt{\bs input\{fileName\}} command will insert all the text from fileName.tex into the document when compiled.
			
			The \texttt{\bs today} command will be replaced with the current date when the document is compiled.
			
			The \texttt{\bs ensuremath} command can be used to define commands that work either in or out of math mode.  
			E.g. \texttt{\bs newcommand\{\bs azimuth\}\{\bs ensuremath\{\bs alpha\_\{az\}\}\}}.
			
			\texttt{\$\bs mathcal\{ABCDEF\}\$} gives $\mathcal{ABCDEF}$.
			
			\texttt{\$\bs mathbb\{ABCDEF\}\$} gives $\mathbb{ABCDEF}$.
			
			You can easily set margins with the geometry package: 
			\texttt{\bs usepackage{[}top=1in,left=.5in,right=.5in, bottom=1in{]}\{geometry\}}
			
			LaTeX ignores spaces after command names with no parameters.  You can force spaces with either \texttt{\bs\textvisiblespace} or by placing \texttt{\{\}} after the command.
			
			%Descriptive subscripts to variables should be romanized with the \texttt{\bs mathrm\{\}} command: \( (p_\mathrm{n}, p_\mathrm{e}, p_\mathrm{d}) \), not \( (p_n, p_e, p_d) \).
			
			Don't just type words while in math mode---it will space the letters like a bunch of single letter variables multiplied together.  
			Put words in a \texttt{\bs mathit\{\}} or \texttt{\bs mathrm\{\}} command depending on if they should be italicized (variable names) or romanized.
			I.e., $\mathit{variable}_\mathrm{min}$ should not look like $variable_{min}$.
			
			If missing packages don't download automatically, you can use the MiKTeX Package Manager to download them manually.
			
			In TeXnicCenter, F9, F10, and F11 cycle through errors, warnings, and bad boxes respectively.
			
			In TeXnicCenter, ctrl-q comments out the selected block of code and ctrl-w uncomments.
		
		\end{noteblock}
		
	\end{multicols}
	
\end{document}