% \iffalse
%
%% File `beton.dtx'.
%% Copyright (C) 1992--1995 Frank Jensen.  All rights reserved.
%
% Please send error reports and suggestions for improvements to:
%
%                          Frank Jensen
%                          Aalborg University
%                          DK-9220 Aalborg \O
%                          Denmark
%               Internet:  <fj@iesd.auc.dk>
%
% \fi

\def\fileversion{v1.3}
\def\filedate{1995/03/05}

% \CheckSum{112}
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%
% \iffalse
%<*driver>
\documentclass{ltxdoc}
\usepackage[concrete-math]{beton}
\AtBeginDocument
  {\DeclareFontShape\encodingdefault{ccr}{bx}{n}{<->sub*cmss/sbc/n}{}%
   \DeclareFontShape\encodingdefault{ccr}{bx}{it}{<->sub*cmss/sbc/it}{}%
   \DeclareFontShape\encodingdefault{ccr}{bx}{sl}{<->sub*cmss/sbc/sl}{}%
   \DeclareFontShape\encodingdefault{ccr}{bx}{sc}{<->sub*cmss/sbc/sc}{}}
\begin{document}
   \DocInput{beton.dtx}
\end{document}
%</driver>
% \fi
%
% \newcommand\beton{\texttt{beton}}
% \newcommand\euler{\texttt{euler}}
%
% \title{The \beton\ package}
% \author{Frank Jensen}
% \date{\filedate}
%
% \maketitle
%
% \section{Introduction}
%
% The purpose of the \beton\ package is to provide a setup so that
% documents using the package will automatically be typeset with the
% Concrete fonts designed by Don Knuth.
%
% The \beton\ package is based on Knuth's macros for the book
% ``Concrete Mathematics''~\cite{concrete}.  Knuth's macros can be
% found through anonymous ftp to \texttt{labrea.\allowbreak
% stanford.edu}: look for the file \texttt{gkpmac.tex} in directory
% \texttt{pub/tex/local/lib}.  Also, the fonts can be found at that
% site: look in directory \texttt{pub/tex/local/cm}.
%
% The Concrete fonts look best with a larger value for |\baselineskip|
% than the value normally used with the Computer Modern fonts.
% Therefore, the \beton\ package makes some decisions about line
% spacing that override the values specified by the standard \LaTeX\
% classes and packages.  See Section~\ref{beton:baselineskip-settings}
% for further details.
%
% In \cite{concrete}, the margin contains numerous humorous notes,
% so-called `graffiti', contributed by the students that attended the
% course by Graham, Knuth, and Patashnik.  These graffiti are typeset
% in a nine point slanted condensed version of the Concrete fonts.
% The current version of the \beton\ package does not provide any
% commands to support such graffiti.  However, such commands could
% easily be provided, e.g., by changing the |\marginpar| command.
%
% The \beton\ package deals with the \emph{text font} issues
% of~\cite{concrete}; i.e., it does not make any decisions about page
% layout (such as the height and width of the text area), font size,
% numbering scheme (e.g., \cite{concrete}~uses the page number for the
% numbering of tables [but not figures, since the book doesn't have
% any numbered illustrations]; use a separate package to get such a
% scheme), math fonts (use the \euler\ package to get this distinctive
% part of the look of~\cite{concrete}), or the amount of space above
% and below displayed equations.  However, the \beton\ package does
% set up the following:
% \begin{itemize}
%    \item Concrete fonts for text
%	(Section~\ref{beton:font-definitions}).
%    \item Increased value for |\baselineskip|
%	(Section~\ref{beton:baselineskip-settings}).  This may not be
%	appropriate for documents with short lines (e.g., two-column
%	documents), so an option (\texttt{standard-baselineskips}) is
%	provided to turn this feature off.
%    \item An option (\texttt{oldstyle-equation-numbers}) to request
%	`oldstyle' numerals for equation numbers
%	(Section~\ref{beton:equation-numbers}).
%    \item An option (\texttt{concrete-math}) to request `concrete'
%	math, if you insist
%	(Section~\ref{beton:concrete-math}).\footnote{Footnote numbers
%	are typeset in math mode, so if the math fonts are not
%	properly set up, these numbers will come out wrong.  The
%	\euler\ package and the \texttt{concrete-math} option will
%	both provide a proper setup.}
%    \item Some commands to `fine tune' the typography
%	(Section~\ref{beton:miscellany}).
% \end{itemize}
%
% Last, a note about the name of the present package: ``beton'' is the
% danish word for the `hard' meaning of the english word ``concrete''
% (and since there already exists a package of the name ``concrete''
% by Frank Mittelbach and Rainer Sch\"opf, I chose ``beton'' for
% mnemonic reasons).
%
% \StopEventually {
% \begin{thebibliography}{1}
%    \bibitem{concrete}
%       \textsc{R. L. Graham}, \textsc{D. E. Knuth}, and
%       \textsc{O. Patashnik}.
%       \newblock \textit{Concrete Mathematics}.
%       \newblock Addison-Wesley, 1989. 
% \end{thebibliography}
% }
%
% \section{Hello world}
%
% First, we announce the package.
%    \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{beton}[\filedate\space\fileversion]
\typeout{Package: `beton' \fileversion\space <\filedate> (FJ)}
%    \end{macrocode}
%
% \section{Font definitions}\label{beton:font-definitions}
%
% The Concrete family comes in medium normal, medium italic, medium
% slanted, and medium caps and small caps.  The \texttt{.fd} files for
% this family are defined in the \texttt{cmfonts.fdd} file (part of
% the \LaTeX\ `base' distribution).  Note that these \texttt{.fd}
% files are \emph{not} generated during the normal installation
% process for \LaTeX; you have to explicitly run \LaTeX\ on the
% \texttt{cmextra.ins} file.
%
% There are no bold variants of the Concrete fonts.  However,
% in~\cite{concrete}, Knuth chose the bold extended font from the
% Computer Modern (Roman) family to go with the Concrete fonts.  The
% \texttt{.fd} files for the Concrete fonts implement this choice.
%
% Instead of the CMR bold extended font, I recommend the CM Sans Serif
% demibold condensed font.\footnote{In 1992, I was involved in the
% production of a math book using Concrete for text and Euler for
% math; in that book, all headings were set in CM Sans Serif demibold
% condensed.  (The layout and the choice of fonts were decided by a
% reputable danish designer.)}  Simply put the following lines in the
% preamble or in a package file (do \emph{not} put spaces within the
% arguments to |\DeclareFontShape|):
%\begin{verbatim}
%\AtBeginDocument
%  {\DeclareFontShape\encodingdefault{ccr}{bx}{n}{<->sub*cmss/sbc/n}{}%
%   \DeclareFontShape\encodingdefault{ccr}{bx}{it}{<->sub*cmss/sbc/it}{}%
%   \DeclareFontShape\encodingdefault{ccr}{bx}{sl}{<->sub*cmss/sbc/sl}{}%
%   \DeclareFontShape\encodingdefault{ccr}{bx}{sc}{<->sub*cmss/sbc/sc}{}}
%\end{verbatim}
% Or, alternatively, use the medium weight Concrete (Roman) fonts for
% headings (and other places where bold is commonly used).  In my
% opinion, both alternatives are better than CMR bold extended.
%
% There is also a math italic version of the Concrete fonts; the
% \texttt{.fd} file for this subfamily is also defined in
% \texttt{cmfonts.fdd}.
%
% To typeset graffiti, special nine point condensed variants of the
% Concrete slanted and the Concrete math italic fonts were designed.
% These variants are not used by the current version of the \beton\
% package.
%
% We set the default family for |\rm| to Concrete Roman:
%    \begin{macrocode}
\def\rmdefault{ccr}
%    \end{macrocode}
% \section{Baselineskip settings}\label{beton:baselineskip-settings}
%
% Knuth chose a high value for |\baselineskip| to compensate for the
% relatively heavy (compared to Computer Modern) weight of the
% Concrete fonts.
%
% \begin{macro}{\beton@baselineskip@table}
% We specify the desired values for |\baselineskip| at various point
% sizes in a style similar to font definitions.  Here is a tentative
% specification for the most important sizes of the Concrete fonts:
%    \begin{macrocode}
\def\beton@baselineskip@table
   {<\@viiipt>10<\@ixpt>11.5<\@xpt>13<\@xipt>14.5<\@xiipt>16}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@setfontsize}
% All the standard \LaTeX\ size-changing commands (|\small|, |\large|,
% etc.)\ are defined in terms of the |\@setfontsize| macro.  This
% macro is called with the following three arguments: |#1|~is the
% size-changing command; |#2|~is the font size; |#3|~is the
% |\baselineskip| value.  We modify this macro to check
% |\beton@baselineskip@table| for an alternative |\baselineskip|
% value.
%    \begin{macrocode}
\def\beton@new@setfontsize#1#2#3%
   {\edef\@tempa{\def\noexpand\@tempb####1<#2}%
    \@tempa>##2<##3\@nil{\def\beton@baselineskip@value{##2}}%
    \edef\@tempa{\noexpand\@tempb\beton@baselineskip@table<#2}%
    \@tempa><\@nil
    \ifx\beton@baselineskip@value\@empty
       \def\beton@baselineskip@value{#3}%
    \fi
    \beton@old@setfontsize{#1}{#2}\beton@baselineskip@value}
%    \end{macrocode}
% Since the \texttt{oldlfont} and \texttt{newlfont} packages redefine
% the |\@setfontsize| macro, we defer our changes until the end of the
% preamble.  (See also Section~\ref{options}.)
%    \begin{macrocode}
\AtBeginDocument
   {\let\beton@old@setfontsize=\@setfontsize
    \let\@setfontsize=\beton@new@setfontsize}
%    \end{macrocode}
% \end{macro}
% The |\baselineskip| values specified in the above table should be
% appropriate for most purposes, i.e., for one-column material in the
% normal article/report/book formats.  However, it is usually
% desirable to use a smaller vaue for |\baselineskip| in two-column
% material.  We therefore provide the option
% \texttt{standard-baselineskips} to turn off the above automatic
% mechanism for |\baselineskip| settings.  (An alternative way to
% exercise control over the |\baselineskip| settings is to redefine
% the |\beton@baselineskip@table| macro.)
%    \begin{macrocode}
\DeclareOption{standard-baselineskips}
   {\AtBeginDocument{\let\@setfontsize=\beton@old@setfontsize}}
%    \end{macrocode}
% Note that the |\let|-assignment has to be executed after
% |\beton@old@setfontsize| has been defined; this is ensured by
% |\AtBeginDocument| and the fact that options to the \beton\ package
% is processed at the end of the package (Section~\ref{options}).
%
% \section{Equation numbers}\label{beton:equation-numbers}
%
% \begin{macro}{\theequation}\begin{macro}{\beton@oldstyle}
% In~\cite{concrete}, equation numbers are typeset with oldstyle
% numerals (from the math italic font).  You have to specify the
% \texttt{oldstyle-equation-numbers} option to get them.
%    \begin{macrocode}
\DeclareOption{oldstyle-equation-numbers}
   {\@ifundefined{chapter}
       {\def\theequation{{\beton@oldstyle\arabic{equation}}}}
       {\def\theequation{{\beton@oldstyle\thechapter}.%
                         {\beton@oldstyle\arabic{equation}}}}}
\DeclareRobustCommand\beton@oldstyle{\usefont{OML}{ccm}\f@series{it}}
%    \end{macrocode}
% Here, we assume that |\thechapter| generates a number (\emph{note}
% that in appendices, we will get math italic letters as `chapter
% numbers'!).  We also assume the standard format for equation
% numbers.
%
% The |\beton@oldstyle| macro is also used in the definition of
% the~|\t| accent macro (Section~\ref{beton:miscellany}).
% \end{macro}\end{macro}
%
% \begin{macro}{\oldstylenums}
% \begin{macro}{\TextOldstyle}\begin{macro}{\MathOldstyle}
% We provide a new definition of the |\oldstylenums| macro: this
% definition allows us to modify the generation of oldstyle numerals
% in text and in math separately, using two hooks, |\TextOldstyle| and
% |\MathOldstyle|.
%    \begin{macrocode}
\DeclareRobustCommand\oldstylenums[1]%
  {\begingroup
      \spaceskip\fontdimen\tw@\font
      \TextOldstyle \MathOldstyle #1%
   \endgroup}
%    \end{macrocode}
% In text, oldstyle digits should come from the Concrete fonts.
%    \begin{macrocode}
\let\TextOldstyle=\beton@oldstyle
%    \end{macrocode}
% By default, oldstyle digits in math come from the `letters' symbol
% font (this is also true if the \texttt{concrete-math} option to the
% \beton\ package is specified).
%    \begin{macrocode}
\providecommand\MathOldstyle{\mathgroup\symletters}
%    \end{macrocode}
% \end{macro}\end{macro}\end{macro}
%
% \section{Concrete math}\label{beton:concrete-math}
%
% The Concrete fonts were designed to blend well with the Euler math
% fonts, so I recommend the \euler\ package to go with the \beton\
% package.  If, however, for some reason, you wish to use the few
% Concrete fonts available for math, you can specify the
% \texttt{concrete-math} option for the \beton\ package.
%
% The \texttt{concrete-math} option selects Concrete Roman for math
% symbol font `operators' and Concrete math italic for math symbol
% font `letters'.  No bold versions and no `symbols' or `largesymbols'
% symbol fonts are available.
%    \begin{macrocode}
\DeclareOption{concrete-math}
   {\DeclareSymbolFont{operators}{OT1}{ccr}{m}{n}%
    \DeclareSymbolFont{letters}{OML}{ccm}{m}{it}}
%    \end{macrocode}
% We specify OT1 encoding (not |\encodingdefault|) for the `operators'
% symbol font, since uppercase greek letters still come from this font
% in the standard setup.
%
% \section{Miscellany}\label{beton:miscellany}
%
% \begin{macro}{\dash}\begin{macro}{\qback}\begin{macro}{\t}
% Knuth added a little extra space around em-dashes
% in~\cite{concrete}; this is obtained by typing |\dash---|. Also, the
% ending double-quote is pulled a little closer to commas and periods
% (|,\qback''| and |.\qback''|).
%
% The `tie-after' (|\t|) accent macro needs a math italic font:
% Knuth's macros use CM (my hypothesis is that this is due to 
% historical reasons: Knuth may have decided to switch to 
% oldstyle numerals for equation numbers \emph{after} he wrote the
% |\t| macro).  I believe Concrete should be used: Surely, it is best
% to have the accent come from the same font [family] as the accentee?
%    \begin{macrocode}
\def\dash---{\thinspace---\hskip.16667em\relax}
\def\qback{\kern-.15em} % between , or . and ''
\def\t#1{{\edef\next{\the\font}\beton@oldstyle\accent"7F\next#1}}
%    \end{macrocode}
% \end{macro}\end{macro}\end{macro}
%
% \section{Processing options}\label{options}
%
% Finally, we must remember to process the options:
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
% At this point, we have completed our changes to the |\@setfontsize|
% macro (through the |\AtBeginDocument| hook).  To make the changes
% take effect (i.e., setting the correct |\baselineskip| value), we
% execute the |\normalsize| command.
%    \begin{macrocode}
\AtBeginDocument{\normalsize}
%</package>
%    \end{macrocode}
%
% \Finale
\endinput
