100% found this document useful (1 vote)
1K views11 pages

Linear Algebra in Latex

This document provides instructions for compiling the source code for Jim Hefferon's undergraduate linear algebra textbook. It can be viewed online or downloaded for free. The source code uses LaTeX and requires a LaTeX distribution like TeXLive to compile. Running make_book_for_web.sh will generate a printable PDF version. Potential issues that could arise during compilation include errors with MetaPost graphics or incompatible LaTeX packages.

Uploaded by

ritolab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views11 pages

Linear Algebra in Latex

This document provides instructions for compiling the source code for Jim Hefferon's undergraduate linear algebra textbook. It can be viewed online or downloaded for free. The source code uses LaTeX and requires a LaTeX distribution like TeXLive to compile. Running make_book_for_web.sh will generate a printable PDF version. Potential issues that could arise during compilation include errors with MetaPost graphics or incompatible LaTeX packages.

Uploaded by

ritolab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

A

LT

X-ing
E
Linear Algebra

Jim Hefferon
2012-Feb-29

This document contains instructions for compiling the source to Jim Hefferons undergraduate textbook
Linear Algebra.

Summary of Linear Algebra.

Linear Algebra covers the material that is usually done in a three or four hour a week, one semester US
course: solving linear systems, vector spaces, linear maps, determinants, and eigenvalues and eigenvectors.
The pedagogical approach of the book is to help a student make the transition from calculus to upper division
mathematics. Therefore the presentation stresses careful motivation, many examples, clarity in the proofs,
and developmental exercise sets. The Preface contains a more detailed description.
1.1

Best When Viewed By . . .


To have a look go to http://joshua.smcvt.edu/linearalgebra. The files there can be viewed with
Acrobat Reader (or, that I know of, any PDF reader).
Get both the book and the answers and put them in the same directory, so that clicking on a question
number takes you to its answer and clicking on the answer takes you back to the question.
1.2

It is Free
These materials are freely available, in both readable and source form.
First, you are free to download the book. If you are a mathematics instructor then you are also free to
have students in your class use paper or electronic copies as a course text, either as the main text or as an
auxilliary text. (This includes the freedom to print out copies and sell them from your bookstore.)
Besides being free to use the output form of the text, you are also free to use the source. Some examples
of how this can be helpful are: an instructor can add a few favorite exercises here and there, perhaps include
a new Topic, adjust the development in a subsection, or even rewrite a portion entirely. Another example is:
someone who finds an error, say in the answer to an exercise, can send me the correction (email me either a
page number and a description or a diff file).
I welcome contribution of work back to the project. I of course reserve the ability to not use some things
but all the contributions that I do use are acknowledged in the source.

Use the Source

If you want to modify the materials then you need to know that the files here use the LATEX macro system
for the text formatter TEX. It is the standard system for writing mathematics.
So the first think you need is a distribution of TEX. I recommend TEXLive, http://www.tug.org/texlive.
If you are unfamiliar with TEX then a good way to get started is to get this document to come out.
These work for me under Linux: pdflatex 1st_readme. If that works if you can view it under Acrobat
Reader then your setup is at least partially correct. However, I must say that each TEX distribution has
a slightly different approach and, Im sorry, I cant help much. Youll have to find that information in the
distribution documentation.
What good is this How to Run It file if it must be run? It builds character. Anyway, if you are
having trouble even getting started, or only want a quick look, Ive included the output material in the file
1st readme.pdf.
If you are just starting working with LATEX then I recommend finding the Short Guide to LATEX2e
at http://www.ctan.org/, which might be enough for you to get through making small changes in the
materials.
The graphics here are in MetaPost. This should come with a TEX distribution, but you need to search
for the manual and you may also want The MetaFont Book by Knuth (ISBN 0-201-13444-6).
2.1

Compiling from source


Unzip the contents of linear_algebra.zip. This makes a new directory book.
The books source comes in a number of separate files. In addition to separate files for each section, such
as gr1.tex for the first section of the first chapter, here are some other key files.
1

file name
book.tex
bookjh.sty
linalgjh.sty
jhanswer.tex

what it is
Main file
Formatting instructions
Macros for Linear Algebra
Main file for the answers

After you get the files, you will have in your directory many .tex files, a few .mp files, and a few other
types such as LATEX style files .sty. The .tex files are for LATEX and the .mp files are for MetaPost for the
graphics (a few graphics are in forms such as .jpg).
2.1.1 The easy way
If you are on a Unix-y machine, such as Linux, try running ./make_book_for_web.sh from the command
line. Thats how I get a version of the book.
If you are not on a Unix machine then you have to read make_book_for_web.sh and mimic the steps.
There are not too many of them; it shouldnt be hard. These steps will give a printable version.
mpost dotprod.mp
mpost ch1.mp . . . mpost ch5.mp, mpost appen.mp, mpost voting.mp
pdflatex book
makeindex -s book.isty -p odd book.idx
pdflatex book
pdflatex jhanswer
pdflatex jhanswer

Make the dot product symbol.


Make the line art.
Produce the book and the future references
Alphabatize index.
Produce the final version of the book
Produce the answers
Resolve references from the first run

If something fails, make sure you have the latest TEX installation. Try it again.
If you still have trouble, in case it helps I can tell you what I have that works for me. I have the
TEXLive 2009 that comes with Ubuntus package system. The additional packages that I have downloaded
(often these are updates of the 2009 ones), besides the ones distributed in my file bundle, are these.
$ ls /usr/local/share/texmf/tex/latex
emerald
l3kernel
luxi
etoolbox
l3kernel.zip
mdframed
etoolbox.zip l3packages
mdframed.zip
geometry
l3packages.zip mh
geometry.zip local
mh.zip

picins
siunitx
siunitx.zip
slatex
tabu

thmtools
thmtools.zip

(Some of them may not be relevant.)


2.1.2 When Good Systems Do Things That Are Bad
What can go wrong? Almost anything. As Tom Wolfe quotes the early astronauts, It can blow at any
seam. Discouraging, isnt it?
The MetaPost-ing can fail in a number of ways. First, you need the 3D material from CTAN. Second,
you need all of the MetaPost material that Ive generated (e.g., venn.mp for Venn diagrams), although youll
have gotten that from me unless Ive made a mistake. Third, typesetting the labels, etc., may result in
MetaPost giving you a LATEX error. The thing about this failure is that the error message will say that the
first label is bad. But it isnt the first label; it is likely somewhere much further down the file. To figure it
out you must run pdflatex mpxerr.tex (this oddly-named file is where MetaPost writes the labeling lines
for them to be automatically LATEX-ed). Then youll get an error message that at least points to the correct
line, and presumably a little staring at it will give you a clue. (Ive wasted any number of hours looking at
line one when the problem was somewhere else entirely.)
LATEX-ing the book can then give you a wide variety of troubles.
It is a big book, and I use a number of styles. If you are having trouble that seems to come from, say,
color.sty, your first try is to go to CTAN and download the latest. In particular, I find that hyperref has been
a frequent changer over the course of time that I have been working on the text (understandably, obviously).
If you are having trouble with a part, see what commenting it out does. Go into book.tex, for instance
and comment out that part of the includeonly material (watch your commas! if you say ,vs3%, instead
2

of ,vs3,% then you may find LATEX complaining about not finding vs3map1.tex since map1 starts the next
line).
One area that can be annoying is that errors in the answer file do not tell you the line number in the
original source file. Instead, they tell you the line number in the source file for the answers (probably
bookans.tex ). That file was written when you LATEX-ed the book. So dont edit that file since your changes
will disappear the next time you do the book again. Instead, you can look up that line in the answers
source, then look for that same line in the original source. Edit that one. Then LATEX the book again.
Thank goodness for fast computers. (Getting the line numbers from the original source into bookans.tex
somehow would be a fine project for someone.)
One trouble that Ive had comes when switching between a hyperref -ed and non-hyperref -ed versions.
LATEX complains about not liking the cross-reference file (something about fifthoffive). My solution is to
delete all the cross-reference files (under Linux, rm -f *.aux *.toc), and then rerun the LATEX command
line twice. Not very elegant, I know, and once I accidentally left out the . between the * and the aux, but I
am over that now.
2.1.3 Options
I have a number of versions. If you like Knuths Computer Modern Roman more than the Concrete/Euler
combination that is the default then edit bookjh.sty to make the change. Now run ./make_book_for_web.sh.
2.1.4 Slides
I have some projector slides. These are beta. You can generate them by changing into the \slides
directory and running ./make_slides.sh. Some of the graphics take a few minutes to run, so you need to
be patient.

Guide to the Macros

You can use the same macros to write your materials as are used in the text. For example, when you make
up an exam and you want to refer to the vector space of polynomials of degree three, use $\polyspace_3$,
avoiding students confusion and also simplifying your day. This section describes how to use those macros.
First, the traditional disclaimer. In developing the book, I got to know a little bit about how to write
TEX and LATEX macros but I didnt get to know a lot! If you can improve what is here, Id welcome that
contribution.
3.1

Linear algebra macros


The macros that seemed to me to be specific to typesetting the linear algebra material are in the file
linalgjh.sty. For instance, here are macros for displaying systems of linear equations, matrices, row and
column vectors, special vector spaces, linear maps, etc.
Note that the book uses the amsmath package, including the commutative diagram extension amscd, so
all of those wonderful macros are available. In particular, displayed equations are shown with equation*
(the * makes them not-numbered) and all of the alignment structures like align and matrix structures are
available.
Another style that gets loaded is mathrsfs, for the Ralph Smith Formal Script fonts to make, for instance,
the script R for the range space.
linsys Make a linear system, in such a way that the columns line up. Here is an example of a three-unknowns
system; you want to do this only as a displayed equation.
\begin{equation*}
\begin{linsys}{3}
x &+ &3y &+ &a &= &7 \\
x &- &3y &+ &a &= &7
\end{linsys}
\end{equation*}
If a row is without some of the variables, be sure to nonetheless add the appropriate &s.
3

\begin{equation*}
\begin{linsys}{3}
x &+ &3y &+ &a &= &7 \\
& &3y & & &= &7
\end{linsys}
\end{equation*}
In the special case that a row starts with a negative sign, do not use &. That is, do not start the
second line below with &- &3y.
\begin{equation*}
\begin{linsys}{3}
x &+ &3y &+ &a &= &7 \\
& &-3y&+ &a &= &7
\end{linsys}
\end{equation*}
Remarks.
1. In the exercises I might have three or four linear systems on a horizontal line and to get them to
line up (to be t-aligned) I included an optional argument governing that vertical alignment.
2. LATEX note. The variables are put in the columns right-justified, while the additions or subtractions are centered. Between the columns is put 4/18-ths of an em (TEXbook, p. 167170; thats
a medmuskip).
3. LATEX note. The argument saying how many variables (which in the examples above is the 3) is
there instead of some quite large number because it isnt as simple as arg + 1 times rc. But I
wasnt sure, and might be convinced to change this by someone who knows what they are doing
here.
grstep Denote a step of Gausss Method.
\begin{equation*}
\begin{linsys}{2}
x &+ &y &= &0 \\
x &- &y &= &1
\end{linsys}
\grstep{-\rho_1+\rho_2}
\begin{linsys}{2}
x &+ &y &= &0 \\
&
&-2y&= &1
\end{linsys}
\end{equation*}
Show more than one row operation at a time with \grstep[2\rho_5]{\rho_1+\rho_3} for two
row operations, or \grstep[2\rho_5 \\ 3\rho_6]{\rho_1+\rho_3} for three. Swap two rows with
\rho_1\swap\rho_2.
matrix structures Generic matrices are made with mat.
\begin{equation*}
\begin{mat}
1 &2 &3 \\
4 &5 &6
\end{mat}
\end{equation*}
4

Note that there is no need to specify the number of columns; see the amsmath documentation.
There is an optional argument to make the columns right-aligned.
\begin{equation*}
\begin{mat}[r]
1 &2 &13 \\
4 &5 &6
\end{mat}
\end{equation*}
I restrict its use to those matrices (and column vectors) that contain only numbers, no variables at all.
There are places where I needed something a little different. In particular, I needed augmented matrices:
\begin{equation*}
\begin{amat}{2}
1 &2 &3 \\
4 &5 &6
\end{amat}
\end{equation*}
produces a matrix that is two-by-three, with a vertical bar between the final and next-to-final columns.
The argument 2 means that there are two columns before the vertical bar. (This also has an optional
argument to right-align.) I also sometime need matrices partitioned into columns:
\begin{equation*}
\begin{pmat}{c|c|c}
1 &2 &3 \\
4 &5 &6
\end{pmat}
\end{equation*}
produces a two-by-three matrix that has vertical bars separating the columns.
I make displayed determinant arrays with vmat
\begin{equation*}
\begin{vmat}
a &c \\
b &d
\end{vmat}
=ad-bc
\end{equation*}
and in-line determinants with \deter{A}. (Again, there is an optional argument to right-align.)
vectors Make column vectors with \colvec{1 \\ 2 \\ 3}. (There is an optonal argument to right-align
that I use for number-only vectors \colvec[r]{1 \\ 2 \\ 3}) Make row vectors with \rowvec{1 &2 &3}.
decimal point-aligned columns I use the dcolumn package:
\begin{equation*}
\begin{aligncolondecimal}{3}
15.12 &0.345
\end{aligncolondecimal}
\end{equation*}
5

makes a column vector aligned on the decimal with room for at most three decimal places on the right.
strings A digit 3 in a square is \digitinsq{3}. Not surprisingly, a digit 3 in a circle is \digitincirc{3}.
A sequence of strings is shown this way.
\begin{equation*}
\begin{strings}{ccccc}
\vec{e}_1 &\mapsto &\vec{e}_2 &\mapsto &\zero \\
\vec{e}_3 &\mapsto &\zero
\end{strings}
\end{equation*}
There are five cs because the longest line is of length five.
names for things Note that there is a page (inside the books cover) covering the notation conventions.
I tried to remember to make up macros to name things, rather than retype the thing each time I ran
across it. Here is a list.
1. The reals \Re, the rationals \Q, the complex numbers \C, the integers \Z, and the natural numbers
\N come out in the traditional blackboard bold.
2. A vector is \vec{v}_j. The zero vector is \zero. The length of a vector is \norm{\vec{v}},
and the absolute value of a number is \absval{r}. An angle can be expressed in degrees as
$53\degs$. The distance between two vectors is \dist (\vec{v}_1,\vec{v}_2).
3. The dot product of two vectors \vec{v}\dotprod\vec{w}. Please note that (as it is set up coming
from me) this is different than a \cdot.
4. The vector space of degree n polynomials \polyspace_n, and the vector space of n-by-m matrices
\matspace_{\nbym{n}{m}}. The vector space of linear maps from V to W \linmaps{V}{W}.
5. The span of a set S of vectors \spanof{S}.
6. The row space of a matrix is \rowspace{M} and the columnspace is \colspace{M}.
7. A set is \set{\colvec{x \\ y}\suchthat 2x+y=0}. The union and intersection of the sets S
and T is S\union T and S\intersection T. The complement of a set is \complement{S}.
8. The empty set is \emptyset.
9. A sequence, such as a string, is \sequence{s_0,s_1,\dots,s_n}. The concatenation of two
sequences is \cat{B_1}{B_2}.
10. A basis is \basis{\vec{\beta}_1,\dots,\vec{\beta}_n}. The standard basis for real n-space
is \stdbasis_n.
11. Isomorphic spaces is V\isomorphicto W.
12. The matrix representing a linear map h with respect to the bases B and D is \rep{h}{B,D}.
13. The size of a general matrix is \nbym{n}{m} while the special case of a square matrix is \nbyn{n}.
14. A map hs range space \rangespace{h} and null space \nullspace{h}, and generalized range
space \genrangespace{h} and generalized null space \gennullspace{h}
15. The direct sum of two subspaces V\directsum W.
16. The function, as specified by its domain and codomain, is described by \map{f}{D}{C}. Its action
on a single element x is x\mapsunder{f} f(x). Two maps are composed with \composed{g}{f}.
The identity map is \identity.
17. The projection of a vector into a subspace \proj{\vec{v}}{S}.
18. The restriction of a map to some subdomain is \restrictionmap{f}{S}.
19. The rank of a matrix \rank (A) and the nullity of a matrix \nullity (A). The transpose of a
matrix \trans{A}. The trace of a matrix \trace (A). The adjoint of a matrix is \adj (A).
6

20. The size of a box is \size (B).


21. The signum of a permutation is \sgn (\phi).
22. For the Topic on voting, voter preferences are indicated by \votepreflist{7}{1}{5} for the
column vector, and \voteprefloop{1}{2}{3} for the circle (for this one, the first argument
appears at the ten oclock position, the second argument at six oclock, and the third argument
at two oclock).
23. A generic field is \F.
aligned vdots To make \vdots come out inside a bunch of aligned equations, I use \vdotswithin{} from
the mathtools package.
\begin{align*}
a_{1,1}x_1+\cdots+a_{1,n}x_n &= d_1
\\
&\vdotswithin{=} \\
a_{m,1}x_1+\cdots+a_{m,n}x_n &= d_m
\end{align*}
Otherwise the three vertical dots are not centered on the equals sign.
3.2

Book layout macros


The macros that do chapter and section headings, or cross references, or how the exercises are laid out,
are in the file bookjh.sty.
theorem-like structures I have already declared the theorem, lemma, definition, and corollary environments. These will come out shaded. To change this, or the color of the shading or its border, see
also bookjh.sty
\begin{definition}
A \definend{big} vector space is one where you cant see the end when
you are standing at the zero vector, even with your glasses on.
\end{definition}
I have also declared (not shaded): example and remark.
By the way, note the \definend; I use this for the term being defined (I though I would automate
indexing, but Ive not got around to that).
proofs Use this.
\begin{proof}
Because I said so; thats why.
\end{proof}
The end-of-proof symbol can be changed as \renewcommand{\qedsymbol}{$\box$}. I avoid ever
having a proof end with a displayed equation so the question of where to put the end-of-proof symbol
in that case never arises.
footnotes Footnotes come out on the same page as the reference. I only use footnotes to suggest that a
reader can look for more in the Appendix \appendrefs{codomains}.
graphics I am using MetaPost for all of the graphics and all of the output drivers that I am interested in
handle .mps straight off. Instead I say this.
\begin{center}
\includegraphics{gr2.7}
\end{center}
7

Putting two graphics side-by-side, or putting parallel text, are all a bit messy. I use vcenteredhbox{}
jJust mimic what I did somewhere.
exercises and answers The exercise portions of a subsection looks like you might expect.
\begin{exercises}
\item
First Exercise
\begin{answer}
Answer to the first exercise.
\end{answer}
\item
Second Exercise
\begin{answer}
Answer to the second.
\end{answer}
\recommended \item
Third Exercise, recommended.
\begin{answer}
Answer to the third.
\end{answer}
\end{exercises}
Exercises are, of course, numbered automatically, in the same sequence as the other numbered parts
of the text.
My goal is to have all exercises have answers, even the proof exercises. Of course, the answers are not
written directly to the text; they are written to one or two separate files. Use jhanswer.tex to print
them.
Remarks.
1. Some of the exercises have parts. I use the environment exparts. The items in such an environment are \partsitems.
\recommended\item Do this one right away.
\begin{exparts}
\partsitem Do this first.
\partsitem Do this second.
\end{exparts}
\begin{answer}
\begin{exparts}
\partsitem Answer to the first.
\partsitem Answer to the second.
\end{exparts}
\end{answer}
I sometimes use exparts*, which leaves the items in a horizontal list, but it doesnt work very well
(it sometimes causes TEXs Underfull hbox errors; this is not as easy to fix as using a paralist
because I dont want the beginning of a part on one line and the end on another).
2. Any desired changes to the spacing, etc., of exercises is in exerciselist. See also the style for
the answers in bookans.sty.
3. You can redefine \recommendationmark to change the mark used to denote recommended exercises. You can also mark puzzles with \puzzle\item. This can be combined with \recommended.
4. If you are putting in an exercise without an answer, your best bet is to put an answer environment
that is blank. But really, you shouldnt do that. I have found that doing the answers to all of

the exercises improved both the questions and the presentation greatly, since I often found that
I needed a detail here, or some tweak there. (If what you want is that students cant read the
answer in their answer list, that is a different matter. See the next two remarks.)
5. These answers are typically quite detailed, giving the work and not just the answer; I approached
the answers expecting that the reader wants to learn and did not take the approach that the
reader is trying to cheat. (Remark. As a practicing teacher, I am very aware that it is not a
simple issue. Nonetheless, in my opinion, a reader is entitled to enough exercise and answer pairs
that, having tried a good selection and not just read the questions and peeked at the answers,
they can move on well-prepared to the next subsection. I figure that a dozen such pairs in each
subsection is about right. Then, to provide a selection and also to allow someone a second crack
at a problem type that gave them trouble the first time, I aimed for two dozen questions in each
subsection. If this question/answer situation bothers you, I would very much welcome additional
submissions of exercise sets for which students do not have access to the answers.)
6. As Ive set it up, you can have the answers written to either a single file, or separate files for the
answers to recommended exercises and the answers to the others. See the description above under
Options.
7. LATEX note. You can use \refs inside answers, even though they are written to other files. The
style for the answers reads in the reference files.
8. An answer that is taken from a cited source may not blend stylistically with the others (insofar
as I have a style). I use the disclaimer \answerasgiven.
tfae A small environment for The Following are Equivalent-type lists.
clearemptydoublepage Taken straight from the Companion. It does what it says.
cross references I use \nearbydefinition{def:BigThm}-like references. This has the disadvantage that
the referrer has to know what type of textual element it is referring to (in this case a definition), but
LATEX doesnt give you a way to know in this case (that I can see). Note that I try to make the
\label{def:BigThm} moderately descriptive.
I have set up nearby cross references (meaning there is no need to reference the chapter number
and the section number) for: \nearbydefinition, \nearbyfigure, \nearbylemma, \nearbyexample,
\nearbycounterexample, \nearbytheorem, \nearbycorollary, \nearbyexercise, \nearbyremark,
\nearbynotice, and \nearbynote. (I dont use most of these, but they are there anyway.)
topics Begin a new topic with \topic{My Favorite Topic}. The exercises come out looking a little
differently automatically, because I couldnt think of a common treatment that was both convienent
and consistent.
optional subsections A subsection is marked as optional with \subsectionoptional instead of LATEXs
standard \subsection. This asterisks the name in the Table of Contents. I have also followed the
practice of beginning each optional subsection with a italicised comment that it is optional, but this is
not part of the macro.
page headings This work is all done through the wonderful fancyhdr style. See the documentation for
that package.
hyperlink style I have set the links to come out in blue. Change that by altering the
\usepackage{
..,
linkcolor=blue,
..}{hyperref}
entry.

Making Your Exams

I have included an exam style that does what youd think it would do, number the exercises automatically,
automatically put headers and page numbers, and optionally allow exercises to have attached answers that
are printed to a separate file.
Here is a sample exam, without answers. See the web page for more extensive examples.
\begin{exam}
\item \pts{15}
How much wood could a woodchuck chuck?
\begin{enumerate}
\item If he would chuck wood?
\item If not?
\end{enumerate}
\item \pts{85}
Justify the Axiom of Choice, since we all know it is true anyway.
\end{exam}

Bugs
See the TODO.org file in the source.

10

You might also like