CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

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

Views: 8489
1
\documentclass[12pt]{article}
2
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
3
\title{Writing in \LaTeX}
4
\author{Aaron Tresham}
5
\date{June 8, 2015}
6
7
\usepackage{hyperref, parskip, amsmath, amssymb, latexsym, graphicx, enumerate, cancel, sagetex}
8
\usepackage[normalem]{ulem}
9
10
\begin{document}
11
\maketitle
12
\newcommand{\ds}{\displaystyle}
13
14
In 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.
15
16
\section{Basics of \LaTeX}
17
18
When 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.
19
20
\subsection{The Output Pane}
21
22
Above 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).
23
24
Next 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.
25
26
After ``PDF'' there is the ``Build'' tab. Most of the time you will not need this. Later we'll see when this tab is useful.
27
28
Below these four tabs you'll see magnifying glasses with a minus and plus inside. Use these to zoom in and out on the preview.
29
30
Above 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.
31
32
Every 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.
33
34
\subsection{The Input Pane}
35
36
Now 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).
37
38
\begin{itemize}
39
40
\item[1] \verb|\documentclass[12pt]{article}|.
41
42
You can ignore this line unless you want to change the font size (it can be 10pt, 11pt, or 12pt).
43
44
\item[2] \verb|\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}|
45
46
You can change the margins here (don't worry about everything else on this line).
47
48
\item[3-5] \verb|\title{...}, \author{...}, \date{...}|
49
50
You 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|.]
51
52
\item[7] \verb|\usepackage{...}|
53
54
I 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.
55
56
\end{itemize}
57
58
Line 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.
59
60
Next 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.
61
62
\subsection{Organizing the Document}
63
64
Your document will be easier to read if you include sections, subsections, etc. to organize the material.
65
66
Use the command \verb|\section{...}| to insert a section heading. \LaTeX{} automatically numbers and resizes the section heading.
67
68
The 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).
69
70
If you need even deeper levels of organization, the commands are \verb|\subsubsection{...}|, \verb|\paragraph{...}|, and \verb|\subparagraph{...}|.
71
72
\subsection{Basic Formatting}
73
74
\subsubsection{Emphasis}
75
76
If you want to emphasize text, use the following commands:
77
78
\verb|\textbf{This is bold}| produces \textbf{This is bold}.
79
80
\verb|\textit{This is italics}| produces \textit{This is italics}.
81
82
If you include the \texttt{ulem} package (which I have), then you can use the following commands for underlining, etc.
83
84
\verb|\uline{This is underlined}| produces \uline{This is underlined}.
85
86
\verb|\uuline{This is double-underlined}| produces \uuline{This is double-underlined}.
87
88
\verb|\uwave{This is wavy-underlined}| produces \uwave{This is wavy-underlined}.
89
90
\verb|\sout{This is struck out}| produces \sout{This is struck out}.
91
92
\verb|\xout{This is crossed out}| produces \xout{This is crossed out}.
93
94
\verb|\dashuline{This is underlined with dashes}| produces \dashuline{This is underlined with dashes}.
95
96
\verb|\dotuline{This is underlined with dots}| produces \dotuline{This is underlined with dots}.
97
98
Note: These formatting changes may not work in math mode (see below).
99
100
\subsubsection{Text Size}
101
102
If you want to change the text size, then you can use a declaration (not quite like a command). For example,
103
104
105
\verb|{\huge This is huge}| produces {\huge This is huge}.
106
107
Notice 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.]
108
109
Here are some size options: \verb|\tiny, \small, \large, \Large, \LARGE, \huge, \Huge|.
110
111
\subsubsection{Centering}
112
113
If you want to center text, then you declare a new ``environment'' using \verb|\begin| and \verb|\end|
114
115
For example, \verb|\begin{center} This is centered \end{center}| produces
116
\begin{center} This is centered \end{center}
117
118
[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.]
119
120
\subsubsection{Spacing}
121
122
To add horizontal space, use the \verb|\hspace| command. For example \verb|abc \hspace{1in} xyz| produces
123
124
abc \hspace{1in} xyz
125
126
To add vertical space, use the \verb|\vspace| command. For example \begin{verbatim}
127
abc \vspace{.25in}
128
129
xyz
130
\end{verbatim}
131
produces
132
133
abc \vspace{.25in}
134
135
xyz
136
137
[Note the blank line after vspace.]
138
139
I have used inches (in) in my example, but you can also use centimeters (cm) or points (pt), among other less common options.
140
141
The command \verb|\pagebreak| will end the page at that point.
142
143
\subsubsection{Smart Quotes}
144
145
For 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)
146
147
Compare: \verb|"Here is a quotation."|, which produces "Here is a quotation."
148
149
with \`{}\`{}\verb|Here is a quotation."|, which produces ``Here is a quotation."
150
151
The 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.'
152
153
\subsection{Lists}
154
155
There are two environments used to create lists: enumerate and itemize.
156
157
\subsubsection{Numbered Lists}
158
159
To 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:
160
161
\begin{verbatim}
162
\begin{enumerate}
163
\item First thing in the list.
164
\item Second thing in the list.
165
\item Third thing in the list.
166
\end{enumerate}
167
\end{verbatim}
168
produces:
169
170
\begin{enumerate}
171
\item First thing in the list.
172
\item Second thing in the list.
173
\item Third thing in the list.
174
\end{enumerate}
175
176
\subsubsection{Bullet Points}
177
178
If you want bullet points instead of numbers, use \verb|itemize| in place of \verb|enumerate|.
179
180
\begin{verbatim}
181
\begin{itemize}
182
\item First thing in the list.
183
\item Second thing in the list.
184
\item Third thing in the list.
185
\end{itemize}
186
\end{verbatim}
187
produces:
188
189
\begin{itemize}
190
\item First thing in the list.
191
\item Second thing in the list.
192
\item Third thing in the list.
193
\end{itemize}
194
195
\subsubsection{Nested Lists}
196
197
Lists can also be nested (up to four levels deep). Here's an example with enumerate.
198
199
\begin{verbatim}
200
\begin{enumerate}
201
\item First item
202
\begin{enumerate}
203
\item First subitem
204
\item Second subitem
205
\end{enumerate}
206
\item Second item
207
\begin{enumerate}
208
\item First subitem
209
\item Second subitem
210
\end{enumerate}
211
\end{enumerate}
212
\end{verbatim}
213
produces:
214
215
\begin{enumerate}
216
\item First item
217
\begin{enumerate}
218
\item First subitem
219
\item Second subitem
220
\end{enumerate}
221
\item Second item
222
\begin{enumerate}
223
\item First subitem
224
\item Second subitem
225
\end{enumerate}
226
\end{enumerate}
227
228
\subsubsection{Changing the Item Counters}
229
230
By 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).
231
232
For example,
233
234
\begin{verbatim}
235
\begin{enumerate}[A.]
236
\item First item
237
\item Second item
238
\item Third item
239
\end{enumerate}
240
\end{verbatim}
241
produces
242
243
\begin{enumerate}[A.]
244
\item First item
245
\item Second item
246
\item Third item
247
\end{enumerate}
248
249
These 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.
250
251
If 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,
252
253
\begin{verbatim}
254
\begin{itemize}
255
\item[Apple] First item
256
\item[Orange] Second item
257
\item[Lemon] Third item
258
\end{itemize}
259
\end{verbatim}
260
produces:
261
262
\begin{itemize}
263
\item[Apple] First item
264
\item[Orange] Second item
265
\item[Lemon] Third item
266
\end{itemize}
267
268
The labels can be anything you like. One disadvantage is that you have to specify the label for each item separately.
269
270
\vspace{12pt}
271
272
\textbf{Remember, every} \verb|\begin{...}| \textbf{needs an} \verb|\end{...}|!
273
274
\subsection{Special Symbols}
275
276
Some 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.
277
278
The 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.
279
280
The percent sign is used to indicate a comment (everything after \% will be ignored). If you want \% to show up, then type \verb|\%|.
281
282
The underscore is used for subscripts, and \verb|\_| is used for an underscore, \_.
283
284
The 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).]
285
286
Curly brackets are used all over the place, so \verb|\{| and \verb|\}| are used to get curly brackets, \{\}.
287
288
\subsection{Verbatim Mode}
289
290
If you want text to appear exactly as you type it (helpful for typing Sage or \LaTeX{} code), then you need to use verbatim mode.
291
292
If 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.]
293
294
If you have a longer portion (with multiple lines), then use the verbatim environment. For example,
295
296
\verb|\begin{verbatim}|
297
\begin{verbatim}
298
f(x)=x^2
299
plot(f)
300
derivative(f,x)
301
\end{verbatim}
302
\verb|\end{verbatim}|
303
304
produces:
305
306
\begin{verbatim}
307
f(x)=x^2
308
plot(f)
309
derivative(f,x)
310
\end{verbatim}
311
312
\subsection{Including Graphics}\label{ingr}
313
314
If you want to add graphics to your document, then use the \verb|\includegraphics| command (this requires the graphicx package, which I have already included).
315
316
Here is an example: \verb|\includegraphics[scale=.25]{main_campus_map.pdf}| produces:
317
318
\includegraphics[scale=.25]{main_campus_map.pdf}
319
320
The graphics document must be in the same folder as your \LaTeX{} document. The graphics file may be .pdf, .png, or .jpg.
321
322
Notice 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.
323
324
\subsection{Tables}
325
326
If you want to include a table, you use the \verb|tabular| environment. Here is a simple example.
327
328
\begin{verbatim}
329
\begin{tabular}{cc}
330
Name & Grade \\
331
John & 99 \\
332
Jane & 100 \\
333
\end{tabular}
334
\end{verbatim}
335
336
produces:
337
338
\begin{tabular}{cc}
339
Name & Grade \\
340
John & 99 \\
341
Jane & 100 \\
342
\end{tabular}
343
344
The \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}|.
345
346
Here is an example with three columns, where the first is left aligned, the second is centered, and the third is right aligned:
347
348
\begin{verbatim}
349
\begin{tabular}{lcr}
350
Name & Exam Grade & Course Grade \\
351
John & 89 & B \\
352
Jane & 100 & A \\
353
\end{tabular}
354
\end{verbatim}
355
356
produces:
357
358
\begin{tabular}{lcr}
359
Name & Exam Grade & Course Grade \\
360
John & 89 & B \\
361
Jane & 100 & A \\
362
\end{tabular}
363
364
Notice that each row of the table has an ampersand (\verb|&|) between each column and a double backslash (\verb|\\|) at the end of the line.
365
366
If you want to add horizontal lines, you place \verb|\hline| between the rows.
367
368
\begin{verbatim}
369
\begin{tabular}{lcr}
370
Name & Exam Grade & Course Grade \\
371
\hline
372
John & 89 & B \\
373
Jane & 100 & A \\
374
\end{tabular}
375
\end{verbatim}
376
377
produces:
378
379
\begin{tabular}{lcr}
380
Name & Exam Grade & Course Grade \\
381
\hline
382
John & 89 & B \\
383
Jane & 100 & A \\
384
\end{tabular}
385
386
If you want to add vertical lines, you place a vertical bar ($|$) between the l, c, or r used to specify the number of columns.
387
388
\begin{verbatim}
389
\begin{tabular}{l|c|r}
390
Name & Exam Grade & Course Grade \\
391
\hline
392
John & 89 & B \\
393
Jane & 100 & A \\
394
\end{tabular}
395
\end{verbatim}
396
397
produces:
398
399
\begin{tabular}{l|c|r}
400
Name & Exam Grade & Course Grade \\
401
\hline
402
John & 89 & B \\
403
Jane & 100 & A \\
404
\end{tabular}
405
406
Here is a final example with lines everywhere:
407
408
\begin{verbatim}
409
\begin{tabular}{|l|c|r|}
410
\hline
411
Name & Exam Grade & Course Grade \\
412
\hline
413
John & 89 & B \\
414
\hline
415
Jane & 100 & A \\
416
\hline
417
\end{tabular}
418
\end{verbatim}
419
420
produces:
421
422
\begin{tabular}{|l|c|r|}
423
\hline
424
Name & Exam Grade & Course Grade \\
425
\hline
426
John & 89 & B \\
427
\hline
428
Jane & 100 & A \\
429
\hline
430
\end{tabular}
431
432
There are many more things you can do with tables, but these are the basics.
433
434
\section{Math in \LaTeX}
435
436
As we learned in Math 205, if we want to type math, we enclose the appropriate commands in dollar signs.
437
438
For example, type \verb|$f(x)=x^2+3x+2$| to get $f(x)=x^2+3x+2$.
439
440
Using 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$$
441
442
Note: 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.
443
444
\subsection{Fractions}
445
446
To produce a fraction, type \verb|$\frac{numerator}{denominator}$|.
447
448
For example, typing \verb|$\frac{3}{7}$| produces $\frac{3}{7}$.
449
450
Typing \verb|$\frac{x^2+3x+9}{2x-4}$| produces $\frac{x^2+3x+9}{2x-4}$.
451
452
If these fractions are too small, you can make them larger by typing \verb|\ds| at the beginning:
453
454
Typing \verb|$\ds\frac{x^2+3x+9}{2x-4}$| produces $\ds\frac{x^2+3x+9}{2x-4}$.
455
456
Note that \verb|\ds| is not required when you use double dollar signs.
457
458
Typing \verb|$$\frac{x^2+3x+9}{2x-4}$$| produces $$\frac{x^2+3x+9}{2x-4}$$
459
460
\subsection{Powers and Roots}
461
462
If you have an exponent that is only one character, you can simply type a caret. For example, typing \verb|$x^2$| produces $x^2$.
463
464
If your exponent has more than one character (whether it's $-1$, $25$, or $x^2-3x+2$), enclose the exponent in curly brackets.
465
466
Compare what happens with \verb|$3^-2$| and \verb|$3^{-2}$|:
467
468
$3^-2$ versus $3^{-2}$ [in the first case, only the negative symbol is in the exponent]
469
470
Here's another example. To get $3^{x^2-8x+6}$ you type \verb|$3^{x^2-8x+6}$|.
471
472
To get a square root, use \verb|\sqrt{}|.
473
474
For example, \verb|$\sqrt{2}$| produces $\sqrt{2}$.
475
476
And \verb|$\sqrt{3x^2-5x+1}$| produces $\sqrt{3x^2-5x+1}$.
477
478
If you want a cube root, 4th root, etc., enclose the root number in square brackets after \verb|\sqrt|.
479
480
For example, \verb|$\sqrt[3]{2}$| produces $\sqrt[3]{2}$.
481
482
And \verb|$\sqrt[8]{\frac{3x+1}{9x+2}}$| produces $\sqrt[8]{\frac{3x+1}{9x+2}}$.
483
484
Or \verb|$\ds\sqrt[8]{\frac{3x+1}{9x+2}}$| produces $\displaystyle\sqrt[8]{\frac{3x+1}{9x+2}}$.
485
486
\subsection{Limits}
487
488
To display a limit symbol, you type \verb|\lim|. To get text below the limit symbol, use an underscore followed by curly brackets.
489
490
Here's an example:
491
492
\verb|$\lim_{x\to 1}f(x)$| produces $\lim_{x\to 1}f(x)$. [Notice that \verb|\to| produces the arrow.]
493
494
This usually looks better using \verb|\ds|:
495
496
\verb|$\ds\lim_{x\to 1}f(x)$| produces $\ds\lim_{x\to 1}f(x)$.
497
498
Here's another example:
499
500
\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}$.
501
502
To get a limit at infinity, use \verb|\infty|:
503
504
Typing \verb|$\ds\lim_{x\to\infty}f(x)$| produces $\ds\lim_{x\to\infty}f(x)$.
505
506
or typing \verb|$\ds\lim_{x\to -\infty}f(x)$| produces $\ds\lim_{x\to -\infty}f(x)$.
507
508
For left and right limits, use the caret (\verb|^|) to put a plus or minus sign in the right spot:
509
510
For example, \verb|$\displaystyle\lim_{x\to 1^+}f(x)$| produces $\displaystyle\lim_{x\to 1^+}f(x)$.
511
512
And \verb|$\displaystyle\lim_{x\to 1^-}f(x)$| produces $\displaystyle\lim_{x\to 1^-}f(x)$.
513
514
\subsection{Derivatives}
515
516
Type \verb|$f'(x)$| to get $f'(x)$.
517
518
For the second derivative, type \verb|$f''(x)$| to get $f''(x)$.
519
520
For the third derivative, type \verb|$f'''(x)$| to get $f'''(x)$.
521
522
For higher order derivatives, use the caret (\verb|^|).
523
524
For example, \verb|$f^{(5)}(x)$| produces $f^{(5)}(x)$. [Don't forget the curly brackets around the exponent.]
525
526
If you want to use Leibniz's notation, you can type $\frac{d}{dx}$ just like a regular fraction.
527
528
For example, \verb|$\frac{d}{dx}f(x)$| produces $\frac{d}{dx}f(x)$.
529
530
Here is an example for the 3rd derivative: \verb|$\frac{d^3}{dx^3}f(x)$| produces $\frac{d^3}{dx^3}f(x)$.
531
532
\subsection{Summation Notation}
533
534
To get a summation symbol, type \verb|\sum|.
535
536
For example, \verb|$\sum i^2$| produces $\sum i^2$.
537
538
To add a range of values for the sum, use \verb|_| and \verb|^|.
539
540
For example, \verb|$\sum_{i=0}^{10} i^2$| produces $\sum_{i=0}^{10} i^2$. [Note the curly brackets around i=0 and 10.]
541
542
This will look better with \verb|\ds| or double dollar signs:
543
544
$\ds\sum_{i=0}^{10}i^2$ from \verb|$\displaystyle\sum_{i=0}^{10}i^2$|, or
545
546
$$\sum_{i=0}^{10}i^2$$ from \verb|$$\sum_{i=0}^{10}i^2$$|
547
548
\subsection{Integrals}
549
550
To get the integral symbol, type \verb|\int|.
551
552
For example, \verb|$\int f(x)$| produces $\int f(x)$.
553
554
If you want to add the $dx$, you should add an extra space by typing \verb|\,| before $dx$:
555
556
\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$]
557
558
Here's what you get if you add \verb|\ds|: $\ds\int f(x)\,dx$.
559
560
If you want a definite integral, you add a lower limit after an underscore and an upper limit after a caret.
561
562
For example, typing \verb|$\int_a^b f(x)\,dx$| produces $\int_a^b f(x)\,dx$.
563
564
Or, with \verb|\ds| you get $\ds\int_a^b f(x)\,dx$.
565
566
If a limit of integration is more than one character, then enclose it in curly brackets:
567
568
Typing \verb$\ds\int_{-2}^{18}f(x)\,dx$| produces $\ds\int_{-2}^{18} f(x)\, dx$.
569
570
Here's what the same integral looks like in display mode (double dollar signs): $$\int_{-2}^{18} f(x)\, dx$$
571
572
\subsection{Miscellaneous Symbols}
573
574
To get ``approximately equal to,'' use \verb|\approx|. For example, \verb|$x\approx 20$| produces $x\approx20$.
575
576
To get the plus or minus symbol, use \verb|\pm|. For example, \verb|$\pm 3$| produces $\pm3$.
577
578
To 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$.
579
580
For the capital Greek letters, capitalize the first letter: \verb|$\Pi$| produces $\Pi$ and \verb|$\Sigma$| produces $\Sigma$.
581
582
[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$.]
583
584
To get $\ge$ and $\le$, type \verb|$\ge$| or \verb|$\le$|. To get \verb|<| or \verb|>|, simply use the keyboard.
585
586
For 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$.
587
588
For composition of functions, use \verb|\circ|. For example, \verb|$f\circ g$| produces $f\circ g$.
589
590
For 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:
591
592
\verb|$1,\ 2,\ 3,\ \dots$| produces $1,\ 2,\ 3,\ \dots$
593
594
\verb|$1+2+3+\cdots$| produces $1+2+3+\cdots$
595
596
The \verb|\cancel| command can be used to cross things out (this requires the cancel package). For example:
597
598
\begin{verbatim}
599
$$\frac{(x+1)\cancel{(x+2)}}{(x-3)\cancel{(x+2)}}=\frac{x+1}{x-3}$$
600
\end{verbatim}
601
602
produces
603
604
$$\frac{(x+1)\cancel{(x+2)}}{(x-3)\cancel{(x+2)}}=\frac{x+1}{x-3}$$
605
606
There is also a \verb|\cancelto| command to do things like this:
607
608
$$\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}$$
609
610
Here is the code:
611
612
\begin{verbatim}
613
$$\lim_{x\to \infty}\frac{2+\cancelto{0}{\frac{3}{x}}
614
-\cancelto{0}{\frac{2}{x^2}}}{3-\cancelto{0}{\frac{1}{x}}
615
+\cancelto{0}{\frac{4}{x^2}}}=\frac{2}{3}$$
616
\end{verbatim}
617
618
Notice that \verb|\cancelto| requires two arguments, a value and an expression. For example, \verb|\cancelto{10}{x}| produces $\cancelto{10}{x}$.
619
620
For more symbols, refer to the PDF ``LaTeX Symbol List.''
621
622
\subsection{Re-sizing Parentheses}
623
624
If 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)$.
625
626
To 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.
627
628
\begin{itemize}
629
630
\item \begin{verbatim}$\ds\left(\frac{4x^2}{9x^5}\right)$\end{verbatim}
631
632
produces $\ds\left(\frac{4x^2}{9x^5}\right)$
633
634
\item \begin{verbatim}$\ds\left[\frac{4x^2}{9x^5}\right]$\end{verbatim}
635
636
produces $\ds\left[\frac{4x^2}{9x^5}\right]$
637
638
\item \begin{verbatim}$\ds\left\{\frac{4x^2}{9x^5}\right\}$\end{verbatim}
639
640
produces $\ds\left\{\frac{4x^2}{9x^5}\right\}$
641
642
[Notice the \verb|\{| and \verb|\}| to get curly brackets.]
643
644
\item \begin{verbatim}$\ds\left|\frac{4x^2}{9x^5}\right|$\end{verbatim}
645
646
produces $\ds\left|\frac{4x^2}{9x^5}\right|$
647
648
\end{itemize}
649
650
Every \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,
651
652
\begin{verbatim}$\ds\left(\frac{4x^2}{9x^5}\right]$\end{verbatim}
653
654
produces $\ds\left(\frac{4x^2}{9x^5}\right]$
655
656
If 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,
657
658
\begin{verbatim}$\ds\left.\frac{4x^2}{9x^5}\right|_{x=2}$\end{verbatim}
659
660
produces $\ds\left.\frac{4x^2}{9x^5}\right|_{x=2}$
661
662
[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.]
663
664
\subsection{Text in Math Mode}
665
666
If you put text within dollar signs, all spaces are ignored and everything is placed in italics.
667
668
To avoid this, use \verb|\text|. Compare the following:
669
670
\verb|$f(x) and g(x)$| produces $f(x) and g(x)$
671
672
\verb|$f(x) \text{ and } g(x)$| produces $f(x) \text{ and } g(x)$ [Notice the spaces around "and"]
673
674
\subsection{Getting \LaTeX{} Code from Sage}
675
676
If you have a mathematical expression in Sage, you can convert it to \LaTeX{} code using the \texttt{latex(...)} command.
677
678
For example, in a Sage worksheet type latex(3/4) and hit ``Run.'' The output will be \verb|\frac{3}{4}|.
679
680
Or 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}}|
681
682
[You may notice that the \LaTeX{} code produced by Sage is more complicated than your own, but it shouldn't be a problem.]
683
684
\section{Using Sage in \LaTeX}
685
686
Sometimes 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{}.
687
688
\subsection{Getting Output from Sage}
689
690
To perform a calculation in Sage and get the output in your \LaTeX{} document, use the \verb|\sage| command. Here are some examples:
691
692
\begin{itemize}
693
694
\item Typing \verb|$\sage{2+2}$| produces $\sage{2+2}$.
695
696
\item Typing \verb|$\sage{2^3*3^4*5^2}$| produces $\sage{2^3*3^4*5^2}$.
697
698
\item Typing \verb|$\sage{derivative(sin(x^2),x)}$| produces $\sage{derivative(sin(x^2),x)}$.
699
700
\end{itemize}
701
702
Since Sage output often includes mathematical symbols, you should usually put dollar signs around \verb|\sage{...}|.
703
704
\subsection{Graphing}
705
706
You 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:
707
708
\sageplot[width=1in]{plot(x^2)}
709
710
Within the parentheses after \verb|plot| you can include all the options you would normally use in Sage. For example,
711
712
\verb|\sageplot[height=2in]{plot(cos(x),xmin=-pi,xmax=pi,color='salmon')}|
713
714
produces:
715
716
\sageplot[height=2in]{plot(cos(x),xmin=-pi,xmax=pi,color='salmon')}
717
718
\subsection{Sending Input to Sage}
719
720
If 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,
721
722
\begin{verbatim}
723
\begin{sageblock}
724
f(x)=3*x+2
725
g(x)=4*x^2
726
h(x)=derivative(f*g,x)
727
\end{sageblock}
728
\end{verbatim}
729
produces this output:
730
731
\begin{sageblock}
732
f(x)=3*x+2
733
g(x)=4*x^2
734
h(x)=derivative(f*g,x)
735
\end{sageblock}
736
737
These 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)}$.
738
739
Once 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:
740
741
\begin{verbatim}
742
\begin{sagesilent}
743
k(x)=integrate(g,x)
744
\end{sagesilent}
745
\end{verbatim}
746
747
This Sage block will not appear in my \LaTeX{} output (I have manually included it here).
748
749
\begin{sagesilent}
750
k(x)=integrate(g,x)
751
\end{sagesilent}
752
753
The $k$ function can now be used. So here is $k(4)$: $\sage{k(4)}$ (type \verb|$\sage{k(4)}$|).
754
755
Note: 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{...}|.
756
757
\subsection{Problems with Sage in \LaTeX{}}
758
759
Sometimes 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.
760
761
When this happens, you can usually fix it manually:
762
763
\begin{enumerate}
764
765
\item Click on the ``Build" tab in the output pane.
766
767
\item Click on the ``Sage" button. You may have to wait a little while for this to finish.
768
769
\item Click on the ``Latex" button. Again, it may take some time to process.
770
771
\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.
772
773
\end{enumerate}
774
775
Another 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.
776
777
\section{You're Ready to Go}
778
779
I have included a \LaTeX{} template document in this assignment folder. When you want to create your own \LaTeX{} document, I suggest the following:
780
781
\begin{enumerate}
782
783
\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).
784
785
\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).
786
787
\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.
788
789
\item Now open this \LaTeX{} file and you're ready to begin.
790
791
\end{enumerate}
792
793
Remember to leave the original template blank for future use.
794
795
You will be using \LaTeX{} for your assignment today. Open the file ``Writing in LaTeX Assignment.tex" for instructions.
796
797
Also note that your group assignment will be written entirely in \LaTeX{}, and you will be submitting a hard copy in two weeks.
798
799
\section{If You Need More Help}
800
801
There 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.
802
803
There 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:
804
805
{\color{blue}\underline{\url{https://www.youtube.com/playlist?list=PLnC5h3PY-znxc090kGv7W4FpbotlWsrm0}}}
806
807
[This should be an active link in the PDF, but links don't work in the Preview.]
808
809
\section{License}
810
811
This 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.}}
812
813
\end{document}
814
815