CoCalc is a real-time collaborative commercial alternative to JupyterHub and Overleaf that provides Jupyter Notebooks, LaTeX documents, and SageMath.
CoCalc is a real-time collaborative commercial alternative to JupyterHub and Overleaf that provides Jupyter Notebooks, LaTeX documents, and SageMath.
| Download
Aaron Tresham Calculus Materials - Feb 2018 snapshot
Project: ᛣ CoCalc Community
Path: Aaron Tresham Calculus Material / Calculus 2 / 03 - Writing in LaTeX Assignment / Notes / Writing in LaTeX Notes.tex
Views: 8489\documentclass[12pt]{article}1\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}2\title{Writing in \LaTeX}3\author{Aaron Tresham}4\date{June 8, 2015}56\usepackage{hyperref, parskip, amsmath, amssymb, latexsym, graphicx, enumerate, cancel, sagetex}7\usepackage[normalem]{ulem}89\begin{document}10\maketitle11\newcommand{\ds}{\displaystyle}1213In Math 205, we talked about writing in Sage using \%md. If we wanted to include mathematical symbols, we could use \LaTeX{} commands enclosed in dollar signs (\$). However, a Sage worksheet is not ideal for producing nice, presentable output. If we want better-looking output, then instead of using \LaTeX{} inside a Sage worksheet, we can use Sage inside a \LaTeX{} document. We do not need another program to do this, since CoCalc already includes the ability to create \LaTeX{} documents. In fact, you're looking at one right now.1415\section{Basics of \LaTeX}1617When you open a \LaTeX{} document in CoCalc, the window will split into two panes. On the left you will see the actual \LaTeX{} document, which includes many obscure commands and strange-looking stuff. This is the input. On the right you will see a preview of what \LaTeX{} will produce. This is the output. You can see that \LaTeX{} produces a nice-looking document.1819\subsection{The Output Pane}2021Above the right pane you will see a button labeled ``Preview.'' To the right you'll see another button, ``Issues.'' If you make a mistake in the input, then the ``Issues'' button will turn yellow or red (depending on how bad the mistake is). If you click on ``Issues'' you can get an error report detailing all the problems by line number. The line numbers are on the left side of the input pane (the pane on the left).2223Next to ``Issues'' you'll see ``PDF.'' If you click this button, the output will be converted to a PDF document and opened. In this view you can save or print your document.2425After ``PDF'' there is the ``Build'' tab. Most of the time you will not need this. Later we'll see when this tab is useful.2627Below these four tabs you'll see magnifying glasses with a minus and plus inside. Use these to zoom in and out on the preview.2829Above the input pane on the left, you'll see buttons labeled ``Forward'' and ``Inverse.'' If you put your cursor somewhere in the input pane and press ``Forward,'' the output pane will move to the corresponding point in the output. If you press ``Inverse,'' then the input pane will move to the point that matches the output.3031Every time the input gets saved (either automatically or by you pressing the green ``Save'' button), the preview will be updated. So to write a \LaTeX{} document, you type in the left pane, press ``Save,'' and the output appears on the right pane.3233\subsection{The Input Pane}3435Now let's look at the left side. At the top is the ``preamble'' of the document. This just sets things up. Most of the time you won't need to do anything here. Here's what's in the preamble (by line number).3637\begin{itemize}3839\item[1] \verb|\documentclass[12pt]{article}|.4041You can ignore this line unless you want to change the font size (it can be 10pt, 11pt, or 12pt).4243\item[2] \verb|\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}|4445You can change the margins here (don't worry about everything else on this line).4647\item[3-5] \verb|\title{...}, \author{...}, \date{...}|4849You indicate the title, author, and date here. These appear at the beginning of the output. [Note: If you have multiple authors, separate their names with \verb|\and|.]5051\item[7] \verb|\usepackage{...}|5253I have included several extra packages that provide additional functionality. You do not need to worry about this line. If you want to do something specialized (for example, wrap text around an image), then you may need to include a specific package to accomplish this task. You can add package names here to include additional packages.5455\end{itemize}5657Line 9, \verb|\begin{document}|, indicates the end of the preamble and the beginning of the actual document. The first thing we have after this is \verb|\maketitle|, which inserts the title, author, and date that we specified above. If you don't want these to appear, then you can either delete \verb|\maketitle| or you can comment it out by placing \% at the beginning of this line.5859Next I have defined a new command, called \verb|\ds|. This is a shortcut for \verb|\displaystyle|, which I got tired of typing all the time. (You may recall from Math 205 that \verb|\displaystyle| is used to make math formulas easier to read.) Feel free to use \verb|\ds| in your documents. You can also define your own commands if you want to.6061\subsection{Organizing the Document}6263Your document will be easier to read if you include sections, subsections, etc. to organize the material.6465Use the command \verb|\section{...}| to insert a section heading. \LaTeX{} automatically numbers and resizes the section heading.6667The next level of organization is the subsection. Use the command \verb|\subsection{...}| to insert a subsection heading. Subsection headings are smaller than section headings. They are also numbered (notice how the section number is included in the subsection number).6869If you need even deeper levels of organization, the commands are \verb|\subsubsection{...}|, \verb|\paragraph{...}|, and \verb|\subparagraph{...}|.7071\subsection{Basic Formatting}7273\subsubsection{Emphasis}7475If you want to emphasize text, use the following commands:7677\verb|\textbf{This is bold}| produces \textbf{This is bold}.7879\verb|\textit{This is italics}| produces \textit{This is italics}.8081If you include the \texttt{ulem} package (which I have), then you can use the following commands for underlining, etc.8283\verb|\uline{This is underlined}| produces \uline{This is underlined}.8485\verb|\uuline{This is double-underlined}| produces \uuline{This is double-underlined}.8687\verb|\uwave{This is wavy-underlined}| produces \uwave{This is wavy-underlined}.8889\verb|\sout{This is struck out}| produces \sout{This is struck out}.9091\verb|\xout{This is crossed out}| produces \xout{This is crossed out}.9293\verb|\dashuline{This is underlined with dashes}| produces \dashuline{This is underlined with dashes}.9495\verb|\dotuline{This is underlined with dots}| produces \dotuline{This is underlined with dots}.9697Note: These formatting changes may not work in math mode (see below).9899\subsubsection{Text Size}100101If you want to change the text size, then you can use a declaration (not quite like a command). For example,102103104\verb|{\huge This is huge}| produces {\huge This is huge}.105106Notice that for a declaration, the first curly bracket is at the beginning (if this were a command, then the first curly bracket would go after large). [By the way, this difference between commands and declarations irritates me.]107108Here are some size options: \verb|\tiny, \small, \large, \Large, \LARGE, \huge, \Huge|.109110\subsubsection{Centering}111112If you want to center text, then you declare a new ``environment'' using \verb|\begin| and \verb|\end|113114For example, \verb|\begin{center} This is centered \end{center}| produces115\begin{center} This is centered \end{center}116117[Note: the \verb|\begin{center}| and \verb|\end{center}| do not have to be on the same line. Anything between the \verb|\begin| and \verb|\end| will be centered.]118119\subsubsection{Spacing}120121To add horizontal space, use the \verb|\hspace| command. For example \verb|abc \hspace{1in} xyz| produces122123abc \hspace{1in} xyz124125To add vertical space, use the \verb|\vspace| command. For example \begin{verbatim}126abc \vspace{.25in}127128xyz129\end{verbatim}130produces131132abc \vspace{.25in}133134xyz135136[Note the blank line after vspace.]137138I have used inches (in) in my example, but you can also use centimeters (cm) or points (pt), among other less common options.139140The command \verb|\pagebreak| will end the page at that point.141142\subsubsection{Smart Quotes}143144For some reason, the quotation mark (\verb|"|) is only used for ending quotations. For beginning a quotation, use two backticks (\`{}, also called backquote; it's on the same key as the tilde)145146Compare: \verb|"Here is a quotation."|, which produces "Here is a quotation."147148with \`{}\`{}\verb|Here is a quotation."|, which produces ``Here is a quotation."149150The same holds for single quotes, where you begin with a backtick and end with an apostrophe. Compare: 'Here is a quotation.' versus `Here is a quotation.'151152\subsection{Lists}153154There are two environments used to create lists: enumerate and itemize.155156\subsubsection{Numbered Lists}157158To create a numbered list, type \verb|\begin{enumerate}|. Then before each item on the list type \verb|\item|. At the end of the list type \verb|\end{enumerate}|. Here's an example:159160\begin{verbatim}161\begin{enumerate}162\item First thing in the list.163\item Second thing in the list.164\item Third thing in the list.165\end{enumerate}166\end{verbatim}167produces:168169\begin{enumerate}170\item First thing in the list.171\item Second thing in the list.172\item Third thing in the list.173\end{enumerate}174175\subsubsection{Bullet Points}176177If you want bullet points instead of numbers, use \verb|itemize| in place of \verb|enumerate|.178179\begin{verbatim}180\begin{itemize}181\item First thing in the list.182\item Second thing in the list.183\item Third thing in the list.184\end{itemize}185\end{verbatim}186produces:187188\begin{itemize}189\item First thing in the list.190\item Second thing in the list.191\item Third thing in the list.192\end{itemize}193194\subsubsection{Nested Lists}195196Lists can also be nested (up to four levels deep). Here's an example with enumerate.197198\begin{verbatim}199\begin{enumerate}200\item First item201\begin{enumerate}202\item First subitem203\item Second subitem204\end{enumerate}205\item Second item206\begin{enumerate}207\item First subitem208\item Second subitem209\end{enumerate}210\end{enumerate}211\end{verbatim}212produces:213214\begin{enumerate}215\item First item216\begin{enumerate}217\item First subitem218\item Second subitem219\end{enumerate}220\item Second item221\begin{enumerate}222\item First subitem223\item Second subitem224\end{enumerate}225\end{enumerate}226227\subsubsection{Changing the Item Counters}228229By default, \verb|enumerate| creates a list with numbers 1., 2., 3., etc. and sublists with letters (a), (b), (c), etc. If you want different item counters, then right after \verb|\begin{enumerate}| put square brackets and the first counter in the desired format (this requires the enumerate package, which I have included).230231For example,232233\begin{verbatim}234\begin{enumerate}[A.]235\item First item236\item Second item237\item Third item238\end{enumerate}239\end{verbatim}240produces241242\begin{enumerate}[A.]243\item First item244\item Second item245\item Third item246\end{enumerate}247248These are the allowed first counters: A, a, I, i, and 1. Any other characters are treated as text. For example, if you use \verb|\begin{enumerate}[(I)]|, your list counters will be (I), (II), (III), etc. If you use \verb|\begin{enumerate}[Ex 1.]|, your counters will be Ex 1., Ex 2., Ex 3., etc.249250If you want to control exactly the label for each item, then use \verb|itemize| and put the label in square brackets after \verb|\item|. For example,251252\begin{verbatim}253\begin{itemize}254\item[Apple] First item255\item[Orange] Second item256\item[Lemon] Third item257\end{itemize}258\end{verbatim}259produces:260261\begin{itemize}262\item[Apple] First item263\item[Orange] Second item264\item[Lemon] Third item265\end{itemize}266267The labels can be anything you like. One disadvantage is that you have to specify the label for each item separately.268269\vspace{12pt}270271\textbf{Remember, every} \verb|\begin{...}| \textbf{needs an} \verb|\end{...}|!272273\subsection{Special Symbols}274275Some symbols are used for \LaTeX{} commands. If you want these symbols to actually appear, then you need to know the right command. Many times this means simply adding a backslash in front.276277The dollar sign is used to indicate math mode. So if you want a dollar sign to show up, you type \verb|\$|. For example, \verb|\$100| produces \$100.278279The percent sign is used to indicate a comment (everything after \% will be ignored). If you want \% to show up, then type \verb|\%|.280281The underscore is used for subscripts, and \verb|\_| is used for an underscore, \_.282283The caret is used for superscripts, and \verb|\^{}| is used for a caret, \^{}. [Note the curly brackets. If you leave them off, the caret will be placed over the next character (circumflex accent).]284285Curly brackets are used all over the place, so \verb|\{| and \verb|\}| are used to get curly brackets, \{\}.286287\subsection{Verbatim Mode}288289If you want text to appear exactly as you type it (helpful for typing Sage or \LaTeX{} code), then you need to use verbatim mode.290291If you have a short segment of text, you can use \verb/\verb|text|/. Whatever you put between the vertical lines will appear exactly as typed. [Note: You do not use curly brackets for this command. I don't know why.]292293If you have a longer portion (with multiple lines), then use the verbatim environment. For example,294295\verb|\begin{verbatim}|296\begin{verbatim}297f(x)=x^2298plot(f)299derivative(f,x)300\end{verbatim}301\verb|\end{verbatim}|302303produces:304305\begin{verbatim}306f(x)=x^2307plot(f)308derivative(f,x)309\end{verbatim}310311\subsection{Including Graphics}\label{ingr}312313If you want to add graphics to your document, then use the \verb|\includegraphics| command (this requires the graphicx package, which I have already included).314315Here is an example: \verb|\includegraphics[scale=.25]{main_campus_map.pdf}| produces:316317\includegraphics[scale=.25]{main_campus_map.pdf}318319The graphics document must be in the same folder as your \LaTeX{} document. The graphics file may be .pdf, .png, or .jpg.320321Notice how you can change the size using the ``scale'' option (in square brackets). Instead of specifying a scale factor, you can also choose the width or height (or both). For example, replace \verb|scale=.25| with \verb|width=1in| to get a picture 1 inch wide (the height will be automatically adjusted to keep the aspect ratio.322323\subsection{Tables}324325If you want to include a table, you use the \verb|tabular| environment. Here is a simple example.326327\begin{verbatim}328\begin{tabular}{cc}329Name & Grade \\330John & 99 \\331Jane & 100 \\332\end{tabular}333\end{verbatim}334335produces:336337\begin{tabular}{cc}338Name & Grade \\339John & 99 \\340Jane & 100 \\341\end{tabular}342343The \verb|{cc}| after the \verb|\begin{tabular}| specifies the number of columns, as well as the alignment. Two c's means you have two columns, and both are centered. If you want two columns that are right aligned, use \verb|{rr}|, and if you want them left aligned use \verb|{ll}|.344345Here is an example with three columns, where the first is left aligned, the second is centered, and the third is right aligned:346347\begin{verbatim}348\begin{tabular}{lcr}349Name & Exam Grade & Course Grade \\350John & 89 & B \\351Jane & 100 & A \\352\end{tabular}353\end{verbatim}354355produces:356357\begin{tabular}{lcr}358Name & Exam Grade & Course Grade \\359John & 89 & B \\360Jane & 100 & A \\361\end{tabular}362363Notice that each row of the table has an ampersand (\verb|&|) between each column and a double backslash (\verb|\\|) at the end of the line.364365If you want to add horizontal lines, you place \verb|\hline| between the rows.366367\begin{verbatim}368\begin{tabular}{lcr}369Name & Exam Grade & Course Grade \\370\hline371John & 89 & B \\372Jane & 100 & A \\373\end{tabular}374\end{verbatim}375376produces:377378\begin{tabular}{lcr}379Name & Exam Grade & Course Grade \\380\hline381John & 89 & B \\382Jane & 100 & A \\383\end{tabular}384385If you want to add vertical lines, you place a vertical bar ($|$) between the l, c, or r used to specify the number of columns.386387\begin{verbatim}388\begin{tabular}{l|c|r}389Name & Exam Grade & Course Grade \\390\hline391John & 89 & B \\392Jane & 100 & A \\393\end{tabular}394\end{verbatim}395396produces:397398\begin{tabular}{l|c|r}399Name & Exam Grade & Course Grade \\400\hline401John & 89 & B \\402Jane & 100 & A \\403\end{tabular}404405Here is a final example with lines everywhere:406407\begin{verbatim}408\begin{tabular}{|l|c|r|}409\hline410Name & Exam Grade & Course Grade \\411\hline412John & 89 & B \\413\hline414Jane & 100 & A \\415\hline416\end{tabular}417\end{verbatim}418419produces:420421\begin{tabular}{|l|c|r|}422\hline423Name & Exam Grade & Course Grade \\424\hline425John & 89 & B \\426\hline427Jane & 100 & A \\428\hline429\end{tabular}430431There are many more things you can do with tables, but these are the basics.432433\section{Math in \LaTeX}434435As we learned in Math 205, if we want to type math, we enclose the appropriate commands in dollar signs.436437For example, type \verb|$f(x)=x^2+3x+2$| to get $f(x)=x^2+3x+2$.438439Using single dollar signs produces typeset math inline. If you have math that you want set off from the rest of the text, enclose it in double dollar signs (display mode). For example, typing \verb|$$f(x)=x^2+3x+2$$| produces $$f(x)=x^2+3x+2$$440441Note: If you have a long math formula on one line, you just have to put one set of dollar signs at the beginning and end of the line. You should not put dollar signs around each individual math command.442443\subsection{Fractions}444445To produce a fraction, type \verb|$\frac{numerator}{denominator}$|.446447For example, typing \verb|$\frac{3}{7}$| produces $\frac{3}{7}$.448449Typing \verb|$\frac{x^2+3x+9}{2x-4}$| produces $\frac{x^2+3x+9}{2x-4}$.450451If these fractions are too small, you can make them larger by typing \verb|\ds| at the beginning:452453Typing \verb|$\ds\frac{x^2+3x+9}{2x-4}$| produces $\ds\frac{x^2+3x+9}{2x-4}$.454455Note that \verb|\ds| is not required when you use double dollar signs.456457Typing \verb|$$\frac{x^2+3x+9}{2x-4}$$| produces $$\frac{x^2+3x+9}{2x-4}$$458459\subsection{Powers and Roots}460461If you have an exponent that is only one character, you can simply type a caret. For example, typing \verb|$x^2$| produces $x^2$.462463If your exponent has more than one character (whether it's $-1$, $25$, or $x^2-3x+2$), enclose the exponent in curly brackets.464465Compare what happens with \verb|$3^-2$| and \verb|$3^{-2}$|:466467$3^-2$ versus $3^{-2}$ [in the first case, only the negative symbol is in the exponent]468469Here's another example. To get $3^{x^2-8x+6}$ you type \verb|$3^{x^2-8x+6}$|.470471To get a square root, use \verb|\sqrt{}|.472473For example, \verb|$\sqrt{2}$| produces $\sqrt{2}$.474475And \verb|$\sqrt{3x^2-5x+1}$| produces $\sqrt{3x^2-5x+1}$.476477If you want a cube root, 4th root, etc., enclose the root number in square brackets after \verb|\sqrt|.478479For example, \verb|$\sqrt[3]{2}$| produces $\sqrt[3]{2}$.480481And \verb|$\sqrt[8]{\frac{3x+1}{9x+2}}$| produces $\sqrt[8]{\frac{3x+1}{9x+2}}$.482483Or \verb|$\ds\sqrt[8]{\frac{3x+1}{9x+2}}$| produces $\displaystyle\sqrt[8]{\frac{3x+1}{9x+2}}$.484485\subsection{Limits}486487To display a limit symbol, you type \verb|\lim|. To get text below the limit symbol, use an underscore followed by curly brackets.488489Here's an example:490491\verb|$\lim_{x\to 1}f(x)$| produces $\lim_{x\to 1}f(x)$. [Notice that \verb|\to| produces the arrow.]492493This usually looks better using \verb|\ds|:494495\verb|$\ds\lim_{x\to 1}f(x)$| produces $\ds\lim_{x\to 1}f(x)$.496497Here's another example:498499\verb|$\ds\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$| produces $\ds\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$.500501To get a limit at infinity, use \verb|\infty|:502503Typing \verb|$\ds\lim_{x\to\infty}f(x)$| produces $\ds\lim_{x\to\infty}f(x)$.504505or typing \verb|$\ds\lim_{x\to -\infty}f(x)$| produces $\ds\lim_{x\to -\infty}f(x)$.506507For left and right limits, use the caret (\verb|^|) to put a plus or minus sign in the right spot:508509For example, \verb|$\displaystyle\lim_{x\to 1^+}f(x)$| produces $\displaystyle\lim_{x\to 1^+}f(x)$.510511And \verb|$\displaystyle\lim_{x\to 1^-}f(x)$| produces $\displaystyle\lim_{x\to 1^-}f(x)$.512513\subsection{Derivatives}514515Type \verb|$f'(x)$| to get $f'(x)$.516517For the second derivative, type \verb|$f''(x)$| to get $f''(x)$.518519For the third derivative, type \verb|$f'''(x)$| to get $f'''(x)$.520521For higher order derivatives, use the caret (\verb|^|).522523For example, \verb|$f^{(5)}(x)$| produces $f^{(5)}(x)$. [Don't forget the curly brackets around the exponent.]524525If you want to use Leibniz's notation, you can type $\frac{d}{dx}$ just like a regular fraction.526527For example, \verb|$\frac{d}{dx}f(x)$| produces $\frac{d}{dx}f(x)$.528529Here is an example for the 3rd derivative: \verb|$\frac{d^3}{dx^3}f(x)$| produces $\frac{d^3}{dx^3}f(x)$.530531\subsection{Summation Notation}532533To get a summation symbol, type \verb|\sum|.534535For example, \verb|$\sum i^2$| produces $\sum i^2$.536537To add a range of values for the sum, use \verb|_| and \verb|^|.538539For example, \verb|$\sum_{i=0}^{10} i^2$| produces $\sum_{i=0}^{10} i^2$. [Note the curly brackets around i=0 and 10.]540541This will look better with \verb|\ds| or double dollar signs:542543$\ds\sum_{i=0}^{10}i^2$ from \verb|$\displaystyle\sum_{i=0}^{10}i^2$|, or544545$$\sum_{i=0}^{10}i^2$$ from \verb|$$\sum_{i=0}^{10}i^2$$|546547\subsection{Integrals}548549To get the integral symbol, type \verb|\int|.550551For example, \verb|$\int f(x)$| produces $\int f(x)$.552553If you want to add the $dx$, you should add an extra space by typing \verb|\,| before $dx$:554555\verb|$\int f(x)\,dx$| produces $\int f(x)\,dx$. [Without \verb|\,| you get $\int f(x) dx$ - no space between $f(x)$ and $dx$]556557Here's what you get if you add \verb|\ds|: $\ds\int f(x)\,dx$.558559If you want a definite integral, you add a lower limit after an underscore and an upper limit after a caret.560561For example, typing \verb|$\int_a^b f(x)\,dx$| produces $\int_a^b f(x)\,dx$.562563Or, with \verb|\ds| you get $\ds\int_a^b f(x)\,dx$.564565If a limit of integration is more than one character, then enclose it in curly brackets:566567Typing \verb$\ds\int_{-2}^{18}f(x)\,dx$| produces $\ds\int_{-2}^{18} f(x)\, dx$.568569Here's what the same integral looks like in display mode (double dollar signs): $$\int_{-2}^{18} f(x)\, dx$$570571\subsection{Miscellaneous Symbols}572573To get ``approximately equal to,'' use \verb|\approx|. For example, \verb|$x\approx 20$| produces $x\approx20$.574575To get the plus or minus symbol, use \verb|\pm|. For example, \verb|$\pm 3$| produces $\pm3$.576577To get a Greek letter, type a backslash and write out the name of the letter. For example, \verb|$\pi$| produces $\pi$ and \verb|$\alpha$| produces $\alpha$.578579For the capital Greek letters, capitalize the first letter: \verb|$\Pi$| produces $\Pi$ and \verb|$\Sigma$| produces $\Sigma$.580581[Note: If the capital Greek letter is the same as the Latin capital, then the Greek won't work. For example, \verb|$\Alpha$| will produce an error, since capital alpha is $A$.]582583To get $\ge$ and $\le$, type \verb|$\ge$| or \verb|$\le$|. To get \verb|<| or \verb|>|, simply use the keyboard.584585For multiplication, you can use either \verb|\times| or \verb|\cdot|. For example, \verb|$x\times y$| prodcues $x\times y$ and \verb|$x\cdot y$| produces $x\cdot y$.586587For composition of functions, use \verb|\circ|. For example, \verb|$f\circ g$| produces $f\circ g$.588589For an ellipsis (three dots), use either \verb|\dots| or \verb|\cdots|. The former has three dots along the base line, while the latter has three dots centered vertically. Here is an example of each:590591\verb|$1,\ 2,\ 3,\ \dots$| produces $1,\ 2,\ 3,\ \dots$592593\verb|$1+2+3+\cdots$| produces $1+2+3+\cdots$594595The \verb|\cancel| command can be used to cross things out (this requires the cancel package). For example:596597\begin{verbatim}598$$\frac{(x+1)\cancel{(x+2)}}{(x-3)\cancel{(x+2)}}=\frac{x+1}{x-3}$$599\end{verbatim}600601produces602603$$\frac{(x+1)\cancel{(x+2)}}{(x-3)\cancel{(x+2)}}=\frac{x+1}{x-3}$$604605There is also a \verb|\cancelto| command to do things like this:606607$$\lim_{x\to \infty}\frac{2+\cancelto{0}{\frac{3}{x}}-\cancelto{0}{\frac{2}{x^2}}}{3-\cancelto{0}{\frac{1}{x}}+\cancelto{0}{\frac{4}{x^2}}}=\frac{2}{3}$$608609Here is the code:610611\begin{verbatim}612$$\lim_{x\to \infty}\frac{2+\cancelto{0}{\frac{3}{x}}613-\cancelto{0}{\frac{2}{x^2}}}{3-\cancelto{0}{\frac{1}{x}}614+\cancelto{0}{\frac{4}{x^2}}}=\frac{2}{3}$$615\end{verbatim}616617Notice that \verb|\cancelto| requires two arguments, a value and an expression. For example, \verb|\cancelto{10}{x}| produces $\cancelto{10}{x}$.618619For more symbols, refer to the PDF ``LaTeX Symbol List.''620621\subsection{Re-sizing Parentheses}622623If you put regular-sized parentheses around a tall mathematical expression, it will not look right. For example, $\ds f(\frac{3x+2}{9x-1})$ would look better with larger parentheses, like this $\ds f\left(\frac{3x+2}{9x-1}\right)$.624625To do this in \LaTeX{} you use the \verb|\left| and \verb|\right| commands. You place \verb|\left| in front of the left parenthesis and \verb|\right| in front of the right one. This also works for square brackets, curly brackets, and vertical bars. Here are examples of each.626627\begin{itemize}628629\item \begin{verbatim}$\ds\left(\frac{4x^2}{9x^5}\right)$\end{verbatim}630631produces $\ds\left(\frac{4x^2}{9x^5}\right)$632633\item \begin{verbatim}$\ds\left[\frac{4x^2}{9x^5}\right]$\end{verbatim}634635produces $\ds\left[\frac{4x^2}{9x^5}\right]$636637\item \begin{verbatim}$\ds\left\{\frac{4x^2}{9x^5}\right\}$\end{verbatim}638639produces $\ds\left\{\frac{4x^2}{9x^5}\right\}$640641[Notice the \verb|\{| and \verb|\}| to get curly brackets.]642643\item \begin{verbatim}$\ds\left|\frac{4x^2}{9x^5}\right|$\end{verbatim}644645produces $\ds\left|\frac{4x^2}{9x^5}\right|$646647\end{itemize}648649Every \verb|\left| must be paired with a \verb|\right|, and vice versa, but the symbol does not have to be the same thing. For example,650651\begin{verbatim}$\ds\left(\frac{4x^2}{9x^5}\right]$\end{verbatim}652653produces $\ds\left(\frac{4x^2}{9x^5}\right]$654655If you want a parenthesis, etc. on only one side, then you put a period (.) on the other side (since left and right must be matched, even if you don't want anything on one side). For example,656657\begin{verbatim}$\ds\left.\frac{4x^2}{9x^5}\right|_{x=2}$\end{verbatim}658659produces $\ds\left.\frac{4x^2}{9x^5}\right|_{x=2}$660661[Notice \verb|\left.| does not produce a period, it's merely a placeholder. The height of everything between \verb|\left| and \verb|\right| determines the height of the parenthesis, etc., so both need to be there.]662663\subsection{Text in Math Mode}664665If you put text within dollar signs, all spaces are ignored and everything is placed in italics.666667To avoid this, use \verb|\text|. Compare the following:668669\verb|$f(x) and g(x)$| produces $f(x) and g(x)$670671\verb|$f(x) \text{ and } g(x)$| produces $f(x) \text{ and } g(x)$ [Notice the spaces around "and"]672673\subsection{Getting \LaTeX{} Code from Sage}674675If you have a mathematical expression in Sage, you can convert it to \LaTeX{} code using the \texttt{latex(...)} command.676677For example, in a Sage worksheet type latex(3/4) and hit ``Run.'' The output will be \verb|\frac{3}{4}|.678679Or suppose you run \verb|derivative(cos(1/x^5))| in a Sage worksheet, which produces the output \verb|5*sin(x^(-5))/x^6|. If you want to convert this answer to \LaTeX{}, simply type \verb|latex(_)| in the next cell and hit ``Run'' [remember, \verb|_| recalls the last output; you could also copy and paste to do \verb|latex(5*sin(x^(-5))/x^6)|]. Then Sage produces the output \verb|\frac{5 \, \sin\left(\frac{1}{x^{5}}\right)}{x^{6}}|680681[You may notice that the \LaTeX{} code produced by Sage is more complicated than your own, but it shouldn't be a problem.]682683\section{Using Sage in \LaTeX}684685Sometimes we want to use the result of a calculation in a \LaTeX{} document. One way to do this would be to perform the calculation elsewhere and then copy the answer into our document. However, using the sagetex package (which I have included), we can get Sage to output results directly into \LaTeX{}.686687\subsection{Getting Output from Sage}688689To perform a calculation in Sage and get the output in your \LaTeX{} document, use the \verb|\sage| command. Here are some examples:690691\begin{itemize}692693\item Typing \verb|$\sage{2+2}$| produces $\sage{2+2}$.694695\item Typing \verb|$\sage{2^3*3^4*5^2}$| produces $\sage{2^3*3^4*5^2}$.696697\item Typing \verb|$\sage{derivative(sin(x^2),x)}$| produces $\sage{derivative(sin(x^2),x)}$.698699\end{itemize}700701Since Sage output often includes mathematical symbols, you should usually put dollar signs around \verb|\sage{...}|.702703\subsection{Graphing}704705You can plot graphs using the \verb|\sageplot| command. It is similar to \verb|\includegraphics| (see section \ref{ingr} above). You can specify either a scale factor or the width or height directly. For example, \verb|\sageplot[width=1in]{plot(x^2)}| produces:706707\sageplot[width=1in]{plot(x^2)}708709Within the parentheses after \verb|plot| you can include all the options you would normally use in Sage. For example,710711\verb|\sageplot[height=2in]{plot(cos(x),xmin=-pi,xmax=pi,color='salmon')}|712713produces:714715\sageplot[height=2in]{plot(cos(x),xmin=-pi,xmax=pi,color='salmon')}716717\subsection{Sending Input to Sage}718719If you want to send things to Sage, you have two options, the \verb|sageblock| and \verb|sagesilent| environments. When you use \verb|sageblock|, the Sage code itself is typeset in your \LaTeX{} output, and the code is run in Sage. When you use \verb|sagesilent|, the Sage code is \emph{not} typeset, it is only run in Sage. For example,720721\begin{verbatim}722\begin{sageblock}723f(x)=3*x+2724g(x)=4*x^2725h(x)=derivative(f*g,x)726\end{sageblock}727\end{verbatim}728produces this output:729730\begin{sageblock}731f(x)=3*x+2732g(x)=4*x^2733h(x)=derivative(f*g,x)734\end{sageblock}735736These three functions are now available in Sage. For example, if I want $h(2)$ I can type \verb|$\sage{h(2)}$| in the \LaTeX{} file, and I will get $\sage{h(2)}$.737738Once I have defined a variable or function using \verb|sageblock| (or \verb|sagesilent|), I can use it again anywhere in my document. For example, I will now define a new function $k$ to be the integral of the $g$ function. I will type the following:739740\begin{verbatim}741\begin{sagesilent}742k(x)=integrate(g,x)743\end{sagesilent}744\end{verbatim}745746This Sage block will not appear in my \LaTeX{} output (I have manually included it here).747748\begin{sagesilent}749k(x)=integrate(g,x)750\end{sagesilent}751752The $k$ function can now be used. So here is $k(4)$: $\sage{k(4)}$ (type \verb|$\sage{k(4)}$|).753754Note: Use \verb|sageblock| and \verb|sagesilent| to \emph{input} things into Sage. These do \emph{not} bring the Sage output into your \LaTeX{} document. To get Sage output to appear, use \verb|\sage{...}|.755756\subsection{Problems with Sage in \LaTeX{}}757758Sometimes the Sage commands you run in \LaTeX{} do not produce the desired output. This can happen because Sage runs too slowly, so \LaTeX{} gives up on it and continues processing. This can result in ``??" showing up in the output, or the incorrect output may appear.759760When this happens, you can usually fix it manually:761762\begin{enumerate}763764\item Click on the ``Build" tab in the output pane.765766\item Click on the ``Sage" button. You may have to wait a little while for this to finish.767768\item Click on the ``Latex" button. Again, it may take some time to process.769770\item Finally, return to the ``Preview." It may take 20 or 30 seconds for the preview to update, but most of the time it will.771772\end{enumerate}773774Another possibility is that you have an error in your Sage code, so Sage is not producing the expected output. If the above steps do not help, double-check your Sage code. If necessary, you may have to copy your code to a Sage worksheet and check for errors there.775776\section{You're Ready to Go}777778I have included a \LaTeX{} template document in this assignment folder. When you want to create your own \LaTeX{} document, I suggest the following:779780\begin{enumerate}781782\item Create a new folder for your \LaTeX{} document (several auxiliary files will be created, and you don't want to clutter up your home directory).783784\item Copy the template file (LaTeX Template.tex) into this new folder (click the check box next to the file, press the ``Copy" button near the top of the page, select the new folder from the drop-down menu under ``Destination," and click the blue ``Copy" button).785786\item Open the new folder, click the check box next to the template, and click the ``Rename" button near the top of the page. Change the name as desired and click the blue ``Rename item" button.787788\item Now open this \LaTeX{} file and you're ready to begin.789790\end{enumerate}791792Remember to leave the original template blank for future use.793794You will be using \LaTeX{} for your assignment today. Open the file ``Writing in LaTeX Assignment.tex" for instructions.795796Also note that your group assignment will be written entirely in \LaTeX{}, and you will be submitting a hard copy in two weeks.797798\section{If You Need More Help}799800There is a large community of \LaTeX{} users online, so a simple search will answer many of your questions. For example if you google ``latex table," you can find instructions for producing tables from many different sources.801802There is a series of brief videos on YouTube about using \LaTeX{} in CoCalc (these videos refer to SageMathCloud, the former name of CoCalc) available here:803804{\color{blue}\underline{\url{https://www.youtube.com/playlist?list=PLnC5h3PY-znxc090kGv7W4FpbotlWsrm0}}}805806[This should be an active link in the PDF, but links don't work in the Preview.]807808\section{License}809810This material was developed by Aaron Tresham at the University of Hawaii at Hilo and is licensed under a \href{http://creativecommons.org/licenses/by-sa/4.0/}{\color{blue}\underline{Creative Commons Attribution-ShareAlike 4.0 International License.}}811812\end{document}813814815