% \iffalse
% File sectsty.dtx
% Copyright Rowland McDonnell 1996, 1998, and 2002
% email rowland.mcdonnell@physics.org
% Some bits copyright the LaTeX3 team 1998.
%
% To install the sectsty package, run LaTeX on sectsty.ins.  To 
% typeset the documentation, run LaTeX on sectsty.dtx.
%
% Documentation and source file for the sectsty package. The package 
% consists of two files:
% 
% sectsty.ins
% sectsty.dtx
%
% This program - the two files sectsty.dtx and sectsty.ins - may be
% distributed and/or modified under the conditions of the LaTeX Project
% Public License, either version 1.2 of this license or (at your option)
% any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.2 or later is part of all distributions of LaTeX 
% version 1999/12/01 or later.
%
% Don't give this file to anyone unless you also give them an unmodified
% versions of sectsty.ins.
% 
% Don't modify this file unless you change its name and change all the
% various identification strings it contains to indicate that: it's
% derived from my sectsty package, it's now your responsibility, and
% it's no longer part of the sectsty package.
% 
% Remove \OnlyDescription to get the code typeset.  The code is not 
% well documented.
%
% Note to me: comment out \OnlyDescription to get the checksum right, 
% and then uncomment it because I don't want the code typeset by 
% default (this package is meant for non-hackers).
%
%\fi
%\iffalse
%<*driver>
\documentclass[a4paper,11pt]{ltxdoc}
\usepackage{varioref}
\def\MacroFont{\fontencoding\encodingdefault
               \fontfamily\ttdefault
               \fontseries\mddefault
               \fontshape\updefault
               \normalsize}%
\OnlyDescription
\begin{document}
 \DocInput{sectsty.dtx}
\end{document}
%</driver>
%\fi
%\iffalse
%<*package>
%\fi
%%
%% \CheckSum{1463}
%% \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
% The instances of ^^A are `real' comment characters to suppress the 
% end-of-line space in the middle of the command definitions.
%\fi
%
% \makeatletter
%\newcommand{\ttlb}{{\ttfamily\def\@tempcmda{OT1}^^A
%\ifx\f@encoding\@tempcmda\char"7B\else\{\fi}}
%
%\newcommand{\ttrb}{{\ttfamily\def\@tempcmda{OT1}^^A
%\ifx\f@encoding\@tempcmda\char"7D\else\}\fi}}
%
%\newcommand{\ttbs}{{\ttfamily\def\@tempcmda{OT1}^^A
%\ifx\f@encoding\@tempcmda\char`\\\else\textbackslash\fi}}
%^^A  \char`\\ was \char"5C
%
%\newcommand*{\comname}[2][VF500F2E]{{\ttfamily\ttbs #2^^A
%\def\@tempcmda{VF500F2E}\def\@tempcmdb{#1}^^A
%\ifx\@tempcmda\@tempcmdb\else\comarg{#1}\fi}}
%
%\newcommand*{\itinangle}[1]{$\langle$^^A
%{\mdseries\rmfamily\itshape#1}\/$\rangle$}
%
%\newcommand*{\comarg}[1]{{\ttfamily\ttlb^^A
%\itinangle{#1}\ttrb}}
%
%\newcommand*{\comoptarg}[1]{{\ttfamily[$\langle$^^A
%{\rmfamily\itshape#1}\/$\rangle$]}}
% \makeatother
% 
% \author{Rowland McDonnell\\ \texttt{rowland.mcdonnell@physics.org}}
% \title{The \packname{sectsty} package v2.0.2}
% \date{25th February 2002}
% 
% \newcommand*{\packname}[1]{{\sffamily #1}}
% \newcommand*{\classname}[1]{{\ttfamily #1}}
% \newcommand*{\filename}[1]{{\ttfamily #1}}
% 
% \maketitle
% 
% \tableofcontents
%
% \section{Introduction}
% 
% The \packname{secsty} package provides a set of commands for changing 
% the fount\footnote{I am one of the few remaining English speaking 
% people on the planet to use this spelling to refer to a set of type in 
% one size and style.} used for the various sectional headings in the 
% standard \LaTeXe\ document classes: \classname{article}, 
% \classname{book}, and \classname{report}.  This package also works 
% with the KOMA-Script classes \classname{scrartcl}, 
% \classname{scrbook}, and \classname{scrreprt}.
% 
% When I refer to sectional headings in this document, I mean the stuff 
% that is printed in the body of a document to indicate the start of 
% a part, chapter, section, and so on.  Appendix headings are treated 
% as chapter headings.
% 
% I'd appreciate any bug reports, comments, or suggestions emailed to 
% the address above.  I'm especially interested in any problems you 
% might have had understanding the documentation; and, of course, 
% anything else you'd like to tell me about this package.  I'm 
% certainly interested in any problems you might have had in using 
% \packname{sectsty} with other packages, although I can't promise to 
% be able to do anything useful about such problems.
%
% The \packname{titlesec} package offers a different 
% approach to changing the appearance of sectional headings.   The 
% \packname{fncychap} package has a set of alternative `canned' chapter 
% headings.  Both are available from CTAN.
% 
% Donald Arseneau won't let me say what bits of \packname{sectsty} he 
% wrote, but I'd like to thank him anyway: I couldn't have managed 
% without his help.  Thanks are also due to the various people who sent 
% me bug reports -- I've not kept track so rather than mention some of 
% you and miss others out, I'll just say thanks and leave it at that.  
% You know who you are and I appreciate your help.
% 
% \section{Basic use of \packname{sectsty}}
% 
% Make sure you include the package in your document by saying in your 
% document preamble:
%\begin{verbatim} 
%    \usepackage{sectsty}
%\end{verbatim}
% You will then have some new commands available.  For example:
%\begin{verbatim} 
%    \allsectionsfont{\sffamily}
%\end{verbatim}
% will give you sanserif for all sectional headings.
% 
% \packname{Sectsty} doesn't make any changes to the fount used until 
% you tell it what to do. The idea is that you supply some standard 
% \LaTeX\ fount selection commands which change the default selection. 
% The standard classes use Computer Modern Bold Extended by default for 
% sectional headings, and your commands change this. This means the 
% example above gives you Computer Modern Sanserif Bold Extended by 
% default.
% 
% You might want to change all headings so that they used medium 
% italic.  Since the default headings use bold extended, you need to 
% switch to the medium weight as well as switching to italic using the 
% standard \LaTeX\ fount selection commands, like this:
%\begin{verbatim}
%    \allsectionsfont{\mdseries\itshape}
%\end{verbatim}
% You can change the style of the different sectional headings separately.
% If you want \comname{section}s to be set in bold Adobe Times, you might 
% use standard \LaTeX\ fount selection commands like this:
%\begin{verbatim}
%    \sectionfont{\fontfamily{ptm}\selectfont}
%\end{verbatim}
% 
% Similar commands exist to change the style of the rest of \LaTeX's 
% standard headings independently: \comname{chapterfont}\comarg{commands} 
% will change chapter headings, and so on.  The full list of commands is 
% given in section~\vref{sec:command_list}.
% 
% If you don't understand the fount selection commands above, you might 
% like to look at the file \filename{fntguide.tex} that comes with the 
% standard \LaTeX\ distribution.
% 
% \section{Raggedright, raggedleft, and centred headings}
% 
% The arguments to \packname{sectsty}'s sectional heading style changing 
% commands can contain any \LaTeX\ commands you like.  For example, you 
% might say:
%\begin{verbatim}
%    \allsectionsfont{\sffamily\raggedright}
%\end{verbatim}
% and all sectional headings would be typeset raggedright in bold 
% extended sanserif. Not all \LaTeX\ commands will work properly when 
% used this like, although these three commands all have the expected 
% effect when used in one of \packname{sectsty}'s 
% \comname{\itinangle{section}font} commands:
% \begin{center}
% \begin{tabular}{ll}
% \comname{centering}   & Headings centred on the page \\
% \comname{raggedright} & Headings set flush left with a ragged right 
%                         margin \\
% \comname{raggedleft}  & Headings set flush right with a ragged left 
%                         margin \\
% \end{tabular}
% \end{center}
% It's a bad idea to use any of these commands to change paragraph or 
% subparagraph sectional headings: these two sections begin with `run-in' 
% headings that are on the same line as the start of the section's text, 
% and don't like being messed around like this. You can change the 
% indentation before these two sectional headings like this:
%\begin{verbatim}
%    \subparagraphfont{\hspace*{5em}}
%\end{verbatim}
% This adds an extra 5\,em space before each subparagraph heading.
% 
% As a further example, you might want chapter headings set flush with 
% the right margin.  This will do the job:
%\begin{verbatim}
%    \chapterfont{\raggedleft}
%\end{verbatim}
% 
% If you want to play around with this sort of thing, it might be useful 
% to know what sort of positioning you get by default with the standard 
% classes: all sectional headings except chapter and part are fully 
% justified (text set flush with the left and right margins), and 
% chapter headings are raggedright. Part headings vary: they are 
% raggedright in the article class, and centred in the book and report 
% classes.
% 
% \subsection{A complication affecting multiple line headings}
% 
% The standard \comname{section}, \comname{subsection}, and 
% \comname{subsubsection} commands ensure that, if you've got a 
% multiple line heading, lines beyond the first are typeset with a small 
% amount of indentation.  This is called hanging indentation, and is 
% entirely appropriate with the standard formatting.  However, two 
% problems arise from this: firstly, this hanging indentation usually 
% looks pretty stupid if you've decided to have centred headings; and 
% secondly, due to a bug in \LaTeX, the hanging indentation is 
% suppressed if you use |\\| in a heading that's typeset raggedright or 
% centred.
% 
% The first problem can be dealt with: if you use the 
% \comname{nohang} command in the appropriate 
% \comname{\itinangle{section}font} command, the hanging indentation will 
% be suppressed. For example:
%\begin{verbatim}
%    \sectionfont{\nohang\centering}
%\end{verbatim}
% will ensure that any multiple line section headings come out centred 
% as expected.
% 
% The second problem -- the suppression of hanging indentation when you 
% use |\\| in a raggedright or centred heading -- remains unsolved. I'm 
% told that it's caused by the definition of \comname{@centercr}. This 
% is part of the \LaTeX\ kernel and beyond my abilities to patch up. 
% This problem has been reported as a \LaTeX\ bug, so it might well be 
% sorted out in a future \LaTeX\ release.
% 
% Donald Arseneau's \packname{ulem} package makes its own arrangements 
% in this area, so sectional headings that are underlined using 
% \packname{sectsty} and \packname{ulem} have correct hanging 
% indentation even if you do use |\\| to end a line early.
%
% \section{The KOMA-script classes}
% 
% If you just want to change the fount used for all sectional headings, 
% you shouldn't use \packname{sectsty} with any of the KOMA-script 
% classes. Instead, you should redefine the \comname{sectfont} command 
% provided by the KOMA-script classes. This is akin to using 
% \packname{sectsty}'s \comname{allsectionsfont} command.
% 
% For example, the default definition is:
%\begin{verbatim}
%  \newcommand*\sectfont{\sffamily\bfseries}
%\end{verbatim}
% you might want to change from this bold sanserif to medium italic 
% roman.  To do this, you could add the following line to your document 
% preamble:
%\begin{verbatim}
%  \renewcommand*\sectfont{\rmfamily\mdseries\itshape}
%\end{verbatim}
% If you'd like different sectional headings to be printed with 
% different styles of type to each other, or if you'd like to underline 
% sectional headings or play other games that you can't do with the 
% KOMA-script \comname{sectfont} command, then \packname{sectsty} might 
% be of use with the KOMA-script classes.
% 
% You should note that the modifications applied by \packname{sectsty} 
% commands happen immediately after the \comname{sectfont} command is 
% executed.
% 
% The documentation for this package is written with the standard 
% \LaTeX\ classes in mind, so might not tie up exactly to the 
% KOMA-script classes. Despite that, and despite differences in 
% behaviour when things go wrong, \packname{sectsty} should work as 
% expected with the KOMA-script classes.
% 
%
%\section{All the commands}\label{sec:command_list}
% 
% The full list of commands is:
% \begin{description}
% \item[\comname{allsectionsfont}\comarg{commands}] Changes the style of 
% all sectional headings by executing \comarg{commands} before 
% printing each heading.
% 
% \item[\comname{partfont}\comarg{commands}] Changes the style of 
% `part' headings only by executing \comarg{commands} before 
% printing each heading; this affects both the title of the part and the 
% part number.
% 
% \item[\comname{chapterfont}\comarg{commands}] Changes the style of 
% `chapter' headings only by executing \comarg{commands} before 
% printing each heading; this affects both the title of the chapter and 
% the chapter number.
% 
% \item[\comname{sectionfont}\comarg{commands}] Changes the style of  
% `section' headings only by executing \comarg{commands} before 
% printing each heading.
% 
% \item[\comname{subsectionfont}\comarg{commands}]Changes the style of 
% `subsection' headings only by executing \comarg{commands} before 
% printing each heading.
% 
% \item[\comname{subsubsectionfont}\comarg{commands}]Changes the style 
% of  `subsubsection' headings only by executing \comarg{commands} before 
% printing each heading.
% 
% \item[\comname{paragraphfont}\comarg{commands}]Changes the style of 
% `paragraph' headings only by executing \comarg{commands} before 
% printing each heading; you should not use text positioning commands 
% for this heading.
% 
% \item[\comname{subparagraphfont}\comarg{commands}]Changes the style of the 
% `subparagraph' heading only by executing \comarg{commands} before 
% printing each heading; you should not use text positioning 
% commands for this heading.
% 
% \item[\comname{minisecfont}\comarg{commands}]]Changes the style of the 
% `minisec' heading only by executing \comarg{commands} before 
% printing each heading.  This command always works, but since these 
% headings only exist in the KOMA-script classes, it's useless with the 
% standard \LaTeX\ classes.
% \end{description}
% 
% There are also these commands:
% \begin{description}
% \item[\comname{partnumberfont}\comarg{commands}]Changes the style of 
% `part' heading numbers only; this does not affect the title of the 
% part heading.
% 
% \item[\comname{parttitlefont}\comarg{commands}]Changes the style of 
% `part' heading titles only; this does not affect the number of the 
% part heading.
% 
% \item[\comname{chapternumberfont}\comarg{commands}]Changes the style 
% of `chapter' heading numbers only; this does not affect the 
% title of the chapter heading.
% 
% \item[\comname{chaptertitlefont}\comarg{commands}]Changes the style of 
% `chapter' heading titles only; this does not affect the number 
% of the chapter heading.
% \end{description}
%
% And finally, an anomalous helper command:
% \begin{description}
% \item[\comname{nohang}]For use in multiple-line headings: this 
% command stops lines beyond the first having hanging indentation, 
% which looks pretty daft with centred headings.
% \end{description}
%
% \section{Some notes}
%
% The way \packname{sectsty} works is by re-defining all the commands 
% that produce the sectional headings.  The change arranges things so 
% that the fount selection commands you specify are executed immediately 
% before the sectional heading is printed.  You can change sizes, for 
% example, with the normal \LaTeX\ size changing commands.
% 
% You can include almost any \LaTeX\ commands in the argument to one of 
% \packname{sectsty's} commands.  Whether any particular command will 
% work properly or have the effect you want is a different matter.  If 
% you come across anything interesting you can do with this package that 
% I've not mentioned and you think someone else might be interested in, 
% you could let me know and I'll put it in the documentation.
% 
% If you use long section names you might like to make all sectional 
% headings \comname{raggedright}:
%\begin{verbatim}
%    \allsectionsfont{\raggedright}
%\end{verbatim}
% This means that \LaTeX\ won't try and justify sectional headings and 
% should manage to avoid a hyphentated sectional heading which tends to 
% look pretty bad.
%
% If you use \packname{sectsty} and get a complaint that you are using
% an old version of \LaTeX, there's probably no need to worry.
% \packname{Sectsty} will probably work correctly with any version of
% \LaTeXe\ after June 1996; because the earliest version I've tested
% \packname{sectsty} with is the June 1998 release of \LaTeX, that's the
% version I've specified as being needed. \packname{Sectsty} is not
% meant to work with \LaTeX~2.09; it's a good idea to get \LaTeXe\ if at
% all possible.
%
% \section{Underlining}
% 
% Some people have to underline sectional headings because of 
% regulations governing thesis submission and things like that. If 
% you're not forced to use underlining, it's probably best to avoid it: 
% underlining is usually considered bad typographical practice 
% (well-placed horizontal rules are a different matter). On top of that, 
% underlining sectional headings with \packname{sectsty} is not as 
% trivial a job as I'd like -- you've either got to get another package 
% or accept quite a lot of limitations.
% 
% To underline a sectional heading with \packname{sectsty}, you need to 
% put the \comname{underline} command as the last command in a 
% \comname{\itinangle{section}font} command.  For example:
%\begin{verbatim}
%   \usepackage{sectsty}
%   \allsectionsfont{\sffamily\underline}
%\end{verbatim}
% will give you underlined sanserif headings.
% 
% There are two main problems with this way of doing things: firstly, 
% the standard \LaTeX\ \comname{underline} command produces a one line 
% box in LR mode that can't be split across lines. This means that long 
% headings can't be split into two or more lines and will always result 
% in overfull \comname{hbox}es. Secondly, the underline rule is placed 
% underneath the lowest extent of the text and affects vertical spacing. 
% This is particularly ugly in the case of \comname{paragraph} and 
% \comname{subparagraph} headings which are on the same line as the 
% first line of text of the section.
% 
% Both these problems can be avoided by using the \packname{ulem} 
% package (see section~\vref{ulemsource} for how to get it):
%\begin{verbatim}
%   \documentclass{article}
%   \usepackage{sectsty}
%   \usepackage[normalem]{ulem}
%   \allsectionsfont{\sffamily\underline}
%\end{verbatim}
% Don't forget that the \comname{underline} command must always be the 
% last item in the \comname{\itinangle{section}font} command. This 
% example uses the familiar \comname{underline} command as before, but 
% because \packname{ulem} has been loaded, \packname{sectsty} 
% automatically redefines \comname{underline} inside sectional headings 
% to use \packname{ulem}'s underline code. The \comname{underline} 
% command has its normal meaning outside sectional headings, so you won't 
% get any nasty surprises.
% 
% I prefer the results you get using the \packname{ulem} package, but 
% you might prefer the appearance of underlined sectional headings 
% produced without \packname{ulem}'s help. If so, and you're not using 
% \comname{paragraph} or \comname{subparagraph} sections, or section 
% headings that need to be split over two lines, there's no need to use 
% \packname{ulem}.
% 
% \packname{Sectsty} always plays some dirty tricks which involve 
% re-defining the \comname{underline} command inside sectional headings 
% only. These tricks work differently if \packname{ulem} has been 
% loaded, but it doesn't matter whether you load \packname{ulem} before 
% or after \packname{sectsty}.
% 
% Despite these fun and games, the \comname{underline} command always 
% has its usual definition outside sectional headings and will work 
% normally in the rest of your document.
%
% \subsection{A detailed look at underlining}
% 
% It is possible to underline sectional headings in other ways.  This 
% section explains how, and also explains a little more about 
% underlining sectional headings with \packname{sectsty}.
% 
% The \packname{secsty} package lets you use two different commands to 
% underline sectional headings: \comname{underline} and 
% \comname{ulemheading}. Both commands suffer from the same restriction 
% in use: they must always be the last command in the argument to the
% \comname{\itinangle{section}font} command.  Both commands can be used 
% whether or not you've loaded \packname{ulem}: they are defined 
% differently depending on whether or not the \packname{ulem} package 
% has been loaded.  The decision on which definition to use is made at 
% the \comname{begin\ttlb document\ttrb} command, so you can load 
% \packname{ulem} before or after \packname{sectsty}.
% 
% If you want to use underlined headings, I strongly suggest you get the 
% \packname{ulem} package as well.  Without the \packname{ulem} package, 
% you get identical results (with a few problems) in sectional headings 
% using both \comname{underline} and \comname{ulemheading}.
%
% \packname{Sectsty} re-defines the \comname{underline} command inside 
% sectional headings.  This re-definition is what allows underlining to 
% work correctly in all of the standard sectional headings, and allows 
% the same command to behave differently if you've use the 
% \packname{ulem} package.  \TeX's usual grouping rules mean that the 
% \comname{underline} command is restored to its usual meaning at the 
% end of each sectional heading: the re-definition used by 
% \packname{sectsty} should have no effect on the rest of your document.
%
% Assuming for the moment that you're not using \packname{ulem}, you can 
% get a straightforward single underline using the normal \LaTeX\ 
% underline command like this:
%\begin{verbatim}
%   \allsectionsfont{\underline}
%\end{verbatim}
% This has a few problems. Most noticeably, it won't allow sectional 
% headings to break at the end of the line, so long headings will extend 
% beyond the right hand edge of the text. This is because the standard 
% \LaTeX\ \comname{underline} command puts its argument into a box made 
% in LR mode, so headings underlined this way will be one line headings 
% no matter what you do.
% 
% Another problem is that the underline rule used sits below the lowest 
% possible extent of the text it's underlining, and so increases the 
% space between the underlined heading and the text below. This is 
% especially noticeable if you're using \comname{paragraph} or 
% \comname{subparagraph} headings. And remember that the 
% \comname{underline} command must be the last in this list, like this:
%\begin{verbatim}
%   \allsectionsfont{\sffamily\underline}
%\end{verbatim}
% If you put \comname{sffamily} (or anything else) after 
% \comname{underline}, it won't work properly.
% 
% \subsubsection{Underlining with the \packname{ulem} package}
% 
% The \packname{ulem} package has some nice commands for improved 
% underlining in normal text. The main advantages are that the underline 
% rule is positioned better (so it doesn't mess up the line spacing), 
% and it allows long underlined headings to break normally at the end of 
% the line. All you need to do is load \packname{ulem}, and 
% \packname{sectsty} will do the rest. Try the following example as it 
% is here:
%\begin{verbatim}
%   \documentclass{article}
%   \usepackage{sectsty}
%   \usepackage[normalem]{ulem}
%   \allsectionsfont{\sffamily\raggedright\underline}
%   \begin{document}
%   \section{A very long sectional heading title that will 
%            have to be split over two lines}
%   \end{document}
%\end{verbatim}
% You'll notice that the long section heading was split over two 
% lines.  Now try this:
%\begin{verbatim}
%   \documentclass{article}
%   \usepackage{sectsty}
%   \allsectionsfont{\sffamily\raggedright\underline}
%   \begin{document}
%   \section{A very long sectional heading title that will 
%            have to be split over two lines}
%   \end{document}
%\end{verbatim}
% You'll notice that the underlining rule is positioned differently, and 
% the heading could not be split over two lines.
% 
% If you want to use in sectional headings some of the other types of 
% underlining allowed by the \packname{ulem} package, you can use the 
% \comname{ulemheading} command, as in this example to give double 
% underlining and raggedright sectional headings:
%\begin{verbatim}
%   \usepackage{sectsty,ulem}
%   \allsectionsfont{\raggedright\ulemheading{\uuline}}
%\end{verbatim}
% The \comname{ulemheading} command is meant to be used only inside 
% sectional headings like this. It takes two arguments: the first 
% argument is the \packname{ulem} package command to generate a 
% particular style of underlining; the second argument is the text to be 
% underlined, and is provided by the command that generates the 
% sectional heading. All you have to do is provide the first argument 
% and ensure that you put the \comname{ulemheading} at the end of the 
% \comname{\itinangle{section}font} command's argument, as in this 
% example to give you wavy underlined sans-serif headings:
%\begin{verbatim}
%   \usepackage{sectsty,ulem}
%   \allsectionsfont{\sffamily\ulemheading{\uwave}}
%\end{verbatim}
% The full list of modifications allowed by the \comname{ulemheading} 
% command is:
% \begin{center}
% \begin{tabular}{ll}
%   \ttbs ulemheading\ttlb\ttbs uline\ttrb  & single underline  \\
%   \ttbs ulemheading\ttlb\ttbs uuline\ttrb & double underline  \\
%   \ttbs ulemheading\ttlb\ttbs uwave\ttrb  & wavy underline    \\
%   \ttbs ulemheading\ttlb\ttbs sout\ttrb   & strike out with \texttt{-} \\
%   \ttbs ulemheading\ttlb\ttbs xout\ttrb   & cross out with \texttt{/}  \\
% \end{tabular}
% \end{center}
% It's possible to define more by following the directions in the 
% \packname{ulem} package.
% 
% If you typeset a document that uses \comname{ulemheading} on a system 
% where the \packname{ulem} package is unavailable, the document will be 
% processed but the output will be different. If you've not loaded the 
% \packname{ulem} package, \comname{ulemheading} will produce 
% underlining exactly the same as if you'd used the \comname{underline} 
% command: \comname{ulemheading} is defined to ignore the first argument 
% and pass the heading text to the normal underlining code. This means 
% you can produce a document using \packname{ulem}'s fancy underlining, 
% and process it on a \LaTeX\ system without \packname{ulem} by making a 
% single modification: commenting out the \comname{usepackage\ttlb 
% ulem\ttrb} command. The results will of course be different, but the 
% document will typeset.
% 
% \subsubsection{More notes on \packname{ulem} and 
% underlining}\label{ulemsource}
% 
% The \packname{ulem} package is available via anonymous ftp from the 
% Comprehensive \TeX\ Archive Network (CTAN). 
% You can find a list of CTAN sites and a Web interface to CTAN at 
% \texttt{http://www.tug.org/ctan.html}. The following ftp urls work now 
% (August 1998):
% \begin{center}
%{\footnotesize\begin{tabular}{@{}l@{}}
% \ttfamily
% ftp://ftp.dante.de/tex-archive/macros/latex/contrib/other/misc/ulem.sty\\
% \ttfamily
% ftp://ftp.tex.ac.uk/tex-archive/macros/latex/contrib/other/misc/ulem.sty\\
% \ttfamily
% ftp://ctan.tug.org/tex-archive/macros/latex/contrib/other/misc/ulem.sty\\
%\end{tabular}}
% \end{center}
% The \packname{ulem} package was written by Donald Arseneau, who 
% contributed some code and lots of useful advice to \packname{sectsty}.
% 
% It doesn't matter if you load \packname{ulem} before or after 
% \packname{sectsty}, because \packname{sectsty} waits until the 
% \comname{begin\ttlb document\ttrb} command before checking to see if 
% \packname{ulem} has been loaded.
% 
% \packname{Sectsty} uses a cunning trick to re-define the 
% \comname{underline} command inside sectional headings only; 
% \comname{underline} will work normally outside sectional headings.  
% The trick is cunning because the re-definition is different if the 
% \packname{ulem} package is in use in that document: the commands that 
% make this trick work wait until the \comname{begin\ttlb document\ttrb} 
% command has been executed, so it doesn't matter if you load 
% \packname{ulem} before or after \packname{sectsty}.
%
% The \comname{underline} and \comname{ulemheading} commands produce 
% identical results if the \packname{ulem} package is not loaded; they 
% will both use \LaTeX's normal underlining mechanism.  If you do load 
% \packname{ulem}, \comname{underline} will produce nicer results, and 
% \comname{ulemheading} will allow you to use any of \packname{ulem}'s 
% different underlining styles.
% 
% The \packname{ulem} package changes \LaTeX's emphasis commands so that 
% they use underlining rather than italics for emphasis.  If you don't 
% want this, you should load \packname{ulem} with the |normalem| option:
%\begin{verbatim}
%   \usepackage[normalem]{ulem}
%\end{verbatim}
%
% \section{Other things you can do with \packname{sectsty}}
% 
% Here are a few other things you can do using \packname{sectsty}; the 
% techniques for modifying section heading numbers work with or without 
% \packname{sectsty}. If you find that you can already get 
% \packname{sectsty} to do what you want to do, it might be an idea to 
% leave reading this section until later.
% 
% If you are going to read on, an apology: the \packname{sectsty} 
% package was originally meant to be a very simple thing to use. Various 
% requests from people who wanted to do various things mean that it's no 
% longer as simple to use as I'd like. This can't be helped: some people 
% \emph{need} underlining, and that's that. Unfortunately, the 
% documentation has ended up much more complicated that I'd like. This 
% section makes it even worse. I hope that the use people get from the 
% over long documentation outweighs the extra hassle it causes.
% 
% \subsection{Suppressing a page number}
% It's occasionally useful to be able to suppress page numbering on the 
% first page of a chapter. You can do this by saying:
%\begin{verbatim}
%   \chapterfont{\thispagestyle{empty}}
%\end{verbatim}
% This works because the argument to the \comname{chapterfont} command 
% is (obviously) executed on the page that the chapter begins on. As 
% luck has it, it's executed after the \comname{thispagestyle\ttlb 
% plain\ttrb} command issued by the \comname{chapter} command, so the 
% page style selected by the \comname{chapterfont} command is the one 
% that's used.
% 
% \subsection{Rules around sectional headings}
% 
% I've included a `unofficial' command, \comname{sectionrule}, in 
% \packname{sectsty} that can put a solid rule across the entire width 
% of the page, above and below a sectional heading. It's probably a good 
% idea to visit the library and study some typography books before using 
% this command. The command must be used as the last command in a 
% \comname{\itinangle{section}font} command, and has this syntax:
% \begin{center}
% \begin{tabular}{ll}
% \comname{sectionrule} & \comarg{raise top by}\comarg{top rule height}\\
%                 & \comarg{raise bottom by}\comarg{bottom rule height}\\
% \end{tabular}
% \end{center}
% \comarg{raise top by} is the length that the top rule is raised above 
% the baseline of the top line of the heading;
% \comarg{top rule height} is the height (thickness) of the top rule;
% \comarg{raise bottom by} is the length that the bottom rule is raised 
% above the baseline of the bottom line of the heading (a negative 
% length places the rule underneath the last line); and
% \comarg{bottom rule height} is the height (thickness) of the bottom 
% rule.
% 
% The \comname{sectionrule} command works like this:
%\begin{verbatim}
%   \sectionfont{\sectionrule{3ex}{3pt}{-1ex}{1pt}}
%\end{verbatim}
% What this example does is place two rules across the full width of the 
% text. One is a 3\,pt rule 3\,ex above the baseline of the top line of 
% the heading, and the other is a 1\,pt rule 1\,ex below the baseline of 
% the bottom line of the heading.
% 
% The vertical space before and after sectional headings can be affected 
% by these rules: the vertical space around a heading is placed before 
% and after \emph{everything} that is printed for the sectional heading, 
% so if a rule is the topmost item in the sectional heading, then the 
% vertical space will be measured to that rule.
% 
% Setting the height of either rule to 0\,pt will make it invisible, 
% although such a rule can still have an effect on spacing if you raise 
% or lower it.
% 
% The \comname{sectionrule} command has a few problems: in particular, 
% it can't place rules around centred headings, and it doesn't work 
% properly with run in headings such as the standard \comname{paragraph} 
% and \comname{subparagraph} headings. You might like to try the 
% \packname{titlesec} package if \packname{sectsty} can't help you do 
% what you want.
% 
% Because \comname{sectionrule} must be the last command in a 
% \comname{\itinangle{section}font} command, it can't be used with 
% underlined section headings: the underlining commands must 
% also be placed last, so you can't have both underlining and rules 
% around a sectional heading.
% 
% I wrote the \comname{sectionrule} command and it will be staying in 
% \packname{sectsty}. I call it `unofficial' because \packname{sectsty} 
% is meant to be very simple, and this command takes things a long way 
% away from my original `design concept'; this is why it's not 
% mentioned in the bulk of the documentation above.
% 
% \subsection{A box around sectional headings}
% 
% You can put a sectional heading inside a frame using the standard 
% \LaTeX\ \comname{fbox} command like this:
%\begin{verbatim}
%   \sectionfont{\noindent\fbox}
%\end{verbatim}
% 
% This has two limits: it doesn't work with \comname{chapter} or 
% \comname{part} headings, and it only works with single line headings. 
% The reason for this last problem is that the \comname{fbox} command 
% typesets text in LR mode and will therefore always produce a single 
% line of text.
%
% I've heard that other box making commands can be used to place a frame 
% around a sectional heading in a similar way (\comname{colorbox} 
% apparently works). If you use any box making command like this, you 
% will need to add a \comname{noindent} as with \comname{fbox}. This is 
% because the box making command switches \TeX\ from vertical mode to 
% horizontal mode, which inserts a paragraph indent unless there's a 
% \comname{noindent} at that point. There is a \comname{noindent} 
% command buried deep inside the code that produces sectional headings, 
% but too late on to help with this.
% 
% Another way of putting a box round a sectional heading gets round the 
% one-line limit of the simple approach above:
%\begin{verbatim}
%   \makeatletter
%   
%   \newcommand{\sectbox}[1]{%
%     \noindent\protect\fbox{%
%       \@tempdima=\hsize
%       \advance\@tempdima by-2\fboxsep
%       \advance\@tempdima by-2\fboxrule
%       \protect\parbox{\@tempdima}{%
%         \smallskip
%         % extra commands here
%         #1\smallskip
%         }}}
%   
%   \makeatother
%   
%   \sectionfont{\sectbox}
%\end{verbatim}
% Again, this doesn't work properly with \comname{chapter} or 
% \comname{part} headings; another limit is that the \comname{sectbox} 
% command must be the last command in the 
% \comname{\itinangle{section}font} command.
% 
% This technique has two significant differences to the first 
% suggestion: firstly, it puts a bit of extra vertical space between the 
% text and the frame, which improves the appearance of the heading; 
% secondly, it places the text of the heading inside a \comname{parbox} 
% that stretches across the full width of the text.  This means that 
% long headings can be broken across lines, and also that the 
% surrounding frame extends across the full width of the text, rather 
% than just enclosing the text of the heading.
% 
% While you can use fount changing commands as usual with the 
% \comname{sectbox} command -- 
% \comname{sectionfont\ttlb\comname{sffamily}\comname{sectbox}\ttrb} 
% will work as expected -- the use of \comname{parbox} means that 
% \comname{raggedright} and similar commands won't work in 
% \comname{\itinangle{section}font} commands. There is a way round this 
% problem: put the appropriate command in the definition of 
% \comname{sectbox} at the place marked \verb|extra commands here|. For 
% example, you could say:
%\begin{verbatim}
%   \makeatletter
%   
%   \newcommand{\sectbox}[1]{%
%   \noindent\protect\fbox{%
%   \@tempdima=\hsize
%   \advance\@tempdima by-2\fboxsep
%   \advance\@tempdima by-2\fboxrule
%   \protect\parbox{\@tempdima}{%
%   \smallskip
%   \raggedright% extra commands here
%   #1 \smallskip
%   }}}
%   
%   \makeatother
%   
%   \sectionfont{\sectbox}
%\end{verbatim}
% and you'd get raggedright headings within the box.  Both 
% \comname{raggedleft} and \comname{centering} also work, although you 
% might like to use \comname{nohang} with \comname{centering}.
% 
% \subsection{Changes to section numbers}
% 
% The two suggestions below don't require \packname{sectsty}; I'm 
% including them because if you're using \packname{sectsty}, you 
% might want to do something like this.
% 
% The suggestions modify the \comname{@seccntformat} command. This is 
% the internal \LaTeX\ command which prints the number part of all 
% sectional headings except chapter and part headings. It's quite in 
% order to change this sort of command: one of the reasons this command 
% exists in the first place is so that people can change it to modify 
% the output they get with \LaTeX.  You can find out more about it 
% by \LaTeX ing \filename{classes.dtx}, part of the standard \LaTeX\ 
% distribution.
% 
% The best place in general for the modifications I suggest in this 
% section is in a class or package file. If you put the modifications 
% there, you won't need the surrounding \comname{makeatletter} and 
% \comname{makeatother} commands.
% 
% If you find yourself wanting to do more stuff along these lines, it 
% might be an idea to look at the \packname{titlesec} package from CTAN.
% 
% \subsubsection{Printing the section number in the left margin}
%
% This is a quick hack I stumbled over by accident one day and I hope 
% someone else finds it useful. I haven't tested it thoroughly, so do be 
% aware that it might produce unwanted effects; I can't see that it will 
% do anything untoward, but I think it's best to be paranoid when 
% dealing with computers.
% 
% Putting this code in the preamble of your document:
%\begin{verbatim}
%   \makeatletter
%   \def\@seccntformat#1{\protect\makebox[0pt][r]{\csname
%                        the#1\endcsname\quad}}
%   \makeatother
%\end{verbatim}
% will typeset the number of each section in the left margin, with the 
% start of each instance of sectional heading text aligned with the left 
% hand edge of the body text. It doesn't affect chapter or part 
% headings. This code won't affect the normal paragraph and subparagraph 
% headings. If you change the normal form of these headings by telling 
% \LaTeX\ to print section numbers with them, paragraph headings will 
% work as you'd expect, but subparagraph headings will have the section 
% number to the left of the normal position although not in the left 
% margin.
% 
% \subsubsection{Putting a full stop (period) after the section number}
% 
% Requests on how to do this appear in \texttt{news://comp.text.tex} 
% quite often.  One solution is:
%\begin{verbatim}
%   \makeatletter
%   \def\@seccntformat#1{\csname the#1\endcsname.\quad}
%   \makeatother
%\end{verbatim}
% This will put a full stop after sectional numbers in sectional headers 
% other than part and chapter headings. It doesn't affect 
% cross-references or table of contents entries.
% 
% An interesting extension to the simple original command allows you to 
% control the style of numbering you get with each level of sectional 
% heading independently:
%\begin{verbatim}
%   \makeatletter
%   \def\@seccntformat#1{\@ifundefined{#1@cntformat}%
%   {\csname the#1\endcsname\quad}%  default
%   {\csname #1@cntformat\endcsname}% individual control
%   }
%   \def\section@cntformat{\thesection.\quad}
%   \def\subsection@cntformat{\thesubsection.\quad}
%   \makeatother
%\end{verbatim}
% this example gives you a full stop after section and subsection 
% headings, and has no effect on other levels.
% 
% \section{Compatibility with other packages}
% 
% The \packname{sectsty} package works by blindly re-defining the 
% various sectioning commands, so any package that requires
% that \LaTeX's sectioning commands are precisely as they are defined 
% in the standard classes will have trouble working with 
% \packname{sectsty}.
% 
% The \packname{fncychap} package, for example, re-defines the code 
% that produces chapter headings.  If you use \packname{fncychap} with 
% \packname{sectsty}, you will have to load \packname{fncychap} after 
% \packname{sectsty}:
%\begin{verbatim}
%    \usepackage{sectsty}
%    \usepackage{fncychap}
%\end{verbatim}
% You'll find that \packname{sectsty} will have no effect on chapter 
% headings when you use it like this.
% 
% Some packages perform interesting tricks to add code to the standard 
% sectioning commands.  These packages might well work quite happily 
% with \packname{sectsty}, but they must be loaded after 
% \packname{sectsty}: because \packname{sectsty} re-defines the 
% sectioning commands, any earlier changes will be thrown away.
% 
% In particular, the \packname{minitoc} package modifies the sectioning 
% commands (rather than just re-defining them like \packname{sectsty} 
% does), but if you say:
%\begin{verbatim}
%   \usepackage{sectsty,minitoc}
%\end{verbatim}
% to load \packname{minitoc} after \packname{sectsty}, everything should 
% work perfectly.
%
% \StopEventually{}
%
% \iffalse
% 2002/02/25 v2.0.2 Changed email address and fiddled with scribbles 
%     round the edges.  No code changes.
% 1999/04/12 v2.0.1 changed licence conditions to lppl.txt; stopping 
%     it typesetting code by default (silly boy).  Released.
% 1999/04/07 v2.0 bit the bullet.  Released
% 1999/04/06 v1.9.7 Added KOMA-script note.  Unreleased.
% 1999/03/08 v1.9.6 Fixed \sectbox definition.  Commented out the 
%     redundant chapfudge defs.  Unreleased.
% 1999/02/07 v1.9.5 Fixed showkeys problem thanks to Bernd Schandl.  
%     More playing with underlining code.  Unreleased.
% 1999/01/22 v1.9.4 Playing with underlining code.  Unreleased.
% 1999/01/20 v1.9.3 Changed \SS@sectlevel to \SSsectlevel so that it 
%     can be used inside documents.  It's 1999, not 1998.  Hunted down 
%     and killed yet another spurious space.  Well, killed it anyway.  
%     God knows where it actually was.  Doc mods.  First bash at 
%     getting \sectionrule to work with the KOMA-script classes.  
%     Unreleased.
% 1999/01/18 v1.9.2 added grouping to \chapter and \part commands.  
%     Why didn't I do this ages ago?  Hunted down and killed a 
%     spurious space.  Added grouping to \minisec too, and made its 
%     underlining stuff same as part and chapter stuff.  Changed 
%     \SE@ to \SS@.  Unreleased.
% 1999/01/15 v1.9.1 added debugging stuff.  Unreleased.
% 1999/01/13 v1.9 added stuff for KOMA-script classes.  Untested,  
%     undocumented, and unreleased.  This will transmogrify into v2.0 
%     when it's ready for release.
% 1999/01/06 v1.8.7 Added warning if sectsty isn't going to do 
%     anything because article, report, or book haven't been loaded.  
%     Released.
% 1999/01/03 v1.8.6 More \fbox doc bits.  Added \ttbs command and 
%     changed \comname definition to use it.  Untested.  Unreleased.
% 1998/12/29 v1.8.5 Added doc note about \fbox.  Unreleased.
% 1998/12/11 v1.8.4 Fixed \nohang bug (how the hell did *that* 
%     happen?).  Some documentation mods.  Released
% 1998/12/10 v1.8.3 Documention mods.  Unreleased
% 1998/12/10 v1.8.2 Documention mods. Released
% 1998/12/09 v1.8.1 Documentation mods and changed syntax of 
%     \sectionrule command.  Modified doc stuff so code comes out in 
%     9pt and codeline numbers in 7pt, as standard.  Unreleased.
% 1998/12/08 v1.8 Major \sectionrule mods - should now work with 
%     raggedleft and chapter/part headings as well.  Documentation 
%     mods.  Unreleased
% 1998/12/06 v1.7.2 Documentation mods.  Unreleased.
% 1998/12/01 v1.7.1 Documentation mods.  Unreleased.
% 1998/11/29 v1.7 Stopped being such a bloody fool and added \nohang.  
%     Added note about rule under chapter and part headings.  
%     Unreleased
% 1998/11/19 v1.6 Probably dealt with centering/underline multiline 
%     problem.  Taken Donald Arseneau's name out of the copyright 
%     notice.  Some doc changes.  Unreleased
% 1998/11/18 v1.5.3 Minor doc changes.  Released?
% 1998/11/16 v1.5.2 Minor doc changes.  Re-positioned \strut in 
%     \SS@ulemsectuline.  Unreleased.
% 1998/11/15 v1.5.1 Added \strut to \SS@ulemsectuline.  Some doc 
%     changes.  Unreleased.
% 1998/11/14 v1.5 Changed \sectionrule command and documented it.  
%     Changed \@svec fix to \let.  Not released.
% 1998/11/12 v1.4.4 added \sectionrule command.  Iffy. No doc changes.  
%     Unreleased.
% 1998/11/11 v1.4.3 Moved the version history; added fix for 
%     underlining *-form heading problem; minor documentation mods; 
%     started to document way of putting a full width rule underneath 
%     a section heading and ran into trouble; unreleased.
% 1998/08/24 v1.4.2 Yet more documentation mods; unreleased
% 1998/08/20 v1.4.1 Documentation mods; unreleased
% 1998/08/05 v1.4 more underlining modifications and finished docs
% 1998/07/15 v1.3 added sectional heading underlining stuff and added 
%      some more documentation.  Unreleased.
% 1998/06/28 v1.2 removed \selectfont commands which are redundant 
%      and stop you using commands that take the sectional heading as 
%      an argument.  This is to allow you to underline sectional 
%      headings, as is often required in theses etc.
% 1998/05/28 v1.1.1 fixed problem with \OnlyDescription and 
%      corrected \CheckSum (kicks self vigorously)
% 1998/05/27 v1.1 Fixed bugs in chapter/part code, corrected a 
%      documentation bug, and added a few more notes (thanks to
%      Bernd Schandl <bschand@math.clemson.edu>).  And removed the 
%      spurious spaces from the other sectional headings (grr).
% 1998/05/26 v1.0 Made into dtx/ins pair for general release
% 1998/05/13 v0.2 Changed more than a little
% 1996/12/08 v0.1 original version
%\fi
%
% \iffalse
% This code is used to switch to the usual fount sizes for 
% typesetting the code; because this document is typeset in 11pt rather 
% than 10pt, the code would normally be typeset in a larger than usual 
% fount leading to lots of overfull \hboxes.  I've bunged it here so 
% the casual reader can see what's going on - it's executed just 
% before the first code is typeset.
%
% Because this document is set in 11pt, need to select a smaller than 
% usual size for \MacroFont to get the macros set in 9pt, and code line 
% numbers set in 7pt.
%
% Yes, I know it's ugly.  It was a bit of a battle to get it to work, 
% and now that it does work, I'm loathe to change anything.
%\fi 
%
% \makeatletter
% \def\macro@font{\fontencoding \encodingdefault \fontfamily \ttdefault 
% \fontseries \mddefault \fontshape \updefault \footnotesize}
% \let\MacroFont\macro@font
% 
% \def\theCodelineNo{\rmfamily%
% \@setfontsize\scriptsize\@viipt\@viiipt%
% \arabic{CodelineNo}}
% \makeatother
%
% 
% \section{The code itself}
% 
%
% Who am I, and what do I need?  This package will probably work with 
% any version of \LaTeXe, but I've only tested it with the June 
% 1998 release and some later ones.
%
%    \begin{macrocode}
\ProvidesPackage{sectsty}[2002/02/25 v2.0.2 Commands to change all 
sectional heading styles]
\NeedsTeXFormat{LaTeX2e}[1998/06/01]
%    \end{macrocode}
% 
% \subsection{Options}
% 
% \subsubsection{Control how much stuff is reported}
% 
% This lot is for my benefit at the moment.  Maybe the full range of 
% values will have some meaning one day.
% 
% \begin{macro}{\SS@ocl}
% \comname{SS@ocl}\comarg{number}\comarg{if okay to blather}\comarg{if 
% not okay to blather}
% 
% (ocl stands for On Chat Level)
% 
% If \comarg{number} (1-4) is greater than the current chat level, then 
% blather away. If not, do the other thing. So use 4 for stuff to be 
% printed all the time, and 1 for other stuff.
% 
%    \begin{macrocode}
\long\def\SS@ocl#1#2#3{\ifnum #1>\SS@chatlevel #2\else #3\fi}
%    \end{macrocode}
% \end{macro} 
%
% \begin{macro}{\SS@oclto}
%
% On Chat Level TypeOut -- used for debugging reports (etc).
% 
%    \begin{macrocode}
\def\SS@oclto#1#2{\SS@ocl{#1}{\typeout{#2}}{}}
%    \end{macrocode}
% \end{macro}
% 
% 
% \begin{macro}{\SS@chatlevel}
% By default, don't make much fuss.
%    \begin{macrocode}
\def\SS@chatlevel{3}
%    \end{macrocode}
% 
% Maybe I'll activate the other options one of these days, but only if 
% the messages are meant for people other than me.
% 
%    \begin{macrocode}
% \DeclareOption{verbose}{\def\SS@chatlevel{1}}% chatty
% \DeclareOption{silent}{\def\SS@chatlevel{3}}%  yorkshire
% 
% \DeclareOption{errorshow}{\def\SSchatlevel{3}}%  yorkshire
% \DeclareOption{warningshow}{\def\SS@chatlevel{2}}%  taciturn
% \DeclareOption{infoshow}{\def\SS@chatlevel{1}}%  chatty
% \DeclareOption{debugshow}{\def\SS@chatlevel{0}}%  garrulous
% 
\DeclareOption{garrulous}{\def\SS@chatlevel{0}}
\DeclareOption{chatty}{\def\SS@chatlevel{1}}
\DeclareOption{taciturn}{\def\SS@chatlevel{2}}
\DeclareOption{yorkshire}{\def\SS@chatlevel{3}}
%    \end{macrocode}
% \end{macro}
% 
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
% 
%
% \subsection{Underlining}
% 
% Stuff for underlining sectional headings.  I didn't write much of 
% this myself.
% 
%\begin{macro}{\@svsec}
% First thing to do\ldots\ Define |\@svsec| to prevent underlining 
% extras throwing a wobbly when you try to underline a |\section*| or 
% similar. |\@svsec| is referred to by the underlining code, but it 
% normally only exists inside the non star form of the commands 
% generating sectional headings.
%    \begin{macrocode}
\let\@svsec\relax
%    \end{macrocode}
%\end{macro}
% 
%\begin{macro}{\nohang}
% A hack: you should get hanging indentation on subsequent lines of all 
% sectional headings, but this isn't always appropriate.  
% \comname{nohang} suppresses the hanging indentation.  If you're using 
% centred or raggedright headings, a bug in \comname{@centercr} means 
% the hanging indentation is suppressed if you end lines with |\\|.
%    \begin{macrocode}
\newcommand{\nohang}{\let\@hangfrom\@empty}
%    \end{macrocode}
%\end{macro}
% 
% And then add some stuff so that:
%\begin{verbatim}
%   \section{Algorithm according to \cite{knuth}}
%\end{verbatim}
% works when using the \packname{showkeys} package.  Problem reported by 
% and solved by Bernd Schandl.
%\begin{macro}{\SS@origunderline}
% start by saving the original definition of \comname{underline}
%    \begin{macrocode}
\let\SS@origunderline\underline
%    \end{macrocode}
%\end{macro}
%
% Then check to ensure that the \comname{underbar} command is as it 
% should be by default.  This matters: \comname{underbar} is defined 
% inside sectional headings to use \comname{orig@underline} rather than 
% \comname{underline}, because \comname{underline} is redefined under 
% such circumstances; this breaks the \comname{underbar} command used 
% by \packname{showkeys}.  If \comname{underbar}'s definition has 
% changed, I need to know about it.
%
%    \begin{macrocode}
\CheckCommand*{\underbar}[1]%
  {\underline{\sbox\tw@{#1}\dp\tw@\z@\box\tw@}}
%    \end{macrocode}
% 
% \subsubsection{Main underlining code}
% The first command is for underlining sectional headings created 
% with |\@startsection|.
% 
%\begin{macro}{\SS@ulemsectuline}
% 
% |\SS@ulemsectuline| is a hack that modifies the behaviour of sections 
% created using the |\@startsection| command. It allows you to underline 
% sectional headings with fewer problems than otherwise. First argument 
% is the \packname{ulem} underlining command; second argument is the 
% section heading text to underline.
%    \begin{macrocode}
\newcommand*{\SS@ulemsectuline}[2]{%
  \ifhmode% run-in head
    \begingroup%
    \def\hskip##1\relax##2\@@par{\endgroup\@@hskip##1\relax#1{##2}}%
  \else% stand alone head
    % \ifx\\\@centercr\let\@hangfrom\@empty\fi% deal with \@hangfrom prob
    \protected@edef\@svsec{\noexpand#1{\@svsec\strut}}% added strut
    \def\interlinepenalty##1##2\@@par{\@@interlinepenalty##1#1{##2}\@@par}%
    \fi%
  #2\@@par}% added strut here then removed it (stupid boy)
\let\@@hskip\hskip
\let\@@interlinepenalty\interlinepenalty
%    \end{macrocode}
%\end{macro}
% 
% \begin{macro}{\SS@chapuline}
% 
% A simple command that underlines everything up to the next |\par|.  
% It's used to underline chapter and part headings.  The |\part| 
% commands need a bit of extra modification for this to work.  This 
% command is now obsolete, because I turned my brain on and added 
% grouping to the chapter and part code, so I don't have to use 
% \comname{par} as an argument delimiter any more.
%    \begin{macrocode}
% \def\SS@chapuline#1\par{\uline{#1}\par}
%    \end{macrocode}
%\end{macro}
%
% \begin{macro}{\SS@underline}
% Save the definition of |\underline| in |\SS@underline| so \LaTeX's 
% normal |\underline| command is available in sectioning commands when 
% |\underline| has been re-defined.  For some reason, the construction
% |\let\SS@underline\underline| didn't work right so I started doing 
% it this way.  This way is now essential, because I need to add 
% |\strut|s to keep the underlines lined up (|\SS@ulemsectuline| 
% underlines the numbers and words of a heading separately, which 
% means the underlining would have a discontinuity unless I forced all 
% both the number and title boxes to have the same depth by adding a 
% |\strut| to each).
% 
% First check the definition of |\underline| in |latex.ltx| 
% hasn't changed; then define |\SS@underline| to be the same with added 
% struts.
%    \begin{macrocode}
\CheckCommand*{\underline}[1]{%
  \relax
  \ifmmode\@@underline{#1}%
  \else $\@@underline{\hbox{#1}}\m@th$\relax\fi}
%
\def\SS@underline#1{%
  \relax
  \ifmmode\@@underline{\strut#1}%
  \else $\@@underline{\hbox{\strut#1}}\m@th$\relax\fi}
%    \end{macrocode}
% \end{macro}
%
%\begin{macro}{\SS@ulemunderlinechapfudge}
%\begin{macro}{\SS@ulemheadingchapfudge}
%\begin{macro}{\SS@normunderlinechapfudge}
% 
% Three remarkable similar commands, written to deal with the problem of 
% underlining the number part of KOMA-script chapter headings.  I'm sure 
% there's a better way of doing it, but this appears to work and my head 
% hurts now.
%
% \comname{SS@ulemheadingchapfudge} is the only one which is still 
% used.  I've not changed the name to anything more sensible out of 
% sheer inertia.
% 
%    \begin{macrocode}
% \def\SS@ulemunderlinechapfudge#1{%
%   \ifSS@komascript%
%     \ifnum\SSsectlevel=1% chapter level
%       \ifx\SS@headingpart\SS@nopartid%
%         \SS@oclto{1}{Koma-script chapter number part}%
%         \let\SS@savechapterformat\chapterformat%
%         \def\chapterformat{\uline{\SS@savechapterformat}}%
%         \def\@tempcmda{#1}%
%       \else%
%         \SS@oclto{1}{Koma-script chapter title part}%
%         \def\@tempcmda{\uline{#1}}%
%       \fi%
%     \else%
%       \SS@oclto{1}{Koma-script not chapter}%
%       \def\@tempcmda{\uline{#1}}%
%     \fi%
%   \else%
%     \SS@oclto{1}{Not Koma-script}%
%     \def\@tempcmda{\uline{#1}}%
%   \fi%
%   \@tempcmda
% }%

\def\SS@ulemheadingchapfudge#1#2{%
  \ifSS@komascript%
    \ifnum\SSsectlevel=1% chapter level
      \ifx\SS@headingpart\SS@nopartid%
        \SS@oclto{1}{Koma-script chapter number part}%
        \let\SS@savechapterformat\chapterformat%
        \def\chapterformat{#1{\SS@savechapterformat}}%
        \def\@tempcmda{#2}%
      \else%
        \SS@oclto{1}{Koma-script chapter title part}%
        \def\@tempcmda{#1{#2}}%
      \fi%
    \else%
      \SS@oclto{1}{Koma-script not chapter}%
      \def\@tempcmda{#1{#2}}%
    \fi%
  \else%
    \SS@oclto{1}{Not Koma-script}%
    \def\@tempcmda{#1{#2}}%
  \fi%
  \@tempcmda
}%

% \def\SS@normunderlinechapfudge#1{%
%   \ifSS@komascript%
%     \ifnum\SSsectlevel=1% chapter level
%       \ifx\SS@headingpart\SS@nopartid%
%         \SS@oclto{1}{Koma-script chapter number part}%
%         \let\SS@savechapterformat\chapterformat%
%         \def\chapterformat{\SS@underline{\SS@savechapterformat}}%
%         \def\@tempcmda{#1}%
%       \else%
%         \SS@oclto{1}{Koma-script chapter title part}%
%         \def\@tempcmda{\SS@underline{#1}}%
%       \fi%
%     \else%
%       \SS@oclto{1}{Koma-script not chapter}%
%       \def\@tempcmda{\SS@underline{#1}}%
%     \fi%
%   \else%
%     \SS@oclto{1}{Not Koma-script}%
%     \def\@tempcmda{\SS@underline{#1}}%
%   \fi%
%   \@tempcmda
% }%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%\begin{macro}{\underline}
%\begin{macro}{\ulemheading}
% Two commands:
%  |\underline{text}|
%                        used for normal underlining in all headings
%  |\ulemheading{ulem underline command}{text}|
%                        used for fancy underlining in all headings
%  
% Basic idea:
%
% \comname{SS@makeulinesect} defines \comname{underline} and 
%                                    \comname{ulemheading} 
% appropriately for |\@startsection| headings.
% 
% |\SS@makeulinechap| defines |\underline| and |\ulemheading| appropriately 
% for chapter and modified part headings.
%
%    \begin{macrocode}
\AtBeginDocument{%
  \@ifundefined{UL@box}%
    {% if ulem has not been loaded
    \SS@oclto{1}{ulem not loaded; underlining setup}%
    \def\SS@makeulinesect{%
% \def\underline##1{\noindent\SS@underline{##1}}%
    \def\underbar##1{\SS@origunderline{\sbox\tw@{##1}\dp\tw@\z@\box\tw@}}%
    \def\underline{\SS@ulemsectuline{\SS@underline}}%
    \def\ulemheading##1{\SS@ulemsectuline{\SS@underline}}}%
%
    \def\SS@makeulinepartchap{%
%     \def\underline##1\par{\SS@underline{##1}\par}
%     \def\ulemheading##1##2\par{\SS@underline{##2}\par}}%
%     \def\underline##1{\SS@underline{##1}}% pre KOMA-script
%     \def\ulemheading##1##2{\SS@underline{##2}}}% pre KOMA-script
    \def\underbar##1{\SS@origunderline{\sbox\tw@{##1}\dp\tw@\z@\box\tw@}}%
%     \let\underline\SS@normunderlinechapfudge% 7/2/99
    \def\underline##1{\SS@ulemheadingchapfudge{\SS@underline}{##1}}%
%     \def\ulemheading##1##2{\SS@normunderlinechapfudge{##2}}% 7/2/99
    \def\ulemheading##1##2{\SS@ulemheadingchapfudge{\SS@underline}{##2}}}%
%
%   \def\SS@makeulinepart{%
%   \def\underline##1\par{\SS@underline{##1}\par}
%   \def\ulemheading##1##2\par{\SS@underline{##2}\par}}%
    }% endif ulem has not been loaded
%
    {% If ulem has been loaded
    \SS@oclto{1}{ulem loaded; underlining setup}%
    \def\SS@makeulinesect{%
    \def\underbar##1{\SS@origunderline{\sbox\tw@{##1}\dp\tw@\z@\box\tw@}}%
    \def\underline{\SS@ulemsectuline{\uline}}%
    \def\ulemheading##1##2{\SS@ulemsectuline{##1}{##2}}}%
%
    \def\SS@makeulinepartchap{%
%     \let\underline\SS@chapuline
%     \def\ulemheading##1##2\par{##1{##2}\par}}%
%     \let\underline\uline% pre KOMA-script
%     \def\ulemheading##1##2{##1{##2}}}% pre KOMA-script
    \def\underbar##1{\SS@origunderline{\sbox\tw@{##1}\dp\tw@\z@\box\tw@}}%
%     \let\underline\SS@ulemunderlinechapfudge% 7/2/99
    \def\underline##1{\SS@ulemheadingchapfudge{\uline}{##1}}%
    \let\ulemheading\SS@ulemheadingchapfudge}
    }% endif ulem has been loaded
}% end \AtBeginDocument
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\SS@rr}
% Stolen from \filename{latex.ltx}; this command is used to remove the 
% \comname{leftskip} and \comname{parindent} changes from the definition 
% of \comname{raggedright} in \comname{@start\-section} headings so run-in 
% headings can be indented as specified when you say 
% \comname{raggedright}.
%    \begin{macrocode}
\def\SS@rr{\def\raggedright{%
  \let\\\@centercr\@rightskip\@flushglue \rightskip\@rightskip}}
%   \leftskip\z@skip% part of the original def
%   \parindent\z@}% part of the original def
%    \end{macrocode}
%\end{macro}
% 
% \subsection{Stuff for putting rules around headings}
% 
% Start out with some supporting commands\ldots
%
%\begin{macro}{\ifSS@komascript}
% 
% I can think of several reasons to know if one of the KOMA-Script 
% classes has been loaded, so let's have a new if for the job. This was 
% written for the \comname{sectionrule} command, which needs to know one 
% way or another, and since \comname{@ifclassloaded} can't be used 
% outside the preamble, this seemed like a sensible solution. The 
% alternative involved hideous contortions or horrible inefficiency as 
% far as I could tell.
% 
%    \begin{macrocode}
\newif\ifSS@komascript
\SS@komascriptfalse
\@ifclassloaded{scrartcl}{\SS@komascripttrue}{}
\@ifclassloaded{scrreprt}{\SS@komascripttrue}{}
\@ifclassloaded{scrbook} {\SS@komascripttrue}{}
%    \end{macrocode}
%\end{macro}

%\begin{macro}{\SS@sectid}
% A command to allow detection of the current section level.  0=part, 
% 1=chapter, 2=section, and so on.
%    \begin{macrocode}
\newcommand{\SS@sectid}[1]{\gdef\SSsectlevel{#1}}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\SS@nopart}
%\begin{macro}{\SS@titlepart}
%\begin{macro}{\SSnopartid}
%\begin{macro}{\SStitlepartid}
%\begin{macro}{\SSifnumberpart}
%\begin{macro}{\SSiftitlepart}
% A set of commands to allow detection of what part of a chapter or 
% part heading is being typeset (the number part or the title part). 
% This is quite important for bunging rules around the Koma-script 
% chapter headings, if nothing else.
%
%    \begin{macrocode}
\newcommand{\SS@nopart}{\global\let\SS@headingpart\SS@nopartid}
\newcommand{\SS@titlepart}{\global\let\SS@headingpart\SS@titlepartid}
% 
\newcommand{\SS@nopartid}{number part}
\newcommand{\SS@titlepartid}{title part}
% 
\newcommand{\SSifnumberpart}{%
  \ifx\SS@headingpart\SS@nopartid
      \expandafter\@firstoftwo
    \else
      \expandafter\@secondoftwo
  \fi}
% 
\newcommand{\SSiftitlepart}{%
  \ifx\SS@headingpart\SS@titlepartid
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
% 
%\begin{macro}{\ifraggedleft}
% With a bit of luck, the following command detects if \LaTeX\ is 
% currently doing raggedleft typesetting -- this test is used by the 
% rule commands below. The tests are based on this stuff from 
% |latex.ltx|:
%\begin{verbatim}
% \def\centering{%
%   \let\\\@centercr
%   \rightskip\@flushglue\leftskip\@flushglue
%   \parindent\z@\parfillskip\z@skip}
% \def\raggedright{%
%   \let\\\@centercr\@rightskip\@flushglue \rightskip\@rightskip
%   \leftskip\z@skip
%   \parindent\z@}
% \def\raggedleft{%
%   \let\\\@centercr
%   \rightskip\z@skip\leftskip\@flushglue
%   \parindent\z@\parfillskip\z@skip}
%\end{verbatim}
% 
% If raggedleft is `on', the first argument is executed.  If it's 
% off, the second argument is executed.  This isn't the most elegant 
% code possible, but it does have the virtue that I understand it.
%    \begin{macrocode}
\def\ifraggedleft#1#2{%
  \edef\@tempcmda{\the\rightskip}%
  \edef\@tempcmdb{\the\z@skip}%
  \ifx\@tempcmda\@tempcmdb\@tempswatrue\else\@tempswafalse\fi
  \edef\@tempcmda{\the\leftskip}%
  \edef\@tempcmdb{\the\@flushglue}%
  \if@tempswa
    \ifx\@tempcmda\@tempcmdb\@tempswatrue\else\@tempswafalse\fi
    \fi
  \if@tempswa#1\else#2\fi}
%    \end{macrocode}
%\end{macro}
% \begin{macro}{\ifcentering}
% 
% A similar command to detect if centering is `on'; again, first 
% argument is executed if centering is on, second argument is executed 
% if it's not. This isn't the most elegant code possible, but it does 
% have the virtue that I understand it.
% 
%    \begin{macrocode}
% \def\ifcentering#1#2{%
%   \edef\@tempcmda{\the\rightskip}%
%   \edef\@tempcmdb{\the\@flushglue}%
%   \ifx\@tempcmda\@tempcmdb\@tempswatrue\else\@tempswafalse\fi
%   \edef\@tempcmda{\the\leftskip}%
%   \edef\@tempcmdb{\the\@flushglue}%
%   \if@tempswa
%     \ifx\@tempcmda\@tempcmdb\@tempswatrue\else\@tempswafalse\fi
%     \fi
%   \if@tempswa#1\else#2\fi}
\def\ifcentering{%
  \edef\@tempcmda{\the\rightskip}%
  \edef\@tempcmdb{\the\@flushglue}%
  \ifx\@tempcmda\@tempcmdb\@tempswatrue\else\@tempswafalse\fi
  \edef\@tempcmda{\the\leftskip}%
  \edef\@tempcmdb{\the\@flushglue}%
  \if@tempswa
    \ifx\@tempcmda\@tempcmdb\@tempswatrue\else\@tempswafalse\fi
    \fi
  \if@tempswa\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
%    \end{macrocode}
%\end{macro}
% 
% \subsubsection{The main heading rule code}
% 
%\begin{macro}{\sectionrule}
% A rather dodgy command that will stick a rule across the full width of 
% the text, around a sectional heading, unless it's a run-in heading or 
% centred. Must be used as the last command in a |\...font| command;
%\begin{verbatim}
% \sectionrule{<top rule raise height>}   {<top rule height>}
%             {<bottom rule raise height>}{<bottom rule height>}.
%\end{verbatim}
% 
%    \begin{macrocode}
\newcommand{\sectionrule}[5]{%
  \ifcentering{%
    \PackageError{sectsty}%
    {Can't use \protect\sectionrule\space with \protect\centering}%
    {The \protect\sectionrule\space command doesn't work properly
    with sectional headings that\MessageBreak are centred, so I'll
    carry on as if you'd not used the \protect\sectionrule\space 
    command.}#5}%
    {\ifSS@komascript
      \ifnum\SSsectlevel>1
%       use normal sectionrule if Koma-script and not part/chapter
        \SS@oclto{1}{KOMA-script; normal section rule}%
        \SS@sectionrule{#1}{#2}{#3}{#4}{#5}%
      \else
%       use strange sectionrule if Koma-script and part/chapter
        \SS@oclto{1}{KOMA-script; part/chap section rule}%
        \SS@komapartchaprule{#1}{#2}{#3}{#4}{#5}%
      \fi
    \else
%     use normal sectionrule if not Koma-script
      \SS@oclto{1}{No KOMA-script; normal section rule}%
        \SS@sectionrule{#1}{#2}{#3}{#4}{#5}%
    \fi}}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\SS@sectionrule}
%
% This gets called by |\sectionrule| unless in a part or chapter 
% heading, and picks one of two commands to place the rules depending on 
% whether the heading's raggedleft or not.
%
%    \begin{macrocode}
\def\SS@sectionrule#1#2#3#4#5{%
  \ifraggedleft
    {\SS@rlsectionrule{#1}{#2}{#3}{#4}{#5}}%
    {\SS@normsectionrule{#1}{#2}{#3}{#4}{#5}}}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\SS@normsectionrule}
%\begin{macro}{\SS@rlsectionrule}
% These are the commands that do the dirty work for 
% \comname{SS@sectionrule} and actually place the rules around the 
% headings. \comname{SS@normsectionrule} does for raggedright and fully 
% justified headings; \comname{SS@rlsectionrule} does for raggedleft 
% headings.
%    \begin{macrocode}
\def\SS@normsectionrule#1#2#3#4#5{%
  \let\SS@@par\@@par\let\@@par\relax% very dodgy
  \noindent\makebox[0pt][l]{\rule[#1]{\hsize}{#2}}%
    #5\hfill\makebox[0pt][r]{\rule[#3]{\hsize}{#4}}%
  \let\@@par\SS@@par\@@par}
% 
\def\SS@rlsectionrule#1#2#3#4#5{%
  \let\SS@@par\@@par\let\@@par\relax% very dodgy
  \noindent\makebox[0pt][l]{\rule[#1]{\hsize}{#2}}\hfill%
    #5\makebox[0pt][r]{\rule[#3]{\hsize}{#4}}%
  \let\@@par\SS@@par\@@par}
%    \end{macrocode}
%\end{macro}
%\end{macro}
% 
%\begin{macro}{\ifSS@starform}
%\begin{macro}{\secdef}
%
% Some code to help the rule drawing commands find out if the star form 
% of a chapter or part heading is being typeset. This information is 
% needed to get rules around chapters right in scrreprt and scrartcl.
%
%    \begin{macrocode}
\newif\ifSS@starform
% 
\def\secdef#1#2{\@ifstar{\SS@starformtrue#2}{\SS@starformfalse\@dblarg{#1}}}
%    \end{macrocode}
%\end{macro}
%\end{macro}
% 
%\begin{macro}{\SS@komapartchaprule}
% 
% Some more commands for shoving rules around headings. They work just 
% like \comname{SS@sectionrule} and friends, but for part and chapter 
% headings
% 
%    \begin{macrocode}
% \def\SS@partchaprule#1#2#3#4#5{%
% \ifraggedleft{\SS@rlpartchaprule{#1}{#2}{#3}{#4}{#5}}%
% {\SS@normpartchaprule{#1}{#2}{#3}{#4}{#5}}}
\def\SS@komapartchaprule#1#2#3#4#5{%
  \ifraggedleft
    {\SS@rlkomapartchaprule{#1}{#2}{#3}{#4}{#5}}%
    {\SS@normkomapartchaprule{#1}{#2}{#3}{#4}{#5}}%
}
%    \end{macrocode}
%\end{macro}
% 
%\begin{macro}{\SS@normkomapartchaprule}
%\begin{macro}{\SS@komapartchaprule}
% 
% Called by \comname{SS@komapartchaprule}: these are the commands that 
% do the dirty work of placing the rules around the headings. 
% \comname{SS@normkomapartchaprule} does for raggedright and fully 
% justified headings; \comname{SS@rlkomapartchaprule} does for 
% raggedleft headings.
% 
%    \begin{macrocode}
% \def\SS@normpartchaprule#1#2#3#4#5\par{%
% \noindent\makebox[0pt][l]{\rule[#1]{\hsize}{#2}}%
% #5%
% \hfill\makebox[0pt][r]{\rule[#3]{\hsize}{#4}}%
% \par}
\def\SS@normkomapartchaprule#1#2#3#4#5{%
  \SS@oclto{1}{SS@normkomapartchaprule}%
  \ifSS@starform
    \SS@normsectionrule{#1}{#2}{#3}{#4}{#5}%
  \else
    \SSifnumberpart
  	  {\noindent\makebox[0pt][l]{\rule[#1]{\hsize}{#2}}#5}%
  	  {#5\hfill\makebox[0pt][r]{\rule[#3]{\hsize}{#4}}}%
  \fi
}
%    \end{macrocode}
% 
%    \begin{macrocode}
% \def\SS@rlpartchaprule#1#2#3#4#5\par{%
% \noindent\makebox[0pt][l]{\rule[#1]{\hsize}{#2}}\hfill%
% #5%
% \makebox[0pt][r]{\rule[#3]{\hsize}{#4}}%
% \par}
\def\SS@rlkomapartchaprule#1#2#3#4#5{%
  \SS@oclto{1}{SS@rlkomapartchaprule}%
  \ifSS@starform
    \SS@rlsectionrule{#1}{#2}{#3}{#4}{#5}%
  \else
    \SSifnumberpart
      {\noindent\makebox[0pt][l]{\rule[#1]{\hsize}{#2}}\hfill#5}%
      {#5\makebox[0pt][r]{\rule[#3]{\hsize}{#4}}}%
  \fi
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
% 
% \subsection{The new author commands}
%
% The extra commands are below.  Note that the |\SSsectlevel| is 
% defined to be 0 in part headings, 1 in chapter headings, 2 in section 
% headings, and so on.  You might find this useful if you want to play 
% interesting games. \comname{minisec} is a KOMA-script sectioning 
% command which is one level lower than \comname{subparagraph}.
%
%    \begin{macrocode}
\newcommand*{\partfont}          [1]
   {\gdef\SS@partnumberfont{\SS@sectid{0}\SS@nopart\SS@makeulinepartchap#1}
    \gdef\SS@parttitlefont{\SS@sectid{0}\SS@titlepart\SS@makeulinepartchap#1}}
\newcommand*{\partnumberfont}    [1]
   {\gdef\SS@partnumberfont{\SS@sectid{0}\SS@nopart\SS@makeulinepartchap#1}}
\newcommand*{\parttitlefont}     [1]
   {\gdef\SS@parttitlefont{\SS@sectid{0}\SS@titlepart\SS@makeulinepartchap#1}}
\newcommand*{\chapterfont}       [1]
   {\gdef\SS@chapnumfont{\SS@sectid{1}\SS@nopart\SS@makeulinepartchap#1}
    \gdef\SS@chaptitlefont{\SS@sectid{1}\SS@titlepart\SS@makeulinepartchap#1}}
\newcommand*{\chapternumberfont} [1]
   {\gdef\SS@chapnumfont{\SS@sectid{1}\SS@nopart\SS@makeulinepartchap#1}}
\newcommand*{\chaptertitlefont}  [1]
   {\gdef\SS@chaptitlefont{\SS@sectid{1}\SS@titlepart\SS@makeulinepartchap#1}}
\newcommand*{\sectionfont}       [1]
   {\gdef\SS@sectfont{\SS@sectid{2}\SS@rr\SS@makeulinesect#1}}
\newcommand*{\subsectionfont}    [1]
   {\gdef\SS@subsectfont{\SS@sectid{3}\SS@rr\SS@makeulinesect#1}}
\newcommand*{\subsubsectionfont} [1]
   {\gdef\SS@subsubsectfont{\SS@sectid{4}\SS@rr\SS@makeulinesect#1}}
\newcommand*{\paragraphfont}     [1]
   {\gdef\SS@parafont{\SS@sectid{5}\SS@rr\SS@makeulinesect#1}}
\newcommand*{\subparagraphfont}  [1]
   {\gdef\SS@subparafont{\SS@sectid{6}\SS@rr\SS@makeulinesect#1}}
\newcommand*{\minisecfont}  [1]
   {\gdef\SS@minisecfont{\SS@sectid{7}\SS@rr\SS@makeulinepartchap#1}}
% 
\newcommand*{\allsectionsfont}   [1] {\partfont{#1}
                                      \chapterfont{#1}
                                      \sectionfont{#1}
                                      \subsectionfont{#1}
                                      \subsubsectionfont{#1}
                                      \paragraphfont{#1}
                                      \subparagraphfont{#1}
                                      \minisecfont{#1}}
% 
\allsectionsfont{\relax}
%    \end{macrocode}
% 
% \subsection{The re-defined sectioning commands}
%
% For obscure reasons, this is where I test to see if 
% \packname{sectsty} is being used with a class it'll work with. This 
% test isn't infallible, but it does let you know if \packname{sectsty} 
% will do nothing at all.
%
%    \begin{macrocode}
\@tempswafalse
%
\@ifclassloaded{article} {\@tempswatrue\SS@oclto{1}{article detected}} {}
\@ifclassloaded{report}  {\@tempswatrue\SS@oclto{1}{report  detected}} {}
\@ifclassloaded{book}    {\@tempswatrue\SS@oclto{1}{book    detected}} {}
\@ifclassloaded{letter}  {}                                            {}
\@ifclassloaded{slides}  {}                                            {}
%
\@ifclassloaded{scrartcl}{\@tempswatrue\SS@oclto{1}{scrartcl detected}} {}
\@ifclassloaded{scrreprt}{\@tempswatrue\SS@oclto{1}{scrreprt detected}} {}
\@ifclassloaded{scrbook} {\@tempswatrue\SS@oclto{1}{scrbook  detected}} {}
% \@ifclassloaded{handout} {} {}

\if@tempswa\else
    \PackageError{sectsty}%
    {The sectsty package doesn't work with\MessageBreak
    this document class}%
    {The sectsty package only works with the following classes:
    \MessageBreak
    the standard LaTeX document classes\MessageBreak
    article, report, and book; and\MessageBreak
    the KOMA-Script classes\MessageBreak
    scrartcl, scrbook, and scrreprt.}
\fi
%    \end{macrocode}
%
% \subsubsection{Section code for article, book, and report classes}
%
%    \begin{macrocode}
\@tempswafalse
%
\@ifclassloaded{article} {\@tempswatrue\SS@oclto{1}{article detected}} {}
\@ifclassloaded{report}  {\@tempswatrue\SS@oclto{1}{report  detected}} {}
\@ifclassloaded{book}    {\@tempswatrue\SS@oclto{1}{book    detected}} {}
\@ifclassloaded{letter}  {}              {}
\@ifclassloaded{slides}  {}              {}
%
\@ifclassloaded{scrartcl}{} {}
\@ifclassloaded{scrreprt}{} {}
\@ifclassloaded{scrbook} {} {}
% \@ifclassloaded{handout} {} {}
%    \end{macrocode}
%
% Code from |article.cls| and |report.cls| June 1996; same as book code.  
% Execute this only if the book, report, or article classes have been 
% loaded.
%    \begin{macrocode}
\if@tempswa
\SS@oclto{1}{section->subparagraph modifications for article, report, 
and book classes}%
\renewcommand\section{\@startsection {section}{1}{\z@}%
      {-3.5ex \@plus -1ex \@minus -.2ex}%
      {2.3ex \@plus.2ex}%
%     {\normalfont\Large\bfseries}}
      {\normalfont\Large\bfseries\SS@sectfont}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
      {-3.25ex\@plus -1ex \@minus -.2ex}%
      {1.5ex \@plus .2ex}%
%     {\normalfont\large\bfseries}}
      {\normalfont\large\bfseries\SS@subsectfont}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
      {-3.25ex\@plus -1ex \@minus -.2ex}%
      {1.5ex \@plus .2ex}%
%     {\normalfont\normalsize\bfseries}}
      {\normalfont\normalsize\bfseries\SS@subsubsectfont}}
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
      {3.25ex \@plus1ex \@minus.2ex}%
      {-1em}%
%     {\normalfont\normalsize\bfseries}}
      {\normalfont\normalsize\bfseries\SS@parafont}}
\renewcommand\subparagraph{\@startsection{subparagraph}{5}{\parindent}%
      {3.25ex \@plus1ex \@minus .2ex}%
      {-1em}%
%     {\normalfont\normalsize\bfseries}}
      {\normalfont\normalsize\bfseries\SS@subparafont}}
\fi
%    \end{macrocode}
%
% End re-defining section|->|subparagraph commands for article, 
% report, and book classes
%
% \subsubsection{Section code for scrartcl, scrbook, and scrreprt classes}
%
%    \begin{macrocode}
\@tempswafalse
%
\@ifclassloaded{article} {} {}
\@ifclassloaded{report}  {} {}
\@ifclassloaded{book}    {} {}
\@ifclassloaded{letter}  {}              {}
\@ifclassloaded{slides}  {}              {}
%
\@ifclassloaded{scrartcl}{\@tempswatrue\SS@oclto{1}{scrartcl detected}} {}
\@ifclassloaded{scrreprt}{\@tempswatrue\SS@oclto{1}{scrreprt detected}} {}
\@ifclassloaded{scrbook} {\@tempswatrue\SS@oclto{1}{scrbook  detected}} {}
% \@ifclassloaded{handout} {} {}
%    \end{macrocode}
% 
% Code from |scrclass.dtx| 1998/07/17 v2.5e. Execute this only if the 
% scrartcl, scrreprt, or scrbook classes have been loaded.
%
%    \begin{macrocode}
\if@tempswa
\SS@oclto{1}{section->minisec modifications for scrartcl, scrreprt, 
and scrbook classes}%
\renewcommand\section{\@startsection{section}{1}{\z@}%
  {-3.5ex \@plus -1ex \@minus -.2ex}%
  {2.3ex \@plus.2ex}%
  {\raggedsection\normalfont\size@section\sectfont\SS@sectfont}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
  {-3.25ex\@plus -1ex \@minus -.2ex}%
  {1.5ex \@plus .2ex}%
  {\raggedsection\normalfont\size@subsection\sectfont\SS@subsectfont}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
  {-3.25ex\@plus -1ex \@minus -.2ex}%
  {1.5ex \@plus .2ex}%
  {\raggedsection\normalfont\size@subsubsection\sectfont\SS@subsubsectfont}}
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
  {3.25ex \@plus1ex \@minus.2ex}%
  {-1em}%
  {\raggedsection\normalfont\size@paragraph\sectfont\SS@parafont}}
\renewcommand\subparagraph{\@startsection{subparagraph}{5}{\parindent}%
  {3.25ex \@plus1ex \@minus .2ex}%
  {-1em}%
  {\raggedsection\normalfont\size@subparagraph\sectfont\SS@subparafont}}
\renewcommand\minisec[1]{\@afterindentfalse \vskip 1.5ex
  {\parindent \z@ \raggedsection\sectfont\SS@minisecfont {#1}\par\nobreak}%
  \@afterheading}%
  \fi
%    \end{macrocode}
%
% \subsection{Re-defined chapter code}
%
% \subsubsection{Chapter command for report class}
%
%% Code from |report.cls| June 1996
%    \begin{macrocode}
\@ifclassloaded{report}{%
\SS@oclto{1}{chapter modifications for report class}%
\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
        \huge\bfseries\SS@chapnumfont{\@chapapp\space \thechapter}%
        \par\nobreak
        \vskip 20\p@
    \fi
    \interlinepenalty\@M
    \raggedright \normalfont
    \Huge \bfseries \SS@chaptitlefont {#1}\par\nobreak
    \vskip 40\p@
  }}
\def\@makeschapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright
    \normalfont
    \interlinepenalty\@M
    \Huge \bfseries \SS@chaptitlefont {#1}\par\nobreak
    \vskip 40\p@
  }}%
}{}
%    \end{macrocode}
%
%% End code re-defining chapter stuff for report class
%
% \subsubsection{Chapter command for book class}
%
%% Chapter code from |book.cls| 1997/10/10 v1.3x
%
%    \begin{macrocode}
\@ifclassloaded{book}{%
\SS@oclto{1}{chapter modifications for book class}%
\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \huge\bfseries\SS@chapnumfont {\@chapapp\space \thechapter}%
        \par\nobreak
        \vskip 20\p@
      \fi
    \fi
    \interlinepenalty\@M
    \raggedright \normalfont
    \Huge \bfseries \SS@chaptitlefont {#1}\par\nobreak
    \vskip 40\p@
  }}
\def\@makeschapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright
    \normalfont
    \interlinepenalty\@M
    \Huge \bfseries \SS@chaptitlefont  {#1}\par\nobreak
    \vskip 40\p@
  }}%
}{}
%    \end{macrocode}
%
%% End code redefining chapter stuff from book.cls
% 
% \subsubsection{Chapter command for scrreprt class}
% 
% Code from \filename{scrreprt.cls} 1998/07/17 v2.5e.
% 
%% Begin code redefining chapter stuff from scrreprt.cls
%
%    \begin{macrocode}
\@ifclassloaded{scrreprt}{%
\SS@oclto{1}{chapter modifications for scrreprt class}%
\def\@makechapterhead#1{\chapterheadstartvskip%
  {\size@chapter{\sectfont\SS@chapnumfont
    \@hangfrom{\ifnum \c@secnumdepth >\m@ne%
               \chapterformat\fi}%
      {\raggedsection \interlinepenalty \@M \SS@chaptitlefont {#1}\par}}%
    \nobreak\chapterheadendvskip
  }}
\def\@makeschapterhead#1{\chapterheadstartvskip%
  {\parindent \z@ \raggedsection
    \normalfont
    \size@chapter\sectfont\SS@chaptitlefont {#1}\par
    \nobreak\chapterheadendvskip
  }}
}{}
%    \end{macrocode}
% 
%% End code redefining chapter stuff from scrreprt.cls
% 
% \subsubsection{Chapter command for scrbook class}
% 
% Code from \filename{scrbook.cls} 1998/07/17 v2.5e.
% 
%% Begin code redefining chapter stuff from scrbook.cls
%
%    \begin{macrocode}
\@ifclassloaded{scrbook}{%
\SS@oclto{1}{chapter modifications for scrbook class}%
\def\@makechapterhead#1{\chapterheadstartvskip%
  {\size@chapter{\sectfont\SS@chapnumfont
    \@hangfrom{\ifnum \c@secnumdepth >\m@ne%
                 \if@mainmatter \chapterformat\fi\fi}%
       {\raggedsection \interlinepenalty \@M \SS@chaptitlefont {#1}\par}}%
    \nobreak\chapterheadendvskip
  }}
\def\@makeschapterhead#1{\chapterheadstartvskip%
  {\parindent \z@ \raggedsection
    \normalfont
    \size@chapter\sectfont\SS@chaptitlefont {#1}\par
    \nobreak\chapterheadendvskip
  }}%
  }{}
  %    \end{macrocode}
% 
%% End code redefining chapter stuff from scrbook.cls
% 
% \subsection{Re-defined part code}
%
% \subsubsection{Part command for book class}
%
%% Part code from book.cls 1997/10/10 v1.3x
%\begin{macro}{\part}
%
% This code adds the |\SS@...font| hooks; there used to be some other 
% additions but there aren't any more because they were silly.
%
% \begin{macrocode}
\@ifclassloaded{book}{%
\SS@oclto{1}{part modifications for book class}%
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{}{}%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\bfseries\SS@partnumberfont {\partname~\thepart}%
       \par
       \vskip 20\p@
     \fi
     \centering \normalfont
     \Huge \bfseries \SS@parttitlefont {#2}\par}%
    \@endpart}
\def\@spart#1{%
    {\centering
     \interlinepenalty \@M
     \normalfont \Huge \bfseries \SS@parttitlefont {#1}\par}%
    \@endpart}
}{}
%    \end{macrocode}
%
%% End code redefining part stuff from |book.cls|
%
% \subsubsection{Part command for article class}
%
%% Part code from |article.cls| 1997/10/10 v1.3x
%
%    \begin{macrocode}
\@ifclassloaded{article}{%
\SS@oclto{1}{part modifications for article class}%
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >\m@ne
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    {\parindent \z@ \raggedright
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >\m@ne
       \Large\bfseries\SS@partnumberfont {\partname~\thepart}%
       \par\nobreak
     \fi
     \raggedright \normalfont
     \huge \bfseries \SS@parttitlefont {#2}%
     \markboth{}{}\par}%
    \nobreak
    \vskip 3ex
    \@afterheading}
\def\@spart#1{%
    {\parindent \z@ \raggedright
     \interlinepenalty \@M
     \normalfont
     \huge \bfseries \SS@parttitlefont {#1}\par}%
     \nobreak
     \vskip 3ex
     \@afterheading}
}{}
%    \end{macrocode}
%
%% End code redefining part stuff from |article.cls|
%
% \subsubsection{Part command for report class}
%
%% Part code from |report.cls| 1997/10/10 v1.3x
%
%    \begin{macrocode}
\@ifclassloaded{report}{%
\SS@oclto{1}{part modifications for report class}%
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{}{}%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\bfseries\SS@partnumberfont {\partname~\thepart}%
       \par
       \vskip 20\p@
     \fi
     \centering \normalfont
     \Huge \bfseries \SS@parttitlefont {#2}\par}%
    \@endpart}
\def\@spart#1{%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \Huge \bfseries \SS@parttitlefont {#1}\par}%
    \@endpart}
}{}
%    \end{macrocode}
%
%% End code redefining part stuff from report.cls
%
% \subsubsection{Part command for scrbook and scrreprt classes}
%    \begin{macrocode}
\@tempswafalse
%
\@ifclassloaded{scrreprt}{\@tempswatrue}{}
\@ifclassloaded{scrbook} {\@tempswatrue}{}
%
%% Part code from |scrbook.cls| 1998/07/17 v2.5e
\if@tempswa%
\SS@oclto{1}{part modifications for scrreprt and scrbook classes}%
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}\@maybeasf%
      \addcontentsline{toc}{part}{\protect\numberline{\thepart}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \chaptermark{}
    {\centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \size@partnumber\sectfont\SS@partnumberfont\partformat
       \par
       \vskip 20\p@
     \fi
     \size@part\sectfont\SS@parttitlefont {#2}\par}%
    \@endpart}
\def\@spart#1{%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \size@part\sectfont\SS@parttitlefont {#1}\chaptermark{}\par}%
    \@endpart}%
    \fi
%    \end{macrocode}
%% End part code from |scrbook.cls| 1998/07/17 v2.5e
%
% \subsubsection{Part command for the scrartcl classes}
%
%% Part code from |scrartcl.cls| 1998/07/17 v2.5e
%    \begin{macrocode}
\@ifclassloaded{scrartcl}{%
\SS@oclto{1}{part modifications for scrartcl classes}%
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >\m@ne
      \refstepcounter{part}\@maybeasf%
       \addcontentsline{toc}{part}{\protect\numberline{\thepart}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    {\parindent \z@ \raggedright
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >\m@ne
       \size@partnumber\sectfont\SS@partnumberfont\partformat
       \par\nobreak
     \fi
     \size@part\sectfont\SS@parttitlefont {#2}%
     \sectionmark{}\par}%
     \nobreak
     \vskip 3ex
    \@afterheading}
\def\@spart#1{%
    {\parindent \z@ \raggedright
     \interlinepenalty \@M
     \normalfont
     \size@part\sectfont\SS@parttitlefont {#1}\sectionmark{}\par}%
     \nobreak
     \vskip 3ex
    \@afterheading}%
    }{}
%    \end{macrocode}
% 
%\end{macro}
% The end
%    \begin{macrocode}
\endinput
%    \end{macrocode}
%
% \Finale
%\iffalse
%<*package>
%% 
%% End of file `sectsty.dtx'.
%% \fi
