% swrule.sty
% Written by Tobias G. Dussa <tdussa@sdhs.de>
% 09oct01
% Copyright (C) by Tobias G. Dussa <tdussa@sdhs.de>
%
% Provides two macros to create english lines a.k.a. swelled rules (i.e.
% lines % that become thicker towards the middle, much like a very
% far-stretched diamond) that only use plain tex means.
%
% The macros provided are
% - \swrule{length}{maximum width}
% - \swrulex{length}{minimum width}{maximum width}
%
% The \swrule macro is just a shortcut for \swrulex{length}{0pt}{max width}.
%
% The minimum width is the width of the line at the far left and
% right ends, while the maximum width is the width of the line in
% the very middle.
%
% The english line is made up of many short lines of different widths.
% The counter variable \swrulecount specifies how many small line pieces
% should be used to approximate the english line. It is set to 50 by
% default. The larger this value is, the finer-grained the resulting
% english line will be, so that the steps will not be as obvious.
% The \swrulecount variable should never be set to one, as a division
% by zero would occur. Likewise, any value smaller than 1 is pointless,
% albeit possible.
%
% The style package is a quick hack. If any error should occur, then
% I would greatly appreciate learning about it.
% Likewise, any suggestion is appreciated.
%
% The style package is copyrighted but may be used and extended in
% any way, as long as a pointer to the original author is maintained.
% The author is not liable for any problem that may or may not result
% from using this package. Use at your own risk.
%
% Enjoy.

\newcount\swrulecount
\newcount\swrulestep
\newdimen\swrulemin
\newdimen\swrulemax
\newdimen\swrulelength
\newdimen\swruleraise
\newdimen\swrulewidth
\newdimen\swruledelta
\newdimen\swrulepiece

\swrulecount=50

\def\swrulex#1#2#3{%
\swrulestep=\swrulecount%
\advance\swrulestep by -1%
\swrulelength=#1%
\swrulemin=#2%
\swrulemax=#3%
\swrulewidth=\swrulemin%
\swruleraise=\swrulemax%
\advance\swruleraise by -\swrulemin%
\divide\swruleraise by 2%
\swruledelta=\swrulemax%
\advance\swruledelta by -\swrulemin%
\divide\swruledelta by \swrulestep%
\multiply\swrulestep by 2\advance\swrulestep by 1%
\swrulepiece=\swrulelength%
\divide\swrulepiece by \swrulestep%
\swrulestep=1%
\hbox{%
\loop%
\raise\swruleraise\hbox{\rule{\swrulepiece}{\swrulewidth}}%
\ifnum\swrulestep<\swrulecount%
\advance\swrulestep by 1%
\advance\swruleraise by -\swruledelta%
\advance\swrulewidth by 2\swruledelta%
\repeat%
\advance\swrulestep by -1%
\advance\swruleraise by \swruledelta%
\advance\swrulewidth by -2\swruledelta%
\loop%
\raise\swruleraise\hbox{\rule{\swrulepiece}{\swrulewidth}}%
\ifnum\swrulestep>1%
\advance\swrulestep by -1%
\advance\swruleraise by \swruledelta%
\advance\swrulewidth by -2\swruledelta%
\repeat%
}}

\def\swrule#1#2{\swrulex{#1}{0pt}{#2}}
