Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
| Download
Project: Old Math 242
Views: 482\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 6, 2018}56\usepackage{hyperref, parskip, amsmath, amssymb, latexsym, graphicx, enumerate, cancel, sagetex}7\usepackage[normalem]{ulem}89\begin{document}10\maketitle11\newcommand{\ds}{\displaystyle}1213In Calculus 1, 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 four panes. In the upper left you will see the actual \LaTeX{} document, which includes many obscure commands and strange-looking stuff. This is the input. In the upper 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. In the lower left you will see a box listing any errors or warnings. There should be none right now, but if you type incorrect code, then this box will tell you what's wrong. In the lower right you will see the ``Build Control" box. You will most likely not need to do anything with this.1819The active pane has a toolbar at the top (click on a pane to make it ``active"). If you put the cursor on a button, a small box will tell you what that button does. You may not need to use many of the buttons in the toolbars.2021\subsection{The Output Pane}2223The output pane shows a preview of the PDF document that \LaTeX{} produces.2425When the output pane is active, the first button on the left of the toolbar (looks like a fancy S) will synchronize the input and output (the location in the input pane will change to match what you see on the output pane). You can accomplish the same thing by double-clicking anywhere in the preview.2627The next four buttons allow you to change the display size.2829Then there are buttons to download and print a PDF document.3031On the right side of the toolbar, there is a drop-down menu which lets you change what that pane displays. Then there are two buttons to split the pane in two (either horizontally or vertically). This allows you to view two different parts of your document at once.3233Finally, there is a button to display only that pane and a button to close that pane.3435\subsection{The Input Pane}3637The input pane is where you actually type your document.3839The toolbar for the input pane begins with a green save button and a blue ``Time Travel" button (these are similar to what you've seen in Sage worksheets).4041Next is the ``Build'' button, which will process the input and produce the output. By default, ``Save'' and ``Build'' actually do the same thing. If you prefer, you can change this (so that clicking on ``Save" just saves and does not also build): open the account settings (with the gear icon), and uncheck the ``Build on save" box.4243Then you have the ``Synchronize'' button (this will change the output to match where you are in the input).4445The next button (looks like a flow chart) automatically formats the document in some way. I'm actually not sure what it does, and I haven't tried it yet.4647The rounded arrow buttons undo and redo, respectively.4849Then you have zoom in and zoom out buttons.5051The right side of the toolbar is the same as what we saw in the output pane.5253Now let's look at the input itself.5455At 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).5657\begin{itemize}5859\item[1] \verb|\documentclass[12pt]{article}|.6061You can ignore this line unless you want to change the font size (it can be 10pt, 11pt, or 12pt).6263\item[2] \verb|\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}|6465You can change the margins here (don't worry about everything else on this line).6667\item[3-5] \verb|\title{...}, \author{...}, \date{...}|6869You 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|.]7071\item[7] \verb|\usepackage{...}|7273I 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.7475\end{itemize}7677Line 10, \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.7879Next 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 Calculus 1 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.8081\subsection{Organizing the Document}8283Your document will be easier to read if you include sections, subsections, etc. to organize the material.8485Use the command \verb|\section{...}| to insert a section heading. \LaTeX{} automatically numbers and resizes the section heading.8687The 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).8889If you need even deeper levels of organization, the commands are \verb|\subsubsection{...}|, \verb|\paragraph{...}|, and \verb|\subparagraph{...}|.9091\subsection{Basic Formatting}9293\subsubsection{Emphasis}9495If you want to emphasize text, use the following commands:9697\verb|\textbf{This is bold}| produces \textbf{This is bold}.9899\verb|\textit{This is italics}| produces \textit{This is italics}.100101If you include the \texttt{ulem} package (which I have), then you can use the following commands for underlining, etc.102103\verb|\uline{This is underlined}| produces \uline{This is underlined}.104105\verb|\uuline{This is double-underlined}| produces \uuline{This is double-underlined}.106107\verb|\uwave{This is wavy-underlined}| produces \uwave{This is wavy-underlined}.108109\verb|\sout{This is struck out}| produces \sout{This is struck out}.110111\verb|\xout{This is crossed out}| produces \xout{This is crossed out}.112113\verb|\dashuline{This is underlined with dashes}| produces \dashuline{This is underlined with dashes}.114115\verb|\dotuline{This is underlined with dots}| produces \dotuline{This is underlined with dots}.116117Note: These formatting changes may not work in math mode (see below).118119\subsubsection{Text Size}120121If you want to change the text size, then you can use a ``declaration'' (not quite like a command). For example,122123124\verb|{\huge This is huge}| produces {\huge This is huge}.125126Notice 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.]127128Here are some size options: \verb|\tiny, \small, \large, \Large, \LARGE, \huge, \Huge|.129130\subsubsection{Centering}131132If you want to center text, then you declare a new ``environment'' using \verb|\begin| and \verb|\end|133134For example, \verb|\begin{center} This is centered \end{center}| produces135\begin{center} This is centered \end{center}136137[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.]138139\subsubsection{Spacing}140141To add horizontal space, use the \verb|\hspace| command. For example \verb|abc \hspace{1in} xyz| produces142143abc \hspace{1in} xyz144145To add vertical space, use the \verb|\vspace| command. For example \begin{verbatim}146abc \vspace{.25in}147148xyz149\end{verbatim}150produces151152abc \vspace{.25in}153154xyz155156[Note the blank line after vspace.]157158I have used inches (in) in my example, but you can also use centimeters (cm) or points (pt), among other less common options.159160The command \verb|\pagebreak| will end the page at that point.161162\subsubsection{Smart Quotes}163164For 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)165166Compare: \verb|"Here is a quotation."|, which produces "Here is a quotation."167168with \`{}\`{}\verb|Here is a quotation."|, which produces ``Here is a quotation."169170The 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.'171172\subsection{Lists}173174There are two environments used to create lists: enumerate and itemize.175176\subsubsection{Numbered Lists}177178To 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:179180\begin{verbatim}181\begin{enumerate}182\item First thing in the list.183\item Second thing in the list.184\item Third thing in the list.185\end{enumerate}186\end{verbatim}187produces:188189\begin{enumerate}190\item First thing in the list.191\item Second thing in the list.192\item Third thing in the list.193\end{enumerate}194195\subsubsection{Bullet Points}196197If you want bullet points instead of numbers, use \verb|itemize| in place of \verb|enumerate|.198199\begin{verbatim}200\begin{itemize}201\item First thing in the list.202\item Second thing in the list.203\item Third thing in the list.204\end{itemize}205\end{verbatim}206produces:207208\begin{itemize}209\item First thing in the list.210\item Second thing in the list.211\item Third thing in the list.212\end{itemize}213214\subsubsection{Nested Lists}215216Lists can also be nested (up to four levels deep). Here's an example with enumerate.217218\begin{verbatim}219\begin{enumerate}220\item First item221\begin{enumerate}222\item First subitem223\item Second subitem224\end{enumerate}225\item Second item226\begin{enumerate}227\item First subitem228\item Second subitem229\end{enumerate}230\end{enumerate}231\end{verbatim}232produces:233234\begin{enumerate}235\item First item236\begin{enumerate}237\item First subitem238\item Second subitem239\end{enumerate}240\item Second item241\begin{enumerate}242\item First subitem243\item Second subitem244\end{enumerate}245\end{enumerate}246247\subsubsection{Changing the Item Counters}248249By 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).250251For example,252253\begin{verbatim}254\begin{enumerate}[A.]255\item First item256\item Second item257\item Third item258\end{enumerate}259\end{verbatim}260produces261262\begin{enumerate}[A.]263\item First item264\item Second item265\item Third item266\end{enumerate}267268These 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.269270If 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,271272\begin{verbatim}273\begin{itemize}274\item[Apple] First item275\item[Orange] Second item276\item[Lemon] Third item277\end{itemize}278\end{verbatim}279produces:280281\begin{itemize}282\item[Apple] First item283\item[Orange] Second item284\item[Lemon] Third item285\end{itemize}286287The labels can be anything you like. One disadvantage is that you have to specify the label for each item separately.288289\vspace{12pt}290291\textbf{Remember, every} \verb|\begin{...}| \textbf{needs an} \verb|\end{...}|!292293\subsection{Special Symbols}294295Some 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.296297The 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.298299The percent sign is used to indicate a comment (everything after \% will be ignored). If you want \% to show up, then type \verb|\%|.300301The underscore is used for subscripts, and \verb|\_| is used for an underscore, \_.302303The 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).]304305Curly brackets are used all over the place, so \verb|\{| and \verb|\}| are used to get curly brackets, \{\}.306307\subsection{Verbatim Mode}308309If you want text to appear exactly as you type it (helpful for typing Sage or \LaTeX{} code), then you need to use verbatim mode.310311If 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.]312313If you have a longer portion (with multiple lines), then use the verbatim environment. For example,314315\verb|\begin{verbatim}|316\begin{verbatim}317f(x)=x^2318plot(f)319derivative(f,x)320\end{verbatim}321\verb|\end{verbatim}|322323produces:324325\begin{verbatim}326f(x)=x^2327plot(f)328derivative(f,x)329\end{verbatim}330331\subsection{Including Graphics}\label{ingr}332333If you want to add graphics to your document, then use the \verb|\includegraphics| command (this requires the graphicx package, which I have already included).334335Here is an example: \verb|\includegraphics[scale=.25]{main_campus_map.pdf}| produces:336337\includegraphics[scale=.25]{main_campus_map.pdf}338339The graphics document must be in the same folder as your \LaTeX{} document. The graphics file may be .pdf, .png, or .jpg.340341Notice 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.342343\subsection{Tables}344345If you want to include a table, you use the \verb|tabular| environment. Here is a simple example.346347\begin{verbatim}348\begin{tabular}{cc}349Name & Grade \\350John & 99 \\351Jane & 100 \\352\end{tabular}353\end{verbatim}354355produces:356357\begin{tabular}{cc}358Name & Grade \\359John & 99 \\360Jane & 100 \\361\end{tabular}362363The \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}|.364365Here is an example with three columns, where the first is left aligned, the second is centered, and the third is right aligned:366367\begin{verbatim}368\begin{tabular}{lcr}369Name & Exam Grade & Course Grade \\370John & 89 & B \\371Jane & 100 & A \\372\end{tabular}373\end{verbatim}374375produces:376377\begin{tabular}{lcr}378Name & Exam Grade & Course Grade \\379John & 89 & B \\380Jane & 100 & A \\381\end{tabular}382383Notice that each row of the table has an ampersand (\verb|&|) between each column and a double backslash (\verb|\\|) at the end of the line.384385If you want to add horizontal lines, you place \verb|\hline| between the rows.386387\begin{verbatim}388\begin{tabular}{lcr}389Name & Exam Grade & Course Grade \\390\hline391John & 89 & B \\392Jane & 100 & A \\393\end{tabular}394\end{verbatim}395396produces:397398\begin{tabular}{lcr}399Name & Exam Grade & Course Grade \\400\hline401John & 89 & B \\402Jane & 100 & A \\403\end{tabular}404405If you want to add vertical lines, you place a vertical bar ($|$) between the l, c, or r used to specify the number of columns.406407\begin{verbatim}408\begin{tabular}{l|c|r}409Name & Exam Grade & Course Grade \\410\hline411John & 89 & B \\412Jane & 100 & A \\413\end{tabular}414\end{verbatim}415416produces:417418\begin{tabular}{l|c|r}419Name & Exam Grade & Course Grade \\420\hline421John & 89 & B \\422Jane & 100 & A \\423\end{tabular}424425Here is a final example with lines everywhere:426427\begin{verbatim}428\begin{tabular}{|l|c|r|}429\hline430Name & Exam Grade & Course Grade \\431\hline432John & 89 & B \\433\hline434Jane & 100 & A \\435\hline436\end{tabular}437\end{verbatim}438439produces:440441\begin{tabular}{|l|c|r|}442\hline443Name & Exam Grade & Course Grade \\444\hline445John & 89 & B \\446\hline447Jane & 100 & A \\448\hline449\end{tabular}450451There are many more things you can do with tables, but these are the basics.452453\section{Math in \LaTeX}454455As we learned in Calculus 1, if we want to type math, we enclose the appropriate commands in dollar signs.456457For example, type \verb|$f(x)=x^2+3x+2$| to get $f(x)=x^2+3x+2$.458459Using 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$$460461Note: 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.462463\subsection{Fractions}464465To produce a fraction, type \verb|$\frac{numerator}{denominator}$|.466467For example, typing \verb|$\frac{3}{7}$| produces $\frac{3}{7}$.468469Typing \verb|$\frac{x^2+3x+9}{2x-4}$| produces $\frac{x^2+3x+9}{2x-4}$.470471If these fractions are too small, you can make them larger by typing \verb|\ds| at the beginning:472473Typing \verb|$\ds\frac{x^2+3x+9}{2x-4}$| produces $\ds\frac{x^2+3x+9}{2x-4}$.474475Note that \verb|\ds| is not required when you use double dollar signs.476477Typing \verb|$$\frac{x^2+3x+9}{2x-4}$$| produces $$\frac{x^2+3x+9}{2x-4}$$478479\subsection{Powers and Roots}480481If you have an exponent that is only one character, you can simply type a caret. For example, typing \verb|$x^2$| produces $x^2$.482483If your exponent has more than one character (whether it's $-1$, $25$, or $x^2-3x+2$), enclose the exponent in curly brackets.484485Compare what happens with \verb|$3^-2$| and \verb|$3^{-2}$|:486487$3^-2$ versus $3^{-2}$ [in the first case, only the negative symbol is in the exponent]488489Here's another example. To get $3^{x^2-8x+6}$ you type \verb|$3^{x^2-8x+6}$|.490491To get a square root, use \verb|\sqrt{}|.492493For example, \verb|$\sqrt{2}$| produces $\sqrt{2}$.494495And \verb|$\sqrt{3x^2-5x+1}$| produces $\sqrt{3x^2-5x+1}$.496497If you want a cube root, 4th root, etc., enclose the root number in square brackets after \verb|\sqrt|.498499For example, \verb|$\sqrt[3]{2}$| produces $\sqrt[3]{2}$.500501And \verb|$\sqrt[8]{\frac{3x+1}{9x+2}}$| produces $\sqrt[8]{\frac{3x+1}{9x+2}}$.502503Or \verb|$\ds\sqrt[8]{\frac{3x+1}{9x+2}}$| produces $\displaystyle\sqrt[8]{\frac{3x+1}{9x+2}}$.504505\subsection{Limits}506507To display a limit symbol, you type \verb|\lim|. To get text below the limit symbol, use an underscore followed by curly brackets.508509Here's an example:510511\verb|$\lim_{x\to 1}f(x)$| produces $\lim_{x\to 1}f(x)$. [Notice that \verb|\to| produces the arrow.]512513This usually looks better using \verb|\ds|:514515\verb|$\ds\lim_{x\to 1}f(x)$| produces $\ds\lim_{x\to 1}f(x)$.516517Here's another example:518519\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}$.520521To get a limit at infinity, use \verb|\infty|:522523Typing \verb|$\ds\lim_{x\to\infty}f(x)$| produces $\ds\lim_{x\to\infty}f(x)$.524525or typing \verb|$\ds\lim_{x\to -\infty}f(x)$| produces $\ds\lim_{x\to -\infty}f(x)$.526527For left and right limits, use the caret (\verb|^|) to put a plus or minus sign in the right spot:528529For example, \verb|$\displaystyle\lim_{x\to 1^+}f(x)$| produces $\displaystyle\lim_{x\to 1^+}f(x)$.530531And \verb|$\displaystyle\lim_{x\to 1^-}f(x)$| produces $\displaystyle\lim_{x\to 1^-}f(x)$.532533\subsection{Derivatives}534535Type \verb|$f'(x)$| to get $f'(x)$.536537For the second derivative, type \verb|$f''(x)$| to get $f''(x)$.538539For the third derivative, type \verb|$f'''(x)$| to get $f'''(x)$.540541For higher order derivatives, use the caret (\verb|^|).542543For example, \verb|$f^{(5)}(x)$| produces $f^{(5)}(x)$. [Don't forget the curly brackets around the exponent.]544545If you want to use Leibniz's notation, you can type $\frac{d}{dx}$ just like a regular fraction.546547For example, \verb|$\frac{d}{dx}f(x)$| produces $\frac{d}{dx}f(x)$.548549Here is an example for the 3rd derivative: \verb|$\frac{d^3}{dx^3}f(x)$| produces $\frac{d^3}{dx^3}f(x)$.550551\subsection{Summation Notation}552553To get a summation symbol, type \verb|\sum|.554555For example, \verb|$\sum i^2$| produces $\sum i^2$.556557To add a range of values for the sum, use \verb|_| and \verb|^|.558559For example, \verb|$\sum_{i=0}^{10} i^2$| produces $\sum_{i=0}^{10} i^2$. [Note the curly brackets around i=0 and 10.]560561This will look better with \verb|\ds| or double dollar signs:562563$\ds\sum_{i=0}^{10}i^2$ from \verb|$\displaystyle\sum_{i=0}^{10}i^2$|, or564565$$\sum_{i=0}^{10}i^2$$ from \verb|$$\sum_{i=0}^{10}i^2$$|566567\subsection{Integrals}568569To get the integral symbol, type \verb|\int|.570571For example, \verb|$\int f(x)$| produces $\int f(x)$.572573If you want to add the $dx$, you should add an extra space by typing \verb|\,| before $dx$:574575\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$]576577Here's what you get if you add \verb|\ds|: $\ds\int f(x)\,dx$.578579If you want a definite integral, you add a lower limit after an underscore and an upper limit after a caret.580581For example, typing \verb|$\int_a^b f(x)\,dx$| produces $\int_a^b f(x)\,dx$.582583Or, with \verb|\ds| you get $\ds\int_a^b f(x)\,dx$.584585If a limit of integration is more than one character, then enclose it in curly brackets:586587Typing \verb$\ds\int_{-2}^{18}f(x)\,dx$| produces $\ds\int_{-2}^{18} f(x)\, dx$.588589Here's what the same integral looks like in display mode (double dollar signs): $$\int_{-2}^{18} f(x)\, dx$$590591\subsection{Miscellaneous Symbols}592593To get ``approximately equal to,'' use \verb|\approx|. For example, \verb|$x\approx 20$| produces $x\approx20$.594595To get the plus or minus symbol, use \verb|\pm|. For example, \verb|$\pm 3$| produces $\pm3$.596597To 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$.598599For the capital Greek letters, capitalize the first letter: \verb|$\Pi$| produces $\Pi$ and \verb|$\Sigma$| produces $\Sigma$.600601[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$.]602603To get $\ge$ and $\le$, type \verb|$\ge$| or \verb|$\le$|. To get \verb|<| or \verb|>|, simply use the keyboard.604605For 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$.606607For composition of functions, use \verb|\circ|. For example, \verb|$f\circ g$| produces $f\circ g$.608609For 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:610611\verb|$1,\ 2,\ 3,\ \dots$| produces $1,\ 2,\ 3,\ \dots$612613\verb|$1+2+3+\cdots$| produces $1+2+3+\cdots$614615The \verb|\cancel| command can be used to cross things out (this requires the cancel package). For example:616617\begin{verbatim}618$$\frac{(x+1)\cancel{(x+2)}}{(x-3)\cancel{(x+2)}}=\frac{x+1}{x-3}$$619\end{verbatim}620621produces622623$$\frac{(x+1)\cancel{(x+2)}}{(x-3)\cancel{(x+2)}}=\frac{x+1}{x-3}$$624625There is also a \verb|\cancelto| command to do things like this:626627$$\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}$$628629Here is the code:630631\begin{verbatim}632$$\lim_{x\to \infty}\frac{2+\cancelto{0}{\frac{3}{x}}633-\cancelto{0}{\frac{2}{x^2}}}{3-\cancelto{0}{\frac{1}{x}}634+\cancelto{0}{\frac{4}{x^2}}}=\frac{2}{3}$$635\end{verbatim}636637Notice that \verb|\cancelto| requires two arguments, a value and an expression. For example, \verb|\cancelto{10}{x}| produces $\cancelto{10}{x}$.638639For more symbols, refer to the PDF ``LaTeX Symbol List.''640641\subsection{Re-sizing Parentheses}642643If 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)$.644645To 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.646647\begin{itemize}648649\item \begin{verbatim}$\ds\left(\frac{4x^2}{9x^5}\right)$\end{verbatim}650651produces $\ds\left(\frac{4x^2}{9x^5}\right)$652653\item \begin{verbatim}$\ds\left[\frac{4x^2}{9x^5}\right]$\end{verbatim}654655produces $\ds\left[\frac{4x^2}{9x^5}\right]$656657\item \begin{verbatim}$\ds\left\{\frac{4x^2}{9x^5}\right\}$\end{verbatim}658659produces $\ds\left\{\frac{4x^2}{9x^5}\right\}$660661[Notice the \verb|\{| and \verb|\}| to get curly brackets.]662663\item \begin{verbatim}$\ds\left|\frac{4x^2}{9x^5}\right|$\end{verbatim}664665produces $\ds\left|\frac{4x^2}{9x^5}\right|$666667\end{itemize}668669Every \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,670671\begin{verbatim}$\ds\left(\frac{4x^2}{9x^5}\right]$\end{verbatim}672673produces $\ds\left(\frac{4x^2}{9x^5}\right]$674675If 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,676677\begin{verbatim}$\ds\left.\frac{4x^2}{9x^5}\right|_{x=2}$\end{verbatim}678679produces $\ds\left.\frac{4x^2}{9x^5}\right|_{x=2}$680681[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.]682683\subsection{Text in Math Mode}684685If you put text within dollar signs, all spaces are ignored and everything is placed in italics.686687To avoid this, use \verb|\text|. Compare the following:688689\verb|$f(x) and g(x)$| produces $f(x) and g(x)$690691\verb|$f(x) \text{ and } g(x)$| produces $f(x) \text{ and } g(x)$ [Notice the spaces around "and"]692693\subsection{Getting \LaTeX{} Code from Sage}694695If you have a mathematical expression in Sage, you can convert it to \LaTeX{} code using the \texttt{latex(...)} command.696697For example, in a Sage worksheet type latex(3/4) and hit ``Run.'' The output will be \verb|\frac{3}{4}|.698699Or 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}}|700701[You may notice that the \LaTeX{} code produced by Sage is more complicated than your own, but it shouldn't be a problem.]702703\section{Using Sage in \LaTeX}704705Sometimes 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{}.706707\subsection{Getting Output from Sage}708709To perform a calculation in Sage and get the output in your \LaTeX{} document, use the \verb|\sage| command. Here are some examples:710711\begin{itemize}712713\item Typing \verb|$\sage{2+2}$| produces $\sage{2+2}$.714715\item Typing \verb|$\sage{2^3*3^4*5^2}$| produces $\sage{2^3*3^4*5^2}$.716717\item Typing \verb|$\sage{derivative(sin(x^2),x)}$| produces $\sage{derivative(sin(x^2),x)}$.718719\end{itemize}720721Since Sage output often includes mathematical symbols, you should usually put dollar signs around \verb|\sage{...}|.722723\subsection{Graphing}724725You 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:726727\sageplot[width=1in]{plot(x^2)}728729Within the parentheses after \verb|plot| you can include all the options you would normally use in Sage. For example,730731\verb|\sageplot[height=2in]{plot(cos(x),xmin=-pi,xmax=pi,color='salmon')}|732733produces:734735\sageplot[height=2in]{plot(cos(x),xmin=-pi,xmax=pi,color='salmon')}736737\subsection{Sending Input to Sage}738739If 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,740741\begin{verbatim}742\begin{sageblock}743f(x)=3*x+2744g(x)=4*x^2745h(x)=derivative(f*g,x)746\end{sageblock}747\end{verbatim}748produces this output:749750\begin{sageblock}751f(x)=3*x+2752g(x)=4*x^2753h(x)=derivative(f*g,x)754\end{sageblock}755756These 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)}$.757758Once 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:759760\begin{verbatim}761\begin{sagesilent}762k(x)=integrate(g,x)763\end{sagesilent}764\end{verbatim}765766This Sage block will not appear in my \LaTeX{} output (I have manually included it here).767768\begin{sagesilent}769k(x)=integrate(g,x)770\end{sagesilent}771772The $k$ function can now be used. So here is $k(4)$: $\sage{k(4)}$ (type \verb|$\sage{k(4)}$|).773774Note: 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{...}|.775776Note 2: If you have an error in your Sage code, \LaTeX{} should give you an error or warning. If you have trouble finding the error, you may want to copy your code to a Sage worksheet and check for errors there.777778Note 3: If you want to declare variables using \verb|sageblock| or \verb|sagesilent|, you can't use \verb|%var| like we normally do. To declare the variable h, for example, type \verb|h=var('h')| instead.779780\section{You're Ready to Go}781782I have included a \LaTeX{} template document in this assignment folder. When you want to create your own \LaTeX{} document, I suggest the following:783784\begin{enumerate}785786\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).787788\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).789790\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.791792\item Now open this \LaTeX{} file and you're ready to begin.793794\end{enumerate}795796Remember to leave the original template blank for future use.797798You will be using \LaTeX{} for your assignment today. Open the file ``Writing in LaTeX Assignment.tex" for instructions.799800Also note that your group assignment will be written entirely in \LaTeX{}, and you will be submitting a hard copy in two weeks.801802\section{If You Need More Help}803804There 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.805806There is a series of brief videos on YouTube about using \LaTeX{} in CoCalc. These videos refer to SageMathCloud, the former name of CoCalc, and they were made before the new \LaTeX{} editor (May 2018). But they are still useful and are available here:807808{\color{blue}\underline{\url{https://www.youtube.com/playlist?list=PLnC5h3PY-znxc090kGv7W4FpbotlWsrm0}}}809810[Double-click to follow the link.]811812\section{License}813814This 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.}}815816\end{document}817818819