triplefil.tex
triplefil.tex
—
TeX document,
3 KB (3261 bytes)
File contents
\documentclass[a4paper]{article} \title{Do you need some stretch?} \author{Marcin Woli\'nski} \begin{document} \maketitle \thispagestyle{empty} \TeX's \verb|\leaders| primitive can be used to fill arbitrary space with a stretchable line (cf.\ \verb|\hrulefill|). It is also possible to have an expandable triple line: \def\triplefil{% \leaders\hrule height4pt depth-3.2pt\hfil \hskip0pt plus-1fil \leaders\vrule height1.6pt depth0pt\hfil \hskip0pt plus-1fil \leaders\vrule height-.6pt depth1pt\hfil } \def\triplefilledline#1{% \hbox to\hsize{% \vrule height4ptdepth3ptwidth.8pt \triplefil \vrule height10ptdepth1ptwidth.4pt \enspace\strut#1\enspace \vrule height10ptdepth1ptwidth.4pt \triplefil \vrule height4ptdepth3ptwidth.8pt } } \bigskip \triplefilledline{The St.\ Anford Orchestra} \bigskip \triplefilledline{Variations on a Theme by Tchaikovsky} \begin{verbatim} \def\triplefil{% \leaders\hrule height4pt depth-3.2pt\hfil \hskip0pt plus-1fil \leaders\vrule height1.6pt depth0pt\hfil \hskip0pt plus-1fil \leaders\vrule height-.6pt depth1pt\hfil } \def\triplefilledline#1{% \hbox to\hsize{% \vrule height4ptdepth3ptwidth.8pt \triplefil \vrule height10ptdepth1ptwidth.4pt \enspace\strut#1\enspace \vrule height10ptdepth1ptwidth.4pt \triplefil \vrule height4ptdepth3ptwidth.8pt } } \triplefilledline{The St.\ Anford Orchestra} \triplefilledline{Variations on a Theme by Tchaikovsky} \end{verbatim} To understand what happens here one needs to count stretchability of leaders and glue in \verb|\triplefil|. It is: 1fil (from \verb|\hfil|) + $-1$fil (from \verb|\hskip|) + 1fil + $-1$fil + 1fil, which sums up to 1fil. So when \TeX\ needs to set \verb|\triplefil| to, say, 37pt it stretches each fil of glue to that length. The first leaders become 37pt wide, then comes \verb|\hskip| to $-37$pt ($-1$fil), and so \TeX\ overprints the second \verb|\leaders| on the first, and the same repeats with the next glue and leaders. This trick opens space for countless variations: \def\lquadruple{% \leaders\hrule height6.2pt depth-6pt\hskip0ptplus3fil \hskip0pt plus-2fil \leaders\vrule height4.2pt depth-4pt\hskip0ptplus3fil \hskip0pt plus-2fil \leaders\vrule height2.2pt depth-2pt\hskip0ptplus3fil \hskip0pt plus-2fil \leaders\vrule height0.2pt depth0pt\hskip0ptplus3fil } \def\rquadruple{% \leaders\vrule height0.2pt depth0pt\hskip0ptplus3fil \hskip0pt plus-2fil \leaders\vrule height2.2pt depth-2pt\hskip0ptplus3fil \hskip0pt plus-2fil \leaders\vrule height4.2pt depth-4pt\hskip0ptplus3fil \hskip0pt plus-2fil \leaders\hrule height6.2pt depth-6pt\hskip0ptplus3fil } \def\quadfilledline#1{% \hbox to\hsize{% \lquadruple \enspace\strut#1\enspace \rquadruple } } \bigskip \quadfilledline{The St.\ Anford Orchestra} \bigskip \quadfilledline{Variations on a Theme by Tchaikovsky} \bigskip %Note: The autor is not at all sure he has invented this trick himself. %If this invention is yours please claim the authorship. \end{document} %%% Local Variables: %%% mode: latex %%% TeX-master: t %%% End:
Document Actions