Arithmetic, Elements of Algebra, Logarithms, Geometry and Trigonometry. LaTeX

From DPWiki

This is a wiki page to ease the LaTeX formatting of Arithmetic, Elements of Algebra, Logarithms, Geometry and Trigonometry project.

A forum page about it is here.

The preamble (last changed 03. apr. 2009)

The following preamble should be at the start of the document. Please, change the date when updating.

% last changed 03. apr. 2009

\documentclass[12pt]{book}
\usepackage{amsmath, amssymb, multirow, longtable, array}
\usepackage{tabularx, marvosym, cancel, bigdelim, graphics, wrapfig}
\usepackage[latin1]{inputenc}

% Font for paragraph tags and similar structures
\newcommand{\Tag}[1]{\textbf{\large #1}}
\newcommand{\Paragraph}[1]{\paragraph{\Tag{#1.}}}

% These should be able to handle either 1 or 2 arguments, as in
% \Example{2}{Text of example.} % or
% \Example{Text of example.}
% As defined they require 2 args.
\newcommand\Example[2]{\textsc{Example\if!#1!\else\ \fi#1.}---{\small #2}}

\newcommand\Case[2]{\Tag{Case\if!#1!\else\ \fi#1.}---\textit{#2}}

% Rule, while unnumbered, often has a list of rules in upper-case Roman bold
\newcommand{\Rule}[1]{\Tag{Rule.}---\textit{\large #1}}

% These set their argument in special type, so they *require* an argument
\newcommand{\Note}[1]{\textsc{Note}.--- {\small #1}}
\newcommand{\Proof}[1]{\textbf{Proof.}---\textit{#1}}
\newcommand{\Proofsc}[1]{\textsc{Proof}.--- {\small #1}}
\newcommand{\Suggestion}[1]{\textsc{\small Suggestion}.---{\small #1}}
\newcommand{\Caution}[1]{\textsc{Caution.}---\textit{#1}}
% These are defined to accept an argument only for syntactic uniformity
\newcommand{\Explanation}[1]{\textsc{Explanation}.---#1}
\newcommand{\Solution}[1]{\textsc{Solution}.---#1}

% Thought break for short line between sections
\newcommand\tb{\begin{center}\rule{4em}{.5pt}\end{center}}

% Center Headings
\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\centering\normalfont\Large\bfseries}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\centering\normalfont\large\bfseries}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\centering\normalfont\normalsize\bfseries}}
\makeatother

\makeatletter
\providecommand\shortintertext\intertext
\newcount\DP@lign@no
\newtoks\DP@lignb@dy
\newif\ifDP@cr
\newif\ifbr@ce
\def\f@@zl@bar{\null} 
\def\addto@DPbody#1{\global\DP@lignb@dy\@xp{\the\DP@lignb@dy#1}}
\def\parseb@dy#1{\ifx\f@@zl@bar#1\f@@zl@bar
    \addto@DPbody{{}}\let\@next\parseb@dy
  \else\ifx\end#1
    \let\@next\process@DPb@dy
    \ifDP@cr\else\addto@DPbody{\DPh@@kr&\DP@rint}\@xp\addto@DPbody\@xp{\@xp{\the\DP@lign@no}&}\fi
    \addto@DPbody{\end}
  \else\ifx\intertext#1
    \def\@next{\eat@command0}%
  \else\ifx\shortintertext#1
    \def\@next{\eat@command1}%
  \else\ifDP@cr\addto@DPbody{&\DP@lint}\@xp\addto@DPbody\@xp{\@xp{\the\DP@lign@no}&\DPh@@kl}
          \DP@crfalse\fi
    \ifx\begin#1\def\begin@stack{b}
      \let\@next\eat@environment
  \else\ifx\lintertext#1
    \let\@next\linter@text
  \else\ifx\rintertext#1
    \let\@next\rinter@text
  \else\ifx\\#1
    \addto@DPbody{\DPh@@kr&\DP@rint}\@xp\addto@DPbody\@xp{\@xp{\the\DP@lign@no}&\\}\DP@crtrue
    \global\advance\DP@lign@no\@ne
    \let\@next\parse@cr
  \else\check@braces#1!Q!Q!Q!\ifbr@ce\addto@DPbody{{#1}}\else
    \addto@DPbody{#1}\fi
    \let\@next\parseb@dy
  \fi\fi\fi\fi\fi\fi\fi\fi\@next}
\def\process@DPb@dy{\let\lintertext\@gobble\let\rintertext\@gobble
  \@xp\start@align\@xp\tw@\@xp\st@rredtrue\@xp\m@ne\the\DP@lignb@dy}
\def\linter@text#1{\@xp\DPlint\@xp{\the\DP@lign@no}{#1}\parseb@dy}
\def\rinter@text#1{\@xp\DPrint\@xp{\the\DP@lign@no}{#1}\parseb@dy}
\def\DPlint#1#2{\@xp\def\csname DP@lint:#1\endcsname{\text{#2}}}
\def\DPrint#1#2{\@xp\def\csname DP@rint:#1\endcsname{\text{#2}}}
\def\DP@lint#1{\ifbalancedlrint\@xp\ifx\csname DP@lint:#1\endcsname\relax\phantom
  {\csname DP@rint:#1\endcsname}\else\csname DP@lint:#1\endcsname\fi
  \else\csname DP@lint:#1\endcsname\fi}
\def\DP@rint#1{\ifbalancedlrint\@xp\ifx\csname DP@rint:#1\endcsname\relax\phantom
  {\csname DP@lint:#1\endcsname}\else\csname DP@rint:#1\endcsname\fi
  \else\csname DP@rint:#1\endcsname\fi}
\def\eat@command#1#2{\ifcase#1\addto@DPbody{\intertext{#2}}\or
  \addto@DPbody{\shortintertext{#2}}\fi\DP@crtrue
  \global\advance\DP@lign@no\@ne\parseb@dy}
\def\parse@cr{\new@ifnextchar*{\parse@crst}{\parse@crst{}}}
\def\parse@crst#1{\addto@DPbody{#1}\new@ifnextchar[{\parse@crb}{\parseb@dy}}
\def\parse@crb[#1]{\addto@DPbody{[#1]}\parseb@dy}
{\catcode`\$=13\gdef\check@braces#1#2!Q!Q!Q!{\ifx#2$$\br@cefalse\else\br@cetrue\fi
  }\gdef${\textbf{\huge ERROR}\GenericError{\space\space\space\@spaces\@spaces\@spaces}%
  {!!! DPalign/gather brace-parsing problem}%
  {Likely nested argument beginning with doubled character}%
  {Try putting an empty group at the start of the argument}\let$\relax}}
\def\eat@environment#1{\addto@DPbody{\begin{#1}}\begingroup
  \def\@currenvir{#1}\let\@next\digest@env\@next}
\def\digest@env#1\end#2{%
  \edef\begin@stack{\push@begins#1\begin\end \@xp\@gobble\begin@stack}%
  \ifx\@empty\begin@stack
    \@checkend{#2}
    \endgroup\let\@next\parseb@dy\fi
    \addto@DPbody{#1\end{#2}}
    \@next}
\def\lintertext{lint}\def\rintertext{rint}
\newif\ifbalancedlrint
\let\DPh@@kl\empty\let\DPh@@kr\empty
\def\DPg@therl{&\omit\hfil$\displaystyle}
\def\DPg@therr{$\hfil}
  
\newenvironment{DPalign*}[1][a]{%
  \if m#1\balancedlrintfalse\else\balancedlrinttrue\fi
  \global\DP@lign@no\z@\DP@crfalse
  \DP@lignb@dy{&\DP@lint0&}\parseb@dy
}{%
  \endalign
}
\newenvironment{DPgather*}[1][a]{%
  \if m#1\balancedlrintfalse\else\balancedlrinttrue\fi
  \global\DP@lign@no\z@\DP@crfalse
  \let\DPh@@kl\DPg@therl
  \let\DPh@@kr\DPg@therr
  \DP@lignb@dy{&\DP@lint0&\DPh@@kl}\parseb@dy
}{%
  \endalign
}
\makeatother
\begin{document}

Preamble change log

Please write here what you've added or changed to preamble and the reason for it.

  • 21. jul. 2008 Updated macros by adhere
  • 22. jul. 2008 Corrected a couple of typos and added the reference to the Outline by EveB
  • 23. jul. 2008 Expanded Example and Rule macro to properly place a dot when parameter blank (thanks dcwilson)
  • 23. jul. 2008 Replaced the preamble with my own working preamble. Headings centered to resemble the original, Rule changed to single argument. Thought break added (see Forum discussion) -- by EveB
  • 4. aug. 2008 Added the tabularx and marvosym packages (for tables on p. 57, 67) -- by sjohnson
  • 2. sep. 2008 Added cancel packages to enable cancelation lines (see p. 203) -- by veverica
  • 12. sep. 2008 Added bigdelim package to enable big delimiters in equations (see p. 227) -- by veverica
  • 12. sep. 2008 Added Proofsc macro to format another form of Proof
(see p. 227) -- by veverica
  • 23. oct. 2008 Added Case and Caution macro -- by veverica
  • 19. nov. 2008 Added graphics package to enable text rotation (see p. 405) -- by veverica
  • 09. jan. 2009 Added wrapfig package to enable text wrapping around floats (see p. 430) -- by veverica
  • 03. apr. 2008 Added DPalign and DPgather commands provided by Dcwilson (thanks Dcwilson :) ) -- by veverica

How to handle repeated formatting features

When you came across some new less common formatting feature, please describe here how to handle it so other formatters could adopt it.

Chapters and sections

The table of contents is on pages 003 and 004.

There is a detailed outline of the book (which differs in places from the TofC but reflects actual headings in the text) at [1].


  • Arithmetic, Elements of Algebra etc. are chapters and mark them as:
\chapter*{Name of the chapter}
  • Mark second levels (Definitions, Notation and Numeration etc.) as:
\section*{Name of subsection)
  • BOLD ALLCAPS centered headings (see DEFINITIONS on page 027) mark as:
\subsection*{Name of subsection)
  • EXAMPLES FOR PRACTICE (see page 017) mark as:
Algebra-Examples-practice.jpg
\subsubsection*{EXAMPLES FOR PRACTICE}
Beware!, all section of EXAMPLES FOR PRACTICE is within \begin{small}, \end{small} environment.
  • From page 350 a Series of Questions and Examples begins.
Algebra-Examination questions.jpg
Treat Arithmetics as \chapter*
and EXAMINATION QUESTIONS. as \section*

Paragraphs with various formats

  • Numbered paragraphs (see page 005; 1. Arithmetics ...) as:
Algebra-Paragraph.jpg
\Paragraph{1}Some text...
  • Example

.—Some text... (see page 010, paragraph 28.) mark as (first argument is optional number of an example):

Algebra-Example.jpg
\Example{}{Some text...}
  • Solution

.—Some text... (see page 010, paragraph 28.) mark as:

Algebra-Solution.jpg
\Solution{Some text...}
  • Explanation

.—Some text... (see page 010, paragraph 28.) mark as:

Algebra-Explanation.jpg
\Explanation{Some text...}
  • Note

.—Some text... (see page 011) mark as:

Algebra-Note.jpg
\Note{Some text...}
  • Rule.—Some text... (see page 012; paragraph 32.) mark as (Beware!!! macro to handle I. and II. rule has yet to be defined, help...):
Algebra-Rule.jpg
\Rule{Some text...}
  • Proof.—Some text... (see page 012; paragraph 33.) mark as:
Algebra-Proof.jpg
\Proof{Some text...}
  • Case.—Some text... (see page 314; paragraph 111.) mark as (first argument is optional number of a case):
Algebra-Case.jpg
\Case{}{Some text...}
  • Proof

.—Some text... (see page 227; example

33.) mark as:
Algebra-Proofsc.jpg
\Proofsc{Some text...}
  • Suggestion

.—Some text... (see page 207) mark as:

Algebra-Suggestion.jpg
\Suggestion{Some text...}
  • Caution

.—Some text... (see page 314; paragraph 110.) mark as:

Algebra-Caution.jpg
\Caution{Some text...}

Thought break

  • A thought break, a short centered line that divides two parts of text mark as:
Algebra-tb.jpg
\tb

Cancelation lines

  • Sometimes numbers or expressions are canceled with a strike-trough line (see page 203). Format as:
Algebra-Cancel.jpg
\cancel{6}, or \cancel{b^2}

Tips and tricks

  • In some examples of practice there is an answer at the end of the last line but right justified (see 063 Ans. 7%, nearly). To allow the answer at the same line if enough place or on the next one if not enough place mark this as:
Algebra-tips-Right-justified.jpg
Some text \hfil\allowbreak\null\nobreak\hfill\nobreak Ans.~7\%,~nearly.
  • To write a number or expression above or below the line (see page 203, Solution
1.)
  • above the line: At the place of raised digit we use \rlap command to overlap the text from the right and with \raisebox command we lift it 1em (one hight of m letter or one line). Beware, \raisebox command is textual and one should switch math mode on with $...$!
Algebra-tips-above.jpg
\dfrac{\rlap{\raisebox{1em}{$2$}}\cancel{6}a^2}{5}
  • below the line: The same code only the height is negative (-1em).
\dfrac{\rlap{\raisebox{-1em}{$2$}}\cancel{6}a^2}{5}
  • above or below centered (see page 203, Solution
1., canceled b-squared): We simply create two centered boxes of zero width. First one contains main expression (b-squared; canceled), the second one contains b but lowered -1em below the line.
Algebra-tips-below.jpg
\dfrac {2a\cancel{c}} {\makebox[0cm][c]{$\cancel{b^2}$}\makebox[0cm][c]{\raisebox{-1em}{$b$}}}
  • centered but regarding to some other expression (see page 203, Solution
3.)
Algebra-tips-text-centered-raised1.jpg
First we create a phantom object of the same size as the expression we are centering to. We enclose it in a box of width zero and place it centered (\maxebox[0cm][c]{\phantom}; see red rectangle below) at the beggining of the expression. The right edge of this immaginary box lays exactly at the middle of the expression we are centering to. So, therefore we simply place here (at the end of red box) our raised expression, also enclosed in a box of zero width and centered (see black rectangle below).
Algebra-tips-text-centered-raised.jpg
The code looks like this:
Multiplying, $\dfrac{1 - 4a^2c^2 }{ a^3} \times \dfrac{a^3}{1+2ac}=
\dfrac{
       (\makebox[0cm][c]{\phantom{$1 - 4a^2c^2$}\raisebox{1.1em}{$ 1-2ac$}}
       \cancel{1 - 4a^2c^2})\cancel{a^3}
      }
      {
       (\cancel{1+2ac})\cancel{a^3}
      }
= 1-2ac$  \quad Ans.
  • Big brackets enclosing several lines of equation (see page 227, Example
3.) could be formatted using bigdelim package and Dpalign environment.
Algebra-bigdelim.jpg
The code to format an example aboves:
\begin{DPalign*}
\lintertext{\indent Hence,}    7(x - 500)        &= \text{4,000} -  x +500\\
\lintertext{\indent Solving,}  7x - \text{3,500} &= \text{4,500} - x\\
\lintertext{or}                8x                &= \text{8,000}\\
\lintertext{whence,}           x                 &= \text{1,000 lb.} = \text{weight of smaller load}
\rlap{\raisebox{0.5\baselineskip}{\ \rdelim\}{2}{0em}[\quad \text{Ans.}]}}\\
\lintertext{and}               \text{4,000} -  x &= \text{3,000 lb.} = \text{weight of larger load }
\end{DPalign*}
We exploit bigdelim package and \rdelim command to produce such brackets.
\rdelim\}{2}{0em}[\quad \text{Ans.}]
  • \rdelim: a command defining bracket with some text to the right;
  • \}: defines curly brackets or braces;
  • {2}: braces should span over two lines;
  • {0em}: how much splace to the left should brackets and accompained text occupy. We use 0em as everything is on the right side;
  • [\quad \text{Ans.}]: some text to follow bracket;
One cound also use align enviroment and \intertext command to embbed the text.
  • Bracketed multiple answers right justified in the same line of text or in the next line if not enought space.
Algebra-Multiple-Answer-Right.jpg
At the beginning we use \hfil\allowbreak\null\nobreak\hfill\nobreak to place an object at the end of the line if there is enought place there.
We construct a table containing two left-aligned columns. The first column contains brace:
  • \ldelim: a command defining bracket with some text to the left;
  • \lbrace: a command defining left brace; \} could also be used;
  • {3}: brace should extend three lines;
  • {2.8em}: amount of space reserved for bracket and some text;
  • [Ans. ]: some text placed left from bracket.
To preserve nice vertical spacing we put our table into \raisebox command:
  • {0pt}: lift of raisebox;
  • [0pt]: [extend-above baseline;
  • [\totalheight]: extend-below-baseline. In this case for \totalheight of \raisebox.
Beware of missing space at right margin. This can be avoided by including % after \end{tabular} command. Thanks to dcwilson for prompt answer here.
2. In a right triangle $A C B$, right-angled at $C$, the side $B C
= 10$ feet 4 inches. If angle $A = 26°~59'~6''$, what do the other parts
equal?
\hfil\allowbreak\null\nobreak\hfill\nobreak 
\raisebox{0pt}[0pt][\totalheight]{
\begin{tabular}[t]{@{}ll@{}} 
\ldelim\lbrace{3}{3.8em}[Ans. ]  & Angle $B = 63°~0'~54''$.\\
& $A B = 22$ ft.~$9 \tfrac{1}{4}$ in., nearly.\\
& $A C = 20$ ft.~$3 \frac{1}{2}$ in., nearly.
\end{tabular}}%
  • Rotated text
Algebra-Rotated text.jpg
With graphics package enabled you can rotate the text with:
\rotatebox{90}{tenths.}

Wrapfig package use

  • You have a figure or table and you want to wrap text around it
Algebra-Wrapfig.jpg
First format the table as neccessary and than include it into \wraptable environment. More info about wrapfig package and its use can be found here.
\begin{wraptable}{l}{0pt}
\begin{tabular}[pos]{col}%
table definitions
\end{tabular}%
\end{wraptable}%

To do list

  • Can't find Suggestion

.—Some text... in the book; Found on page 207

  • Include Remark.—Some text... (see page 026) into definitions;
  • Include Short method.—Some text... (see page 104) into definitions;
  • Include thought break, short centered horizontal line into definitions (see formated text of page 015); done (23. jul. 2008)
  • Define how to handle a table of questions and answers where answers are big bracketed (see page 017 bottom). Several approaches are applied (see pages 015 and 018);