  %%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%
  %%  BoxedMacArt.tex INTERGATION DU GRAPHISME DE MACINTOSH  %%
  %%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%  
 %%%  AUTEUR: Laurent Siebenmann
  %%    lcs@matups.matups.fr
  %%  
 %%%  VERSIONS: Avril 1991 - Nov 1991 
 %%%  (remplace ArtAdmin.tex de Sept 1989, Aout 1990) 
  %%  
 %%%  SOMMAIRE: BoxedArt.tex d\'efinit des macro-commandes
  %%    qui permettent d'int\'egrer dans un document TeX 
  %%    destin\'e \`a Textures des 
  %%    objets graphiques d\'ecrits par fichier de norme PICT,
  %%    ou EPSF, tout en accordant a chacun le statut 
  %%    d'une bo\^ite TeX ayant les bonnes dimensions. 
  %%    Son fonctionnement d\'epend d'un programme
  %%    Macintosh "ArtDealer" qui pr\'epare d'avance 
  %%    des fichiers qui permettent \`a TeX d'acc\'eder aux
  %%    dimensions des objets graphiques.
  %%    Pour les objets de norme EPSF on peut se passer 
  %%    de "ArtDealer" et utiliser l'approche 
  %%    de BoxedEPSF.doc, ce qui donne une bonne 
  %%    portbilit� en ce qui concerne les EPSF.
  %%    
  %%%% ECHANTILLON  [SAMPLE]
  %%     \input BoxedArt.tex  
  %%     \SetTexturesArtSpecials 
  %%     %% pr\'eparer � exploiter des "catalogues" de "ArtDealer"
  %%     %% ask to use graphics spec files prepared by "ArtDealer"
  %%     \ShowDisplacementBoxes
  %%     %\HideDisplacementBoxes 
  %%     %% uncomment for final version
  %%     %% supprimer le simple % en version finale
  %%     AA\BoxedArt{MonaLisa scaled 760}ZZ
  %%     %% MonaLisa is name of art file catalogued by "ArtDealer"
  %%     %% MonaLisa est un fichier d'art catalogu\'e par "ArtDealer"
  %%     \bye

  %%    
  %%%% DOCUMENTATION:
  %%  --- voir BoxedArt.doc et BoxedEPSF.doc 
  %%  --- Une meilleure integration du graphisme Macintosh, 
  %%        par Laurent Siebenmann, Cahiers GUTenberg, 
  %%        No. 4 (Dec 1989),  pages 29-38

  %%    
 %%%  AFFICHAGE: anonymous ftp 
  %%  ---  ftp 28.146.7.200 (alias shape.mps.ohio-state.edu); login:
  %%  anonymous; password: <n'importe quoi>; directory pub/osutex
  %%  
  %%  ---  ftp 130.84.128.100 (alias rsovax.circe.fr); 
  %%  login: anonymous; password: <n'importe quoi>; directory 
  %%  [anonymous.siebenmann]
  %%  

 \def\LOADED{\relax}
 \let\temp\relax
 \ifx\BoxedLoaded\LOADED
  \message{}
  \message{ %
       !!! BoxedEPS or BoxedArt macros already defined !!!}
  \let\temp\endinput
 \fi
 \temp

 \let\BoxedLoaded\LOADED
 
 \chardef\CatAt\the\catcode`\@
 \catcode`\@=11
 \chardef\C@tColon\the\catcode`\:
 \chardef\C@tSemicolon\the\catcode`\;
 \chardef\C@tQmark\the\catcode`\?
 \chardef\C@tEmark\the\catcode`\!

 \def\PunctOther@{\catcode`\:=12
   \catcode`\;=12 \catcode`\?=12 \catcode`\!=12}
 \PunctOther@

 %%temporarily suppress Plain's logging of allocations
 \let\wlog@ld\wlog 
 \def\wlog#1{\relax} 

 %% New for TOOLS
 \newif\ifIN@
 \newdimen\XShift@ \newdimen\YShift@ 
 \newtoks\Realtoks
 
 %%% New for Boxed EPSF
  %
 \newdimen\Wd@ \newdimen\Ht@
 \newdimen\Wd@@ \newdimen\Ht@@
 %
 \newdimen\TT@
 \newdimen\LT@
 \newdimen\BT@
 \newdimen\RT@
 %
 \newdimen\XSlide@ \newdimen\YSlide@ 
 %
 \newdimen\TheScale  %% secretly scale in mils: 1pt= 1mil 
 \newdimen\FigScale  %% secretly scale in mils: 1pt= 1mil 
 %
 \newdimen\ForcedDim@@

 \newtoks\gDirectorytoks@
 \newtoks\Drivertoks@
 \newtoks\gNametoks@
 \newtoks\BdBoxtoks@
  \newtoks\LLXtoks@  %% useful info for Oz
  \newtoks\LLYtoks@  

 \newif\ifNotIn@
 \newif\ifForcedDim@
 \newif\ifForcedHeight@
 \newif\ifOrigin@
 %\newif\ifPSOrigin

 \newread\EPSFile@ 
 
 %%%% MESSAGES (separate macro needed for Europe)
  %%  
  \def\ms@g{\immediate\write16}

  %\let\DiagMs@g\ms@g
  \def\DiagMs@g#1{}

 %%%% WORD-PROCESSING MACROS
  %%
  %%% \IN@0#1@#2@ : Is 1st exp of #1 in 1st exp of #2 ??
   %% Answer in \ifIN@
 \newif\ifIN@\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@}

 %%%  \Chain@ chains \Initialtoks@ and \Terminaltoks@
  %%  puts result in \Chainedtoks@
  %%  shares \Initialtoks@ and \Terminaltoks@ with \SPLIT@0#1@#2@
  \newtoks\Chainedtoks@
  \def\Chain@{\let\e@\expandafter
     \def\Chain@@{\Chainedtoks@\e@}%
     \e@\Chain@@\e@{\e@\the\e@\Initialtoks@\the\Terminaltoks@}}

  \def\Chain@@0#1\midChain@@0#2\endChain@@{\let\e@\expandafter
          \Chainedtoks@\e@{#1#2}}

 %%%  \MacroName


 %%%% MACROS TO TRIM  \ForeTrim@0#1@ and \Trim@0#1@  
   %% result appears in \Trimtoks@
   %% LIMITATION: assume no multiple spaces to trim

  \newtoks\Trimtoks@

  %%% \ForeTrim@0#1@ trims initial space of first erpansion of #1
   %% #1 of form \the\toks0 or \mymacro
 \def\ForeTrim@{\expandafter\ForeTrim@@\expandafter}
 \def\ForePrim@0 #1@{\Trimtoks@{#1}}
 \def\ForeTrim@@0#1@{\IN@0\m@rker. @\m@rker.#1@%
     \ifIN@\ForePrim@0#1@%
     \else\Trimtoks@\expandafter{#1}\fi}
   %%\m@rker expands here to \m@@rker since spot initial,
   %% so no confusuion with \m@rker

  %%% \Trim@0#1@ trims init and terminal spaces 
   %% Same syntax.
   %% Warns if internal spaces found.
   %% 
  \def\Trim@0#1@{%
      \ForeTrim@0#1@%
      \IN@0 @\the\Trimtoks@ @%
        \ifIN@ 
             \SPLIT@0 @\the\Trimtoks@ @\Trimtoks@\Initialtoks@
             \IN@0\the\Terminaltoks@ @ @%
                 \ifIN@
                 \else \Trimtoks@ {FigNameWithSpace}%
                 \fi
        \fi
      }


  %%%% MATH MACROS (provisional)
    %% use dimen registers for reals; unit 1pt
    %% (numerical dimension arguments OK unless contrary noted)

  %%%% One needs the point token seq (pt with cat 12) USES dimen 0
   \newtoks\pt@ks
   \def \getpt@ks 0.0#1@{\pt@ks{#1}}
   \dimen0=0pt\expandafter\getpt@ks\the\dimen0@

   %%% Convert dimen to "decimal multiplier"% USES dimens 0,2
  \newtoks\Realtoks% the output!
  \def\Real#1{%
    \dimen2=#1%
      \SPLIT@0\the\pt@ks @\the\dimen2@%%  lop off the points
       \Realtoks=\Initialtoks@
            }

   %%% Multiplication 
      % USES dimens 0,2,4,6; preserves args; output \Product
   \newdimen\Product
   \def\Mult#1#2{%
     \dimen4=#1\relax
     \dimen6=#2%
     \Real{\dimen4}%
     \Product=\the\Realtoks\dimen6%
        }

   %%% Inverse 
     % USES dimens 0; preserves arg; output \Inverse
 \newdimen\Inverse
 \newdimen\hmxdim@ \hmxdim@=8192pt%halfmaxdimen
 \def\Invert#1{%
  \Inverse=\hmxdim@
  \dimen0=#1%
  \divide\Inverse \dimen0%
  \multiply\Inverse 8}

 %%% \Rescale#1#2#3  % USES dimens 0,2,4,6
  %%  alters dimen register #1 by ratio #2/#3 
  %%  where #2,#3 can be raw dimensions OR dimen registers
   \def\Rescale#1#2#3{% Adequate accuracy. Can improve. 
              \divide #1 by 100\relax
              \dimen2=#3\divide\dimen2 by 100 \Invert{\dimen2}% 
              \Mult{#1}{#2}%
              \Mult\Product\Inverse 
              #1=\Product}

 %%% \Scale#1 scales dimen register #1 
   %  by dimen register real \TheScale; USES dimens 0
  \def\Scale#1{\dimen0=\TheScale %
      \divide #1 by  1280 %% 1280*5120*10=1000*2^16 
      \divide \dimen0 by 5120 % 
      \multiply#1 by \dimen0 
      \divide#1 by 10   %% max size of #1 about 32000/10 pt
     }
 
 %%% SCRUNCHING BOXES AND SHIFTING CONTENTS
  %% TeX has to do this in general
  %% since some drivers do not let one do it readily using Postscript
  %% 

 \newbox\scrunchbox

 %%% \Scrunched#1 puts #1 in an hbox
  %%    then in effect zeros the dimensions of this box
 \def\Scrunched#1{{\setbox\scrunchbox\hbox{#1}%
   \wd\scrunchbox=0pt
   \ht\scrunchbox=0pt
   \dp\scrunchbox=0pt
   \box\scrunchbox}}

  %%% \Shifted@#1 puts #1 in \hbox 
   %% then locates basepoint to bottom left corner
   %% then translates ink only by \XShift@,\YShift@
   %% with Postscript convention
   %% For simplicity use only on scrunched boxes
  %\newdimen\XShift@ 
  %\newdimen\YShift@ 
 \def\Shifted@#1{%
   \vbox {\kern-\YShift@
       \hbox {\kern\XShift@\hbox{#1}\kern-\XShift@}%
           \kern\YShift@}}

  %%%% CURATOR MODULE
    %%
   %%% New defs
 \newif\ifgFound@
 \newif\ifWillSearch@
 \newtoks\gTypetoks@
 \newtoks\gTypesListtoks@
 \newtoks\WarnedOuttoks@   %%  
  %%  

 %%% Choice of Curator or not
  %% 
  \def\SetArtFolderPath{\bgroup% PART 1
    \let\OldBackslash@\\%
    \def\\{\OtherB@ckslash}%
        \SetArtFolderPath@}

  \def\SetArtFolderPath@#1{% PART 2
   \edef\temp@{#1}%
    \Trim@0\temp@ @%
    \gDirectorytoks@\expandafter{\the\Trimtoks@ }
         \egroup}

 \newtoks\ArtFolderPathtoks

  \def\SetGSFs{%
     \ms@g{ *** Set\the\Drivertoks@ ArtSpecials}%
     \bgroup\PunctOther@
       \let\\\OtherB@ckslash
       %%%%\globaldefs=1\relax %nec cut 10-91      
          %% horrible cat change bug 9-91 for French
         \input MasterCatalog
       %%%%\globaldefs=0\relax
     \egroup
     %%\gDirectorytoks@\expandafter{\ArtFolderPath}%
     \global\gDirectorytoks@=\ArtFolderPathtoks %
     \def\GraspGraphics@{\ConsultCurator@}%
     \ms@g{}%
     \ms@g{ *** Start using Art Catalogs}%
    }
     
  \def\TeXReadEPSFs@{%
     \gTypetoks@{EPSF}% do better later??
     \def\GraspGraphics@{\ReadEPSFile@ \ReadBdB@x}%
     }
     
  \let\Curator\SetGSFs
  \def\NoCurator{\TeXReadEPSFs@
     \ms@g{ *** Stop using Art Catalogs}}

 \TeXReadEPSFs@ %default

 %%%  Stuff for graphics specfile
 %%%   will have preamble stuff
 %%%   will have \gTypesListtoks@{EPSF PICT PICTr } at end
  %%  
 %%% \gspec#1[#2]#3#4*#5at#6*#7\egs  
  %% --- graphics specfile's principal listing macro
  %%\gspec ERRnum{type}{name}w*h at x*y\egs
  %%
 \def\gspec#1[#2]#3#4*#5at#6*#7\egs{%
   \expandafter\gdef\csname gobj@-#3\endcsname{%
       %% global trial10-91    Space tests!!
        \gFound@true\gTypetoks@{#2}%
        \Wd@@=#4bp\Ht@@=#5bp\LLXtoks@{#6}\LLYtoks@{#7}%
      }%
   \if#1\relax\relax% for speed
   \else\relax 
    %"\ms@g" gave trouble /french AMS: \' to ': 9-91
    %because of cat change becoming global
    %see \global use
    \IN@0#1@\the\WarnedOuttoks@ @%
    \ifIN@\relax%%%nec!!??
    \else\relax%%%nec!!??
      \global\WarnedOuttoks@=\expandafter{\the\WarnedOuttoks@
                #1[#2]}%%\global tried 10-91
      \ms@g{}%
      \csname Warning#1[#2]\endcsname%
      \ms@g{--- problem first noticed for file #3 }%
    \fi
   \fi
   }

  \gspec[????]{missing@}100*100 at 0*0\egs
   %% if graphics object is missing

  \expandafter\def\csname ????Special@\endcsname#1#2{}
 
   %%\def\<Warning1[PICT]>{% 
 \expandafter\def\csname Warning1[PICT]\endcsname{%
    \ms@g{ !!! Suspect PICT-file creator !!!}
    \ms@g{%
    --- pass via MacDraw avoiding release 1.0x of MacDrawII.}%
     }
 
   %%\def\<Warning2[EPSF]>{% 
 \expandafter\def\csname Warning2[EPSF]\endcsname{%
    \ms@g{ !!! Suspect EPSF-file header !!!}%
    \ms@g{ --- is this un-validated DrawOver output?}%
     }
 
  %%%% \gTypesList#1 
    %%  sets up info for each type; 
    %%  possibly driver dependant
    %%
  \def\gTypesList#1{% 
       \gTypesListtoks@={#1}%
       \let\PICTOrigin@\Origin@true
       \let\PICTrOrigin@\Origin@false
       % for \EPSFOrigin@ : please search!
       \CheckSpecials@
       }

 %%%%  \CheckSpecials@
   %% runs through list of \gTypetoks@
   %% to check that [type]Special@ 
   %% exists for each type of graphics
   %%
 \newif\ifWillTest@
 \def\CheckSpecials@{%
  \Terminaltoks@=\gTypesListtoks@
  \WillTest@true
  \loop
    \IN@0 @\the\Terminaltoks@ @%
    \ifIN@\else\WillTest@false\fi%\DiagMs@g{ WillTest@false }
  \ifWillTest@
    \SPLIT@0 @\the\Terminaltoks@ @%
    \Chain@@0\the\Initialtoks@\midChain@@0Special@\endChain@@
   \let\e@\expandafter
   \def\@auxmacro{\e@\let\e@\gSpecial@}%
   \e@\@auxmacro\e@\csname\the\Chainedtoks@\endcsname
    \ifx\gSpecial@\relax
      \ms@g{}%
      \ms@g{ !!! Graphics type \the\Initialtoks@\ %
           unknown to the \the\Drivertoks@\ driver !!!}
         % next graceful exits assured!!
      \e@\e@\e@\let\e@\csname
                \the\Chainedtoks@\endcsname\DblSpider@%
    \fi
  \repeat
  }

  \def\DblSpider@#1#2{} % 
 
 %%% \ConsultCurator@
  %% --- uses \gNametoks@
  %% --- procedure to get all necessary info about named gr obj
  %%
 \def\ConsultCurator@{\message{ConsultCurator}%
  \gFound@false
       \Initialtoks@={gobj@-}\Terminaltoks@=\gNametoks@ \Chain@ 
       \expandafter\csname\the\Chainedtoks@\endcsname
  \ifgFound@
        \DiagMs@g{ \the\gNametoks@\space FOUND! : %
          \the\LLYtoks@\space\the\gTypetoks@}%  
  \else
     \csname gobj@-missing@\endcsname
     \ms@g{}%
     \ms@g{ !!! Graphics object \the\gNametoks@\ unknown !!!}%
     \ms@g{ !!! Will use placeholder !!!}%
  \fi
  }

  %%% \cBoxedArt#1 the main macro
   %%  component macros are explained in order below
   %
 \def\cBoxedArt#1{{}\leavevmode %{} fixes box mirage for \Mas
   \ReadNameAndScale@{#1}%
   \SetgPathSpec@
   \GraspGraphics@ 
   %% Calculations
     \ChooseOriginAndSpecial@%\Origin@false\ms@g{Origin@false}
     \TrimFigDims@ 
     \CalculateFigScale@  
     \ScaleFigDims@
     \SetInkShift@
   \hbox{$\mathsurround=0pt\relax
         \vcenter{\hbox{%
             \FrameSpider{\hskip-.4pt\vrule}%
             \vbox to \Ht@{\offinterlineskip\parindent=\z@%
                \FrameSpider{\vskip-.4pt\hrule}\vfil 
                \hbox to \Wd@{\hfil}%
                \vfil
                \InkShift@{\gSpecial@{\gPathSpec@}{\FigSc@leReal}}%
             \FrameSpider{\hrule\vskip-.4pt}}%
         \FrameSpider{\vrule\hskip-.4pt}}}%
     $}%
    \CleanRegisters@ 
    \ms@g { *** Box composed for the \the\gTypetoks@ 
         \space file \the\gNametoks@}%
    }
 
 \def\tBoxedArt#1{\setbox4\hbox{\cBoxedArt{#1}}%
     \setbox4\hbox{\raise -\ht4 \hbox{\box4}}%
     \box4
      }

 \def\bBoxedArt#1{\setbox4\hbox{\cBoxedArt{#1}}%
     \setbox4\hbox{\raise \dp4 \hbox{\box4}}%
     \box4
      }

  \let\BoxedArt\cBoxedArt% default setting

  %% Some compatibility with Sweet-teX
   %
  \def\gLinefigure[#1scaled#2]_#3{%
      \BoxedArt{#3 scaled #2}}

  %% Some compatibility with Rokicki's dvips
   %
  \let\EPSFbox\bBoxedArt \let\EPSFfile\bBoxedArt
  
  \def\EPSFxsize{\afterassignment\ForceW@\ForcedDim@@}
      \def\ForceW@{\ForcedDim@true\ForcedHeight@false}
  
  \def\EPSFysize{\afterassignment\ForceH@\ForcedDim@@}
      \def\ForceH@{\ForcedDim@true\ForcedHeight@true}
    

 %%% \ReadNameAndScale@#1
  %
 \def\ReadNameAndScale@#1{\IN@0 scaled@#1@% DOUBLE BARRELED
   \ifIN@\ReadNameAndScale@@0#1@%
   \else \ReadNameAndScale@@0#1 scaled\DefaultMilScale @
   \fi}
  
 \def\ReadNameAndScale@@0#1scaled#2@{% HELPER MACRO
    \let\OldBackslash@\\%
    \def\\{\OtherB@ckslash}%
    \edef\temp@{#1}%
    \Trim@0\temp@ @%
    \gNametoks@\expandafter{\the\Trimtoks@ }%
    \FigScale=#2 pt%
    \let\\\OldBackslash@
    }
  
 \def\SetDefaultArtScale#1{%
      \gdef\DefaultMilScale{#1}}

 \SetDefaultArtScale{1000}


 %%% \ReadEPSFile@
  %
 \def \SetBogusBbox@{%
     \global\BdBoxtoks@{ BoundingBox:0 0 100 100 }%
     \gdef\BdBoxLine@{ BoundingBox:0 0 100 100 }%
     \ms@g{ !!! Will use placeholder box. !!!}
     }

 \def\ReadEPSFile@{%
     \openin\EPSFile@\gPathSpec@
     \relax  %necessary to prevent precocious expansion of \ifeof
  \ifeof\EPSFile@
     \ms@g{}%
     \ms@g{ !!! EPS FILE \the\gNametoks@\ NOT FOUND !!!  }%
     \SetBogusBbox@
  \else%\fi
   \begingroup%%
   \catcode`\%=12\catcode`\:=12\catcode`\!=12
   \catcode`\G=14\catcode`\\=14\relax% 14 is comment
   \global\read\EPSFile@ to \BdBoxLine@
   \IN@0!PS@\BdBoxLine@ @%
   \ifIN@
     \NotIn@true %!PS OK so BdBox search!!
     \loop   
       \ifeof\EPSFile@\NotIn@false 
         \ms@g{}%
         \ms@g{ !!! BoundingBox not found in %
             \the\gNametoks@\ !!! }%
         \SetBogusBbox@
       \else\global\read\EPSFile@ to \BdBoxLine@
       \fi
       \global\BdBoxtoks@\expandafter{\BdBoxLine@}%
       \IN@0BoundingBox:@\the\BdBoxtoks@ @%
       \ifIN@\NotIn@false\fi%
     \ifNotIn@\repeat
   \else
         \ms@g{}%
         \ms@g{ !!! \the \gNametoks@\ not PS! !!!}%
         \SetBogusBbox@
   \fi
  \endgroup\relax
  \fi
  \closein\EPSFile@ 
   }

  %%% \ReadBdB@x
   % Rmk For simplicity 0 not used in syntax 
   %  of \ReadBdB@x@,  \ReadBdB@x@@ 
  \def\ReadBdB@x{% PART 0
   \expandafter\ReadBdB@x@\the\BdBoxtoks@ @}
  
  \def\ReadBdB@x@#1BoundingBox:#2@{% PART 1
    \ForeTrim@0#2@%
    \IN@0atend@\the\Trimtoks@ @
       \ifIN@\Trimtoks@={0 0 100 100 }%% cf \SetBogusBbox@
         \ms@g{}%
         \ms@g{ !!! BoundingBox not found in %
         \the\EPSFDirectorytoks@\the\EPSFNametoks@\space !!! }%
         \ms@g{ !!! It must not be at end of EPSF !!! }%
         \ms@g{ !!! Will use placeholder !!! }%
       \fi %% cf \SetBogusBbox@
    \expandafter\ReadBdB@x@@\the\Trimtoks@ @%
   }
    
  \def\ReadBdB@x@@#1 #2 #3 #4@{% PART 2
      \Wd@@=#3bp\advance\Wd@@ by -#1bp%
      \Ht@@=#4bp\advance\Ht@@ by-#2bp%
       \LLXtoks@={#1}\LLYtoks@={#2}%% useful info for Oz
     }

  %%% SetgDirectory 
   %
   \def\G@bbl@#1{}
   \bgroup
     \global\edef\OtherB@ckslash{\expandafter\G@bbl@\string\\}
   \egroup

  \def\SetgDirectory{%  Part 1
           \bgroup\PunctOther@\relax
           \SetgDirectory@}

  \let\SetEPSFDirectory\SetgDirectory 

 \def\SetgDirectory@#1{% Part 2
    \Trim@0#1@%  result in \Trimtoks@
    \global\toks1=\expandafter{\the\Trimtoks@}\relax
    \egroup
    \gDirectorytoks@=\toks1}%

  %%% \SetgPathSpec@
    %
  \def\SetgPathSpec@{%%
     \bgroup
     \let\\=\OtherBackSlash@
     \global\edef\gPathSpec@{%
         \the\gDirectorytoks@\the\gNametoks@}%
     \global\edef\gPathSpec@{\gPathSpec@}%
     \egroup}
    
 %%% \ChooseOriginAndSpecial@ 
   %
 \def\ChooseOriginAndSpecial@{%
     \expandafter\csname
             \the\gTypetoks@ Origin@\endcsname %% Eg \EPSFOrigin@
     \def\gSpecial@{\expandafter \csname
             \the\gTypetoks@ Special@\endcsname}% 
     } 
     

 %%% \TrimFigDims@ 
  % 
 \def\TrimTop#1{\advance\TT@ by #1}
 \def\TrimLeft#1{\advance\LT@ by #1}
 \def\TrimBottom#1{\advance\BT@ by #1}
 \def\TrimRight#1{\advance\RT@ by #1}

 \def\TrimBoundingBox#1{%
   \TrimTop{#1}%
   \TrimLeft{#1}%
   \TrimBottom{#1}%
   \TrimRight{#1}%
       }

 \def\TrimFigDims@{%
    \Wd@=\Wd@@ \Ht@=\Ht@@%
    \advance\Wd@ by -\LT@ 
    \advance\Wd@ by -\RT@ \RT@=\z@
    \advance\Ht@ by -\TT@ \TT@=\z@
    \advance\Ht@ by -\BT@
    \ifOrigin@ \DiagMs@g { *** Origin true! }%
       \XShift@=-\the\LLXtoks@ bp % multiple signs OK!
       \YShift@=-\the\LLYtoks@ bp %
    \fi 
    }


 %%% \CalculateFigScale@
  %
  \def\ForceWidth#1{\ForcedDim@true
       \ForcedDim@@#1\ForcedHeight@false}
  
  \def\ForceHeight#1{\ForcedDim@true
       \ForcedDim@@=#1\ForcedHeight@true}
  
  \def\EPSFxsize{\afterassignment\ForceW@\ForcedDim@@}
      \def\ForceW@{\ForcedDim@true\ForcedHeight@false}
  
  \def\EPSFysize{\afterassignment\ForceH@\ForcedDim@@}
      \def\ForceH@{\ForcedDim@true\ForcedHeight@true}
  
  \def\CalculateFigScale@{%
            %Have default \FigScale or read \FigScale
     \ifForcedDim@\FigScale=1000pt% %% start afresh
           \ifForcedHeight@
                \Rescale\FigScale\ForcedDim@@\Ht@
           \else
                \Rescale\FigScale\ForcedDim@@\Wd@
           \fi
     \fi
     \Real{\FigScale}%
     \edef\FigSc@leReal{\the\Realtoks}%
     }
   
  \def\ScaleFigDims@{\TheScale=\FigScale
      \ifForcedDim@
           \ifForcedHeight@ \Ht@=\ForcedDim@@  \Scale\Wd@
           \else \Wd@=\ForcedDim@@ \Scale\Ht@
           \fi
      \else \Scale\Wd@\Scale\Ht@        
      \fi
      \ForcedDim@false
      \Scale\LT@\Scale\BT@  %%%\Scale\Wd@\Scale\Ht@
      \Scale\XShift@\Scale\YShift@
      }
      
  %%% \ShowReservedBoxes
   %%  shows (prints) corrected scaled and positioned
   %%  bounding boxes; for diagnostics
  %%% \HideReservedBoxes makes them invisible again
   %%
 \def\HideReservedBoxes{\gdef\FrameSpider##1{\null}}
 \def\ShowReservedBoxes{\gdef\FrameSpider##1{##1}}
 \let\HideDisplacementBoxes\HideReservedBoxes  %% some synonyms
 \let\ShowDisplacementBoxes\ShowReservedBoxes
 \let\HideFigureFrames\HideReservedBoxes
 \let\ShowFigureFrames\ShowReservedBoxes
  \ShowReservedBoxes
 
  %%% \hSlide#1, \vSlide#1
   %%
 \def\hSlide#1{\advance\XSlide@ by #1}
 \def\vSlide#1{\advance\YSlide@ by #1}
 
  %%% \SetInkShift@, \InkShift@#1
   %%
  \def\SetInkShift@{%
            \advance\XShift@ by -\LT@
            \advance\XShift@ by \XSlide@
            \advance\YShift@ by -\BT@
            \advance\YShift@ by -\YSlide@
             }
   %
  \def\InkShift@#1{\Shifted@{\Scrunched{#1}}}
 
  %%% \CleanRegisters@
   %
  \def\CleanRegisters@{%
      \globaldefs=1\relax
        \XShift@=\z@\YShift@=\z@\XSlide@=\z@\YSlide@=\z@
        \TT@=\z@\LT@=\z@\BT@=\z@\RT@=\z@
      \globaldefs=0\relax}



 %%% Special syntax for several drivers. The macros 
  %% \SetTexturesEPSFSpecial  %% Textures 
  %% \SetUnixCoopEPSFSpecial %% dvi2ps early unix 
  %% \SetBetcholsheimEPSFSpecial %% dvi2ps by S.P.Betcholsheim
  %% \SetLisEPSFSpecial %% dvi2ps by Tony Lis
  %% \SetRokickiEPSFSpecial  %% dvips by Tom Rokicki
  %% \SetOzTeXEPSFSpecial  %% OzTeX by Andrew Trevorrow
  %% \SetPSprintEPSFSpecial %% PSprint by Andrew Trevorrow
  %% \SetArborEPSFSpecial  %% ArborTeX DVILASER/PS
  %% \SetClarkEPSFSpecial %% dvitops by James Clark
  %% \SetDVIPSoneEPSFSpecial %% DVIPSONE of Y&Y 
  %% \SetBeebeEPSFSpecial %% DVIALW by N. Beebe
  %% \SetStandardEPSFSpecial %% Nonexistant: Placebo below
  %% These macros adapt to various drivers by (re-)defining
  %% the macro \EPSFSpecial@#1#2, where
  %% #1 = EPS file pathname (use \\ for the letter backslash)
  %% #2 = scale in mils 
    %% Be wary of using strange characters in pathnames!

 \def\PSOriginTRUE{\global\let\EPSFOrigin@=\Origin@true}
 \def\PSOriginFALSE{\global\let\EPSFOrigin@=\Origin@false}
 \def\PICTOriginTRUE{\global\let\PICTOrigin@=\Origin@true}
 %\def\PICTOriginFALSE{\global\let\EPSFOrigin@=\Origin@false}
 
 %% Textures, Blue Sky Research, Barry Smith
 \def\SetTexturesEPSFSpecial{\PSOriginFALSE%
  \Drivertoks@{Textures}%
  \gdef\EPSFSpecial@##1##2{\relax
    \edef\specialthis{##2}%
    \SPLIT@0.@\specialthis.@\relax
    \special{illustration ##1 scaled 
                        \the\Initialtoks@}}}

 \def\SetTexturesArtSpecials{\SetTexturesEPSFSpecial%
    \PICTOriginTRUE  
    \gdef\PICTSpecial@##1##2{%
      \edef\specialthis{##2}%
      \SPLIT@0.@\specialthis.@\relax
      \special{pictfile ##1 scaled 
                        \the\Initialtoks@}}%
    \Curator}
   
  
  %% Unix : dvi2ps by:  Mark Senn, Stephan  Bechtolsheim,  
   % Bob  Brown, Richard, Furuta, James Schaad, 
   % Robert  Wells, Norm Hutchinson, Neal Holtz.
   % introduced by B. Horn <bkph@ai.mit.edu>
  \def\SetUnixCoopEPSFSpecial{\PSOriginTRUE % Tested!
   \Drivertoks@{UnixCoop}%
   \gdef\EPSFSpecial@##1##2{%
      \dimen4=##2pt% convert real to dimen
      \divide\dimen4 by 1000\relax
      \Real{\dimen4}%dimens 0,2 used here
      \edef\Aux@{\the\Realtoks}%  
      %%convert dimen to real
      \special{psfile=##1\space 
        hscale=\Aux@\space
        vscale=\Aux@}}}
  \def\SetUnixCoopArtSpecials{\SetUnixCoopEPSFSpecial\Curator}

  %% dvi2ps by S.P. Bechtolsheim,
   % implantations? ; dates?; availability?
   % Introduced by B. Horn <bkph@ai.mit.edu>; please test!!
  \def\SetBechtolsheimRokickiEPSFSpecial{\PSOrigintrue 
   \gdef\EPSFSpecial##1##2{%
      \dimen4=##2pt% convert real to dimen
      \divide\dimen4 by 1000\relax
      \Real{\dimen4}% dimens 0,2 used here
      \edef\Aux@{\the\Realtoks}%  
      %%convert dimen to real
      \special{ps: psfiginit}%
      \special{ps: literal 1 1 0 0 1 1 startTexFig
           \the\mag\space 1000 div \Aux@\space mul 
           \the\mag\space 1000 div \Aux@\space mul scale}%
      \special{ps: include  ##1}%
      \special{ps: literal endTexFig}%
        }}
  \def\SetBechtolsheimArtSpecials{\SetBechtolsheimEPSFSpecial\Curator}

  %% dvi2ps by Tony Lis,
   % implantations? ; dates?; availability?
   % Introduced by B. Horn <bkph@ai.mit.edu>; please test!!
  \def\SetLisEPSFSpecial{\PSOrigintrue 
   \gdef\EPSFSpecial##1##2{%
      \dimen4=##2pt% convert real to dimen
      \divide\dimen4 by 1000\relax
      \Real{\dimen4}% dimens 0,2 used here
      \edef\Aux@{\the\Realtoks}%  
      %%convert dimen to real
      \special{pstext="1 1 0 0 1 1 startTexFig\space
           \the\mag\space 1000 div \Aux@\space mul 
           \the\mag\space 1000 div \Aux@\space mul scale}%
      \special{psfile=##1}%
      \special{pstext=endTexFig}%
        }}
  \def\SetLisArtSpecials{\SetLisEPSFSpecial\Curator}

  %% dvips by Tom Rokicki; driver in portable C 
   % This driver improves on "UnixCoop" dvi2ps; 
   % its Postscript output is thee times as compact 
   % as that produced by dvi2ps
  \def\SetRokickiEPSFSpecial{\PSOriginTRUE 
   \Drivertoks@{Rokicki}%
   \gdef\EPSFSpecial@##1##2{%
      \dimen4=##2pt% convert real to dimen
      \divide\dimen4 by 10\relax
      \Real{\dimen4}% dimens 0,2 used here
      \edef\Aux@{\the\Realtoks}%  
      %%convert dimen to real
      \special{psfile="##1"\space 
        hscale=\Aux@\space
        vscale=\Aux@}}}
  \def\SetRokickiArtSpecials{\SetRokickiEPSFSpecial\Curator}

  %% OzTeX, by AndrewTrevorrow, 
   %  complete public domain TeX for Macintosh
   %  Send 10 UNFORMATTED 800K disks 
   %  with return postage 
   %  Peter Abbott, Computing Service, 
   %  Aston University, Aston Triangle, Birmingham B4 7ET
  \def\SetOzTeXEPSFSpecial{\PSOriginFALSE % artifice; see below
   \Drivertoks@{OzTeX}%
   \gdef\EPSFSpecial@##1##2{%note order
     \special{##1\space 
       ##2 1000 div \the\mag\space 1000 div mul
       ##2 1000 div \the\mag\space 1000 div mul scale
       \the\LLXtoks@\space neg \the\LLYtoks@\space neg translate
       }}}
  \def\SetOzTeXArtSpecials{\SetOzTeXEPSFSpecial\Curator}
 
 %% PSprint,  by AndrewTrevorrow for VaX VMS
  % diagnosed and tested 2-91 by Max Calviani 
  % <ISICA@ASTRPD.infn.it>
  \let\SetPSprintEPSFSpecial\SetOzTeXEPSFSpecial
  \let\SetPsprintEPSFSpecial\SetOzTeXEPSFSpecial
  \def\SetPsprintArtSpecials{\SetOzTeXEPSFSpecial\Curator}

 %% DVILASER/PS driver originally written by David Fuchs
  % marketed and supported by ArborTeXt  535 W. William St.
  % Suite 300, Ann Arbor, MI 48103, U.S.A
  % (313) 996-3566 (313) 996-3573
  % help@arbortext.com, Andrew Dobrowolski
  \def\SetArborEPSFSpecial{\PSOriginFALSE % check!
   \Drivertoks@{Arbor}%
   \gdef\EPSFSpecial@##1##2{%
     \edef\specialthis{##2}%
     \SPLIT@0.@\specialthis.@\relax % suppress decimals (nec!)
     \special{ps: epsfile ##1\space \the\Initialtoks@}}}
  \def\SetArborArtSpecials{\SetArborEPSFSpecial\Curator}

 %% dvitops, (c) James Clark <jjc@jclark.uucp>
  % public domain; distributed by UK TeX Archive
  % computers: unix, msdos, vms, primos and vm/cms,
  % (introduced by S. Ratz <spqr@uk.ac.southampton.ecs>)
  \def\SetClarkEPSFSpecial{\PSOriginFALSE % please test!
   \Drivertoks@{Clark}%
   \gdef\EPSFSpecial@##1##2{%
     \Rescale {\Wd@@}{##2pt}{1000pt}%
     \Rescale {\Ht@@}{##2pt}{1000pt}%
     \special{dvitops: import 
           ##1\space\the\Wd@@\space\the\Ht@@}}}
  \def\SetClarkArtSpecials{\SetClarkEPSFSpecial\Curator}

 %% DVIPSONE, for PC compatibles
  % Y&Y, 106 Indian Hill, Carlisle MA 01741, USA
  % (508) 371-3286
  % (introduced by B. Horn <bkph@ai.mit.edu>)
  \let\SetDVIPSONEEPSFSpecial\SetUnixCoopEPSFSpecial
  \let\SetDVIPSoneEPSFSpecial\SetUnixCoopEPSFSpecial
  \def\SetDVIPSONEArtSpecials{\SetDVIPSONEEPSFSpecial\Curator}

 %% DVIALW by N. Beebe, public domain, charge $100 
  % DVI Driver Distribution, Center for Scientific Computing,
  % Department of Mathematics, 220 South Physics Building,
  % University of Utah, Salt Lake City, UT 84112, USA
  % (introduced by B. Horn <bkph@ai.mit.edu>)
  \def\SetBeebeEPSFSpecial{%please test!
   \PSOriginfalse% 
   \gdef\EPSFSpecial##1##2{\relax
    \special{language "PS"
      literal "##2 1000 div ##2 1000 div scale
      position = "bottom left",
      include "##1"}}}
  \def\SetBeebeArtSpecials{\SetBeebeEEPSFSpecial\Curator}

 \def\SetStandardEPSFSpecial{%
    \Drivertoks@{Standard}%   
    \gdef\EPSFSpecial@##1##2{%
     \ms@g{}
     \ms@g{%
       !!! Sorry! There is still no standard for \string%
       \special \space EPSF integration !!!}%
     \ms@g{%
      --- So you will have to identify your driver using a command}%
     \ms@g{%
      --- of the form \string\Set...EPSFSpecial, in order to get}%
     \ms@g{%
      --- your graphics to print.  See BoxedArt.doc.}%
     \KillEPSFSpecial
     }}
   \def\SetStandardArtSpecials{\SetStandardEEPSFSpecial\Curator}


  \def\KillEPSFSpecial{\gdef\EPSFSpecial@##1##2{}}

  \SetStandardEPSFSpecial %% currently gives warning
 
 \let\wlog\wlog@ld %%restore logging 

 \catcode`\:=\C@tColon
 \catcode`\;=\C@tSemicolon
 \catcode`\?=\C@tQmark
 \catcode`\!=\C@tEmark

 \catcode`\@=\CatAt

  \endinput
 
%%%%%%%%%%%% ASCII Character test
 %
 %       Upper case letters: ABCDEFGHIJKLMNOPQRSTUVWXYZ
 %       Lower case letters: abcdefghijklmnopqrstuvwxyz
 %                                   Digits: 0123456789
 % Square, curly, angle braces, parentheses: [] {} <> ()
 %           Backslash, slash, vertical bar: \ / |
 %                              Punctuation: . ? ! , : ;
 %          Underscore, hyphen, equals sign: _ - =
 %                Quotes--right left double: ' ` "
 %"at", "number" "dollar", "percent", "and": @ # $ % &
 %           "hat", "star", "plus", "tilde": ^ * + ~
 %
 %%%%%%%%%%%%%%%%%%%%%%%%
 %
