summaryrefslogtreecommitdiff
path: root/macros/generic/misc/swrule.sty
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/generic/misc/swrule.sty
Initial commit
Diffstat (limited to 'macros/generic/misc/swrule.sty')
-rw-r--r--macros/generic/misc/swrule.sty89
1 files changed, 89 insertions, 0 deletions
diff --git a/macros/generic/misc/swrule.sty b/macros/generic/misc/swrule.sty
new file mode 100644
index 0000000000..1632cf3c9d
--- /dev/null
+++ b/macros/generic/misc/swrule.sty
@@ -0,0 +1,89 @@
+% 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}}