%
% showdim.sty : a package to display dimensions
%
% checksum = "21419 104 359 3107"
% 
% Package options :
%  cm      show dimensions in centimeters
%  in      show dimensions in inches
%  pt      show dimensions in points
%  pc      show dimensions in picas
%  bp      show dimensions in big points
%  mm      show dimensions in millimeters
%  dd      show dimensions in Didot points
%  cc      show dimensions in ciceros
%
% Package commands :
%  \showdim[some text]{<a dimension>}
%  
%  Display <a dimension> in the unit chosen by the package option.
%  If the optional [some text] argument is present, it will be output 
%  before the dimension.
%  
%  \showdim uses \message to display the text and the dimension.
%  
% Example:
% 
%   \usepackage[mm]{showdim}
%    ...
%   \showdim[^^JText width = ]{\textwidth}
%   \showdim[^^JText height = ]{\textheight}
%   \message{^^J}
%    ...
% 
%
% Fr\'{e}d\'{e}ric Boulanger  <Frederic.Boulanger@supelec.fr>
% Sup\'{e}lec - Service Informatique
% Plateau de Moulon
% F-91192 Gif-sur-Yvette cedex
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{showdim}[2000/04/19 v1.0 by Frederic Boulanger]
%
% Options to choose the display unit for dimensions
\DeclareOption{cm}{%
  \def\showdim@fact{2.54}\def\showdim@unit{cm}%
}
\DeclareOption{in}{%
  \def\showdim@fact{1}\def\showdim@unit{in}%
}
\DeclareOption{pt}{%
  \def\showdim@fact{72.27}\def\showdim@unit{pt}%
}
\DeclareOption{pc}{%
  \def\showdim@fact{6.0225}\def\showdim@unit{pc}%
}
\DeclareOption{bp}{%
  \def\showdim@fact{72}\def\showdim@unit{bp}%
}
\DeclareOption{mm}{%
  \def\showdim@fact{25.4}\def\showdim@unit{mm}%
}
\DeclareOption{dd}{%
  \def\showdim@fact{67.541510501}\def\showdim@unit{dd}%
}
\DeclareOption{cc}{%
  \def\showdim@fact{5.6284592084}\def\showdim@unit{cc}%
}
%
% Display dimensions in inches by default
\ExecuteOptions{in}

\newcount\showdim@intpart  % integer part of the dimension to be displayed
\newcount\showdim@fracpart % fractional part of the dimension to be displayed

% Convert a dimension to the chosen unit (use \showdim@fact)
%  #1 is the dimension
%  #3 is the text to be displayed after the dimension
\newcommand{\showdim}[2][]{%
  \setlength{\@tempdima}{#2}%
  % convert the dimension to millions of inches
  % the 1000000 factor allows to work with integers (counters)
  % without loosing too much precision
  \setlength{\@tempdima}{0.21113586637\@tempdima}% inches*1000000
  % use \showdim@fact to convert the dimension to the chosen unit
  \setlength{\@tempdima}{\showdim@fact\@tempdima}%
  % copy it to counters (converts to integer)
  \showdim@fracpart=\@tempdima
  \showdim@intpart=\showdim@fracpart
  % scale down by the 1000000 factor to get the effective integer part
  \divide\showdim@intpart by 1000000
  % get the remainder of the scale down operation: this is the
  % fractional part.
  \@tempcnta=\showdim@intpart
  \multiply\@tempcnta by 1000000
  \advance\showdim@fracpart by -\@tempcnta
  % display the dimension.
  \message{%
    #1\the\showdim@intpart.\the\showdim@fracpart\showdim@unit
  }%
}

\ProcessOptions\relax
\endinput
%%%%%%%%%%%%%%%%%%%%%%%%%%%
