Ansdoc
Ansdoc
Charles Wells
Department of Mathematics
Case Western Reserve University
University Circle
Cleveland, OH 44106-7058
USA
[email protected]
1 Description
Ans.sty is a LATEX style file. It allows you to write exercises and their
answers together in a LATEX document. When composed, the answers will
appear in a separate chapter or section elsewhere in the document (you
determine where they appear).
Ans.sty allows several variations. In the current release, you can use
article.sty or style files derived from article.sty and have exercises in
a subsection at the end of each section; or you can use book.sty and have
exercises at the end of each section or at the end of each chapter. I hope to
have a version that allows exercises interspersed throughout the document
(as in The TEXbook) in a later version.
This document is written using article.sty. Below are some exercises.
The ones that are marked with a dot have answers on page 9. Some of those
not marked with a dot have answers in the booklet called “Solutions to
exercises not answered in text” that is generated with this article. Later in
the document you will find more elaborate exercises along with their source.
∗
Copyright 2009
c by Charles Frederick Wells
1
1.1 Exercises
2 Using ans.sty
2.1 At the beginning of the document
The beginning of your document should look like this:
\documentstyle[ans]{article}
\makeanswers\artsec %% Use \bkchap or \bksec in book style
%% Other preamble commands you might want here
\begin{document}
If you want a booklet printed with answers to exercises not answered in the
article, you should also put \makesolutions in the preamble.
2.1.1 Options
One of the options commands must come after \makeanswers. The options
commands are
\artsec This is used in article style. It allows (no more than one) subsection
of exercises in each section.
\once This must be used in article style and allows just one section of
exercises for the whole document. See 2.1.2 below. You cannot make
a solution manual in this style. The file onceexam.tex contains an
example of its use.
\bkchap Used with book.sty, allowing one section of exercises per chapter.
\bksec Used with book.sty, allowing one section of exercises per section.
\bkscattered Not currently implemented. Like \artscattered for
book.sty.
\doanswers
You can put this any place after the last batch of exercises. This will
produce an unnumbered section titled “Solutions”, followed by the solutions
to the problems in each section. (The \once option will not produce a section
title, although it will print the answers.) When using book.sty, the section
of answers will be formatted as an unnumbered chapter, therefore starting
on a new page. In article.sty, the answer section will not start on a new
page. If you want it to, type \newpage before \doanswers. If you want the
page numbers to start over, type
\newpage
\setcounter{page}{1}
You could then bind the answer section as a separate document.
The command \dosolutions prints the answers you wrote to exercises
that are not marked as having answers. Normally, you would set the page
counter to 1 as above before invoking \dosolutions. This article does this,
as you can see by examining the source code.
2.3.4 Subexercises
To write an exercise with subexercises, start the exercise with \exer or
\exera, and then introduce each subexercise with \subexer or \subexera.
You can mix answered and nonanswered subexercises as you wish.
If the exercise begins with a subexercise without any preceding text,
it should begin “\exer\immsubexer” (either may be followed by an “a”).
The remaining subexercises are labeled \subexer or \subexera as before.
The answer to a subexercise beginning with \immsubexer should be labeled
\immsubanswer. The use of \immsubexer(a) and \immsubanswer keeps the
spacing straight (although the current version, May 24, 2009, still doesn’t
get the spacing right when the exercise has a double-digit number).
I apologize for the necessity of using \immsubexer and \immsubanswer,
but it seems quite complicated to create a version that knows whether the
exercise has any beginning text or not.
\exer\annot{hard}
In general, you can annotate a problem with any sort of remark in this
way.
\exercises
\exera This the first exercise of section~\ref{seca}.
\answer{This is the answer to the first exercise of
section~\ref{seca}.}
\exer\label{laste}\immsubexera This
is the first subexercise of an exercise
that has no text before the subexercises.
\immsubanswer This is an answer.
\eexer
2.6 Exercises
3 Bugs
3.1 Answers appearing in the text
or text appearing in the answers
If you enter an exercise and answer like this
the answer will appear in the text instead of in the answer section. The
point is that the answer must start on the same line as the word \answer.
If you do this
the second exercise will wind up as part of the answer to the first exercise,
because a blank line must follow the answer. Reread Section 2.3.3 carefully.
4 Customizing
If you look in the file ans.sty, you will discover numerous hints for cus-
tomizing the file.
4.1 Headings
The headings put on the answer section and on the solutions booklet are de-
termined by the option, \artsec, \bkchap, etc. and can easily be changed.
4.3 Exercises
1.• Prove that for any integer n > 2 there are no nonzero integers x, y and
z for which xn + y n = z n .
2. An exercise without an answer.
3.• The very last exercise.
Section 4
1. If I knew how to do \marginpar in LATEX I would have written it in the
margin. But that’s the way the cookie crumbles.
3. The very last answer.
Solutions to exercises
not answered in text
Section 1
3. This is an answer in the Solution Manual.
Section 2
7. Answer to Exercise 7 on page 8.
Section 4