*Fleurons* are small decorative pieces that were often used in the past for filling big blank spaces in books. They are seldom used nowdays. As besides they will not appear more than a few times in any book (mainly at the end of chapters), the easiest thing to do if one insists in using them (for instance for simulating an old edition of some past work) is to arrange its presence manually in the source document in the way one would do for any other figure or piece of text.
I subscribe to this, which is without doubt the way to proceed if the original document will allways be typesett in the same way. But if it were an extensive work and one foresees different layouts for its appearence as different *products*, then one would have one more source of worries after every run of the work through *Context*, as you can bet that sooner than later one page will have been included somewhere whose only content will be the damned *fleuron*, something that obviously should not happen.
This is the problem that I tackled, because I did not find any previous reference or solution to it. My reasoning, my explanations and the working code are all contained in the rest of this message.
It is conceived as being composed of two parts, but it can also be saved and dealt as one piece. If one saves it as two independent files (as should be done if one intends to use it for any other thing that running the tests samples) the content of the first file will be the one delimited as *Fleuron.tex* and that of the second (*Fleuron_test.tex*) would be the rest of the message. The line of this second file
% \input {Fleuron}
should be uncommented if one intends to run it as such. The one file version runs as it is.
The script creates the new command *\Fleuron{\<motive name>}*, which is the one to include at the place intended in the source document for the *fleuron* to appear (of course after having incorporated the contents of *Fleuron.tex* in its preamble with *\input{Fleuron}*). The argument *<motive name>* allows the selection of a specific motive among the several of them that could be available; the user can create and organize all this according to his wishes. For instance *\Fleuron{\MotiveFive}* would use the example labelled *\MotiveFive* in the group of examples provided. The comments in *Fleuron.tex* explain how to handle all this.
Enjoy and critizice
Francisco
%%%%%%%%%%%%%%%%%%%%%%%
%
% Fleuron.tex
% Script that explains and implements in *ConTeXt* Mk-IV the kind of small ornaments
% traditionally used by printers for filling big blank spaces in books and printed works.
%*Fleuron*: subst. masc. 2b) Élément décoratif de fantaisie ornant le titre ou les blancs des principales divisions d'un ouvrage [livre] (Trésor de la langue française informatisé).
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Creation of the ornament as an entity (in the form of a box)
% Typesetting true *fleurons* requires the use of *TeX*'s special *box registers* as arguments;
% here box register number *0* has been arbitrarily selected for the proceedings.
% The essential steps in the construction are:
% - (typo)graphical composition of the motive (as for instance *\midaligned{Finis}* in the first example)
% or designation of the source file of an image,
% - enclosure of it in a vertical box (*\vbox{\midaligned{Finis}}*) and
% - finally association of the boxed motive with boxregister *0* (*\setbox0= ...*), all of which happens
% in reverse order, from right to left, in the code.
% Here are several examples of this:
%\setbox0=\vbox{\midaligned{Finis}}
%\setbox0=\vbox{\midaligned{Finis\\coronat\\opus}}
%\setbox0=\vbox{\midaligned{*****} \Inter \midaligned{***} \Inter \midaligned{*}}
% In order to get in *TeX* something remotely similar to a normal variable,
% called *Motivo*, the following machinery has to be implemented
\def\Motivo{\copy0} % get a copy of register's *0* content
% the graphic parts of several (typographical) test motives follow:
\def\MotOne{{\midaligned{\em Finis}}}
\def\MotTwo{{\midaligned{\em Finis\\\em coronat\\\em opus}}}
\def\MotThree{{\midaligned{*****} \Inter \midaligned{***} \Inter \midaligned{*}}}
\def\MotFour{{\midaligned{___________}}}
\def\MotFive{{\bf \midaligned{\hl[1]} \Inter \midaligned{\hl[5]} \Inter \midaligned{\hl[1]}}}
%%%%%%%%%%%%%%%%%%%%%%%%%
%
% THINGS THAT DO NOT WORK
%
%\setbox0=\vbox{\midaligned{\switchtobodyfont[20pt]*}} % executing these corrupt the whole script
%\setbox0=\vbox{\switchtobodyfont[20pt] \midaligned{*****\\***\\*}}
%\def\Grande{\midaligned{\switchtobodyfont[50pt]*}} % in any form it is tried
%\setbox0=\vbox{\Grande}
%
%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%
%
% USING FIGURES AS MOTIVES
%
% Most *fleurons* will be based on figures (usually images of schematic line drawings)
% rather than on elements of the alphabetical character set.
% So it is important to insure that also this alternative works as it should.
% *Contextref* says that just giving the name of the figure's file is enough,
%\useexternalfigure [cow] [cow.pdf] [scale=300]
% but this usually does not work, so better give the whole path to the figure in your machine
\useexternalfigure [cow] [L:/ConTeXt/context/tex/texmf-context/tex/context/sample/cow.pdf] [hfactor=20]
%\setbox0=\vbox{\externalfigure [cow] }
\def\MotCow{{\externalfigure [cow] }}
%
%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This is the algorithmically interesting part of the whole business. It rests upon one instruction,
% *pagespace*, which gets and handles some of *TeX*'s internal magnitudes of the page.
% Its code was devised, implemented and very well explained by D. Salomon
% in *Output Routines: Examples and Techniques.
% Part I: Introduction and Examples.* Tugboat 11 nº 1: 71.), from where the following extract originates:
%
% "As an example, the two variables [*pagetotal*, *t*, and *pagegoal*, *g*] will be used
% to determine how much space is left on the current page.
% If *t* is zero, the space left on the page is the entire page (*\vsize*).
% Otherwise, it is the difference *g − t*. Macro *\pagespace* calculates that difference".
% The interpretations and comments that follow are on the contrary mine;
% so be careful: they can be wrong!
% Determination of the space available in *TeX*'s *current page*
\newdimen\Spaceleft % the result will be stored under this name
% computation of the datum
\def\pagespace{%
\ifdim\pagetotal=0pt % if the page is empty (i.e. if it is a new page)
\Spaceleft=\vsize % the available space is the full design page
\else % otherwise
\Spaceleft=\pagegoal % the required amount is the design maximum size
\advance\Spaceleft -\pagetotal % less the already used space
\fi}
% We also need for our purposes certain numerical information about the ornament,
% mainly its height; so let's get it algorithmically
%\def\Talla{100pt}
\newdimen\Orn % the height of the ornament in points
\newdimen\Talla % the space requested from the page (with some *air* around)
\newdimen\Respiro % the blank space between text and *fleuron*
% let us construct the selected *fleuron*
\def\Instance#1{% % we get the (typo)graphical content as argument,
\setbox0=\vbox{#1} % put it in a box and assign the box to register *0*
\Orn=\ht0 % after which we can get the required values through this register
\Talla=\ht0 % (getting as an aside a little sample of the daunting *texan* arithmetic)
%\advance \Talla by 0.5\Talla % compute half the height of the ornament
\advance \Talla by \Talla % twice the height of the ornament
% \Respiro=0.5\ht0 % half the height of the ornament
}
% and the operative command can be finally issued
\def\Fleuron#1{%
\Instance{#1} % assemble the object
\pagespace % get from *TeX* the relevant magnitudes about the *current page*
% (transitory debug information
% Available: \the\Spaceleft\par % this shows the information on the document itself
% Required: \the\Talla\par
% Ornament: \the\Orn\par
% Disponible: \show\Spaceleft\par % and this shows it in the terminal
% Requerido: \show\Talla\par
% Ornamento: \show\Orn\par % )
\ifdim\Spaceleft>4\Orn % if there are lots of space available
% \Respiro=\ht0 % insert a bigger separation
\Respiro=\Orn % insert a bigger separation
\else
\Respiro=0.5\Orn % insert a smaller separation
\fi
\ifdim\Spaceleft<\vsize % only when the page has already some previous content
\ifdim\Spaceleft>\Talla % but keeps also enough space for the ornament,
\vskip\Respiro % add a reasonable separation from the text
% \vskip 0.5\Orn % (as could be half the size of the ornament)
\midaligned{\Motivo} % and typeset the ornament centered
\fi
\fi
}
\def\Inter{\vskip 0.1pt} % small downward displacement
%%%%%%%%%%%%%%%%%%%%%
%
%End of *Fleuron.tex*
%
%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%
%
% *Fleuron_test.tex*
% Test script for the *Fleuron* instruction
%\input {Fleuron} % incorporate the contents of *Fleuron.tex*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% some layout provisions for the test document
\setuplayout[lines=10] % size of the output page in lines
\preloadtypescripts
\usetypescript[latinmodern]
\setupbodyfont[9pt]
%\tracingpages=1 % show some internal typrographical magnitudes in the *.log* file
%%%%%%%%%%%%%%%%%%%%%
%
% Typesetting and display
%
\starttext
Test script for the \em Fleuron \em complement.\par
%\placefigure [none] {}{\externalfigure[cow]} % testing if figure reproduction works by itself
\dorecurse{2}{Line \recurselevel\par} % fill the page with some lines and show the *fleuron*
%\dorecurse{6}{Line \recurselevel\par} % (more lines could exclude the *fleuron*)
% *\MotOne*, *\MotTwo*, *\MotThree*, *\MotFour*, *\MotFive*
% y *\MotCow* are available as example arguments
\Fleuron{\MotTwo} % passed argument allows selection among available motives
\stoptext