Files
writeup/AlCapSimulationReport/labelfig.sty

309 lines
9.3 KiB
TeX

%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%%%% LabelFig.tex FOR LABELLING FIGURE INSERTS %%%%%
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%% AUTHORS: Raymond S\'eroul and Laurent Siebenmann
%% A18645@FRCCSC21.bitnet and lcs@matups.matups.fr
%%
%%% VERSIONS: July, October, December 1991
%%
%%% PURPOSE:
%% Occasionally, figures imported into TeX lack some labels.
%% It may then be most appropriate to use TeX to provide
%% the labels. Several macro sets, notably the
%% LaTeX picture environment, provide means to insert
%% labels. LabelFig.tex is a macro set offering
%% labelling capability for other TeX formats such
%% as Plain and AmSTeX. Unlike most graphics tools it is
%% fast and of moderate size (costing about 1 Ko of main
%% memory and 60 control sequences). Hopefully it will work
%% in essentially all TeX environments.
%%
%%% THE IDEA:
%% A grid is laid down on the figure, as in the LaTeX
%% picture environment, and the labels are then
%% located with respect to the grid.
%% There are two auxiliary devices that give this
%% macro package a touch of novelty even for LateX users.
%% (a) the grid appears on the preview/preprint.
%% For users with a fast preview this makes
%% labeling an interactive process.
%% (b) the grid is canonical, i.e. so naturally chosen
%% that labels will probably remain well placed
%% if the figure scale is changed.
%%
%%% MAIN POSTINGS : anonymous ftp
%% --- ftp 129.69.1.12 (alias
%% rusinfo.rus.uni-stuttgart.de); login: anonymous;
%% password: <anything>.
%% --- ftp 130.84.128.100 (alias rsovax.circe.fr);
%% login: anonymous; password: <anything>; directory
%% [anonymous.siebenmann]
%% --- ftp 28.146.7.200 (alias shape.mps.ohio-state.edu);
%% login: anonymous; password: <anything>;
%% directory pub/osutex
%%
%%%% DOCUMENTATION:
%% --- see LabelFig.doc
%% (may be included at end, after \endinput)
%%
%%%% EXAMPLE OF USAGE:
%% \input \LabelFig.tex
%% \SetLabels
%% (.3*.7) first label\\
%% % center of baseline of the label
%% % will go to position .3 from left
%% % and .7 from bottom
%% \L(.61*.333) $\Lambda_1\leq\Gamma$\\
%% % \L places left edge of label
%% % (rather than the center)
%% % similarly use \R for right edge;
%% % and \B for bottom, \E for equator, and \T for top
%% \T\R(.3*.7) last label \\
%% \endSetLabels
%% \ShowGrid
%% % lays grid on figure to label;
%% % delete for final printing
%% \AffixLabels{\BoxedEPSF{MyFigure}}
%% % argument of \AffixLabels#1 should be a TeX box;
%% % the grid will cover exactly that box.
%% % (Here \BoxedEPSF is the figure insertion macro
%% % of the package \BoxedEPS.tex (same sources)
%% % for inserting encapsulated PostScript graphics.
%% % But any other means of inserting
%% % the figure can be used.)
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% FORBID REREADING %%%%%
%
\ifx\LabelFigloaded\MYundefined\relax
\else
\message{ !!! LabelFig.tex ALREADY loaded !!!}
\endinput\fi
\def\LabelFigloaded{\relax}% now loaded
%%% Beyond this point we use some control sequences
%%% that are 'padlocked' with @ of category 11
\chardef\LabelFigCatAt\the\catcode`\@
\catcode`\@=11
%%temporarily suppress Plain's logging of allocations
\let\LabelFigwlog@ld\wlog
\def\wlog#1{\relax}
\ifx\\\MYundefined@
\let\\\relax
\fi
%%%%%%% end of preamble
\def\ms@g{\immediate\write16}
\def\N@wif{\csname newif\endcsname }
\def\Temp@ {\N@wif\ifIN@}
\ifx\INN@\MYundefined@
\else \let\Temp@\relax
\fi
\Temp@
%%% \IN@0#1@#2@ : Is 1st exp of #1 in 1st exp of #2 ??
%% Answer in \ifIN@
%\newif\ifIN@ %% conserve if's
\def\IN@{\expandafter\INN@\expandafter}
\long\def\INN@0#1@#2@{\long\def\NI@##1#1##2##3\ENDNI@
{\ifx\m@rker##2\IN@false\else\IN@true\fi}%
\expandafter\NI@#2@@#1\m@rker\ENDNI@}
\def\m@rker{\m@@rker}
%%% \SPLIT@0#1@#2@ : Split 1st exp of #2 at 1st exp of #1
%% \Initialtoks@ , \Terminaltoks@ will contain pieces
\newtoks\Initialtoks@ \newtoks\Terminaltoks@
\def\SPLIT@{\expandafter\SPLITT@\expandafter}
\def\SPLITT@0#1@#2@{\def\TTILPS@##1#1##2@{%
\Initialtoks@{##1}\Terminaltoks@{##2}}\expandafter\TTILPS@#2@}
%%% \Shifted@@#1#2#3 puts #3 in \hbox
%% leaves basepoint as is
%% then translates ink only by dims #1,#2
%% with Postscript convention
%% For simplicity use only on scrunched boxes
\def\Shifted@@#1#2#3{\setbox0=\hbox{#3}%
\raise -\dp0\vbox {\kern-#2%
\hbox {\kern#1\unhbox0\kern-#1}%
\kern#2}}
\newcount\gridcount
\newbox\auxGridbox@ \newbox\hGridbox@ \newbox\vGridbox@
\newbox\Labelbox@ \newbox\auxLabelbox@
\newbox\Coordinatebox@
\newtoks\Labeltoks@
\newdimen\Wdd@ \newdimen\Htt@
\def\hRule@{\advance\gridcount -2%
\vskip-.2pt\hrule\vskip-.2pt\vfil
\llap{\smash{\raise -2.5pt
\hbox{.\number\gridcount\kern2pt}}}%
\vskip-.2pt\hrule\vskip-.2pt\vfil}
\def\vRule@{\advance\gridcount 2%
\hskip-.2pt\vrule\hskip-.2pt\hfil
\setbox\auxGridbox@=\vbox to 0pt
{\vskip \Htt@\vskip 2pt
\hbox{\kern-3.5pt.\number\gridcount}\vss}%
\wd\auxGridbox@=0pt \box\auxGridbox@
\hskip-.2pt\vrule\hskip-.2pt\hfil}
\def\PlaceGrid@@{\gridcount=10%
\setbox\hGridbox@=%
\hbox{\hbox{\hskip-.4pt\vrule
\vbox to \Htt@{\offinterlineskip\parindent=\z@\relax
\vskip-.4pt\hrule\vfil
\hRule@\hRule@\hRule@\hRule@
\vskip-.2pt\hrule\vskip-.2pt\vfil
\hbox to \Wdd@{\hfil}%
\hrule\vskip-.4pt}%
\vrule\hskip-.4pt}}%
\gridcount=0%
\setbox\vGridbox@=
\hbox{\vbox{\offinterlineskip\parindent=0pt\hsize=0pt
\vskip-.4pt\hrule%
\hbox to \Wdd@{%
\hskip-.4pt\vrule\hfil
\vtop to \Htt@{\vfil}%
\vRule@\vRule@\vRule@\vRule@
\hskip-.2pt\vrule\hskip-.2pt\hfil
\vrule\hskip-.4pt}%
\hrule\vskip-.4pt}}%
%
\wd\hGridbox@=0pt\ht\hGridbox@=0pt
\wd\vGridbox@=0pt\ht\vGridbox@=0pt
%
\hbox{\box\hGridbox@\box\vGridbox@}%
}
\def\LabelsGlobal{\def\LabGl@b{\global}}
\def\LabelsLocal{\def\LabGl@b{}}
\LabelsGlobal %% default
\def\SetLabels#1\endSetLabels{%
\LabGl@b\Labeltoks@={#1()\\}%
}
\LabGl@b\Labeltoks@={()\\}
\let\PlaceGrid@\relax
\def\ShowGrid{\let\PlaceGrid@\PlaceGrid@@}
\def\bAdjust@@{%
\setbox\auxLabelbox@=\hbox{\raise \dp\auxLabelbox@
\box\auxLabelbox@}}
\def\bAdjust@{\let\vAdjust@\bAdjust@@}
\def\eAdjust@@{\dimen0=-.5\ht\auxLabelbox@
\advance\dimen0 by .5\dp\auxLabelbox@
\setbox\auxLabelbox@=
\hbox{\raise\dimen0\box\auxLabelbox@}}
\def\eAdjust@{\let\vAdjust@\eAdjust@@}
\def\tAdjust@@{%
\setbox\auxLabelbox@=\hbox{\raise-\ht\auxLabelbox@
\box\auxLabelbox@}}
\def\tAdjust@{\let\vAdjust@\tAdjust@@}
\let\vAdjust@\relax
\def\lAdjust@{\let\hAdjust@\rlap}
\def\rAdjust@{\let\hAdjust@\llap}
\let\hAdjust@\relax\let\vAdjust@\relax
\def\FetchLabel@#1(#2)#3\\{%
\IN@0#2@@\ifIN@
\setbox0=\hbox{\ignorespaces#1#3\unskip}%
\ifdim\wd0>0pt
\ms@g{}%
\ms@g{ !!! Bad label(s)? !!!}%
\message{ #1(#2)#3}%
\fi
\def\LabelMole@##1\endFetchLabel@{%
\IN@0()\\@##1@%
\ifIN@\def\Temp@{\FetchLabel@##1\endFetchLabel@}%
\else\def\Temp@{}%
\fi
\Temp@
}%
\else
\ignorespaces#1\unskip
\setbox\auxLabelbox@=%
\hbox to 0pt{\hss\ignorespaces\hAdjust@
{\ignorespaces#3\unskip}\hss}%
\vAdjust@
\let\hAdjust@\relax\let\vAdjust@\relax
\AugmentLabelBox@@{#2}%
\ht\Labelbox@=0pt\dp\Labelbox@=0pt
\let\LabelMole@\FetchLabel@%
\fi\LabelMole@}
\newtoks\XYSep@ %\XYSep@{*}
\def\SetXYSeparator#1{%
\IN@0#1@@\ifIN@\XYSep@{*}%
\else
\XYSep@{#1}%
\fi
}
\SetXYSeparator*
\def\AugmentLabelBox@@#1{%
\IN@0\the\XYSep@ @#1@\ifIN@
\SPLIT@0\the\XYSep@ @#1@%
\setbox\Labelbox@=\hbox to 0pt{%
\unhbox\Labelbox@
\Shifted@@{\the\Initialtoks@\Wdd@}%
{\the\Terminaltoks@\Htt@}%
{\box\auxLabelbox@}}%
\else
\ms@g{}%
\ms@g{ !!! Bad insertion point. !!!}%
\message{ (#1\ this point was rejected.)}%
\fi
}
\def\PlaceLabels@@{\bgroup\mathsurround=0pt%
\def\Cr@{\\}%
\let\L\lAdjust@\let\R\rAdjust@
\let\B\bAdjust@\let\E\eAdjust@\let\T\tAdjust@
\expandafter\FetchLabel@\the\Labeltoks@\endFetchLabel@
\box\Labelbox@\egroup
}%
\let \PlaceLabels@\PlaceLabels@@
\def\AffixLabels#1{\setbox\Coordinatebox@=\hbox{#1}%
\Wdd@=\wd\Coordinatebox@ \Htt@=\ht\Coordinatebox@
\advance\Htt@ \dp\Coordinatebox@
\hbox{\copy\Coordinatebox@\kern-\Wdd@
\Shifted@@{0pt}{-\dp\Coordinatebox@}%
{\PlaceGrid@\PlaceLabels@}\kern\Wdd@}%
\let\PlaceGrid@\relax
\LabGl@b\Labeltoks@{()\\}%
}
%%% Restoring
\let\wlog\LabelFigwlog@ld %%restore logging
\catcode`\@=\LabelFigCatAt %%12 or 13
\endinput
%% end of LabelFig.tex