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