diff options
author | Karl Berry <karl@freefriends.org> | 2006-01-12 23:58:22 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2006-01-12 23:58:22 +0000 |
commit | c6b827c6f5aab4beff40b7bef80e869c6815d826 (patch) | |
tree | 1ed61d883ba88897fbf68a71547b4a7286e57368 /Master/texmf-dist/tex/latex/ltxmisc/printlen.sty | |
parent | 7f9543ffaf295484b99beae71350a519562df613 (diff) |
ltxmisc
git-svn-id: svn://tug.org/texlive/trunk@1056 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/ltxmisc/printlen.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/ltxmisc/printlen.sty | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/ltxmisc/printlen.sty b/Master/texmf-dist/tex/latex/ltxmisc/printlen.sty new file mode 100644 index 00000000000..067eff68957 --- /dev/null +++ b/Master/texmf-dist/tex/latex/ltxmisc/printlen.sty @@ -0,0 +1,138 @@ +% printlen.sty Print lengths in a variety of units +% +% Author: Peter Wilson (CUA) +% (now at peter.r.wilson@boeing.com) +% Copyright 2001 Peter R. Wilson +% Released under the LaTeX Project Public License +% +% Extensions courtesy of Harald Harders (h.harders@tu-bs.de) +% +% Usage instructions are at the end of this file. +% +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{printlen}[2001/12/09 v1.1 print lengths with units] +% +% \uselengthunit{<unit>} sets \l@nunits to the value of <unit> +% and \l@nunitperpt to the number of <unit> in 1pt. +\newcommand{\uselengthunit}[1]{% + \def\l@nunitperpt{1.0}\def\l@nunits{pt}% + \def\l@nta{#1}\def\l@ntb{pt}% + \ifx \l@nta\l@ntb + \def\l@nunitperpt{1.0}\def\l@nunits{pt}% + \else + \def\l@ntb{pc}% + \ifx \l@nta\l@ntb + \def\l@nunitperpt{0.083333}\def\l@nunits{pc}% + \else + \def\l@ntb{in}% + \ifx \l@nta\l@ntb + \def\l@nunitperpt{0.013837}\def\l@nunits{in}% + \else + \def\l@ntb{mm}% + \ifx \l@nta\l@ntb + \def\l@nunitperpt{0.351459}\def\l@nunits{mm}% + \else + \def\l@ntb{cm}% + \ifx \l@nta\l@ntb + \def\l@nunitperpt{0.0351459}\def\l@nunits{cm}% + \else + \def\l@ntb{bp}% + \ifx \l@nta\l@ntb + \def\l@nunitperpt{0.996264}\def\l@nunits{bp}% + \else + \def\l@ntb{dd}% + \ifx \l@nta\l@ntb + \def\l@nunitperpt{0.9345718}\def\l@nunits{dd}% + \else + \def\l@ntb{cc}% + \ifx \l@nta\l@ntb + \def\l@nunitperpt{0.0778809}\def\l@nunits{cc}% + \else + \def\l@ntb{PT}% + \ifx \l@nta\l@ntb + \def\l@nunitperpt{1.0}\def\l@nunits{PT}% + \fi + \fi + \fi + \fi + \fi + \fi + \fi + \fi + \fi +} +\uselengthunit{pt} + +% \printlength{<length>} prints the value of <length> in the units set +% by \uselengthunit. +\newcommand{\printlength}[1]{% + \def\l@nta{pt}\ifx\l@nta\l@nunits\the#1\else + \def\l@nta{PT}% + \@tempdimc=\l@nunitperpt #1\relax\strip@pt\@tempdimc + \unitspace\relax\ifmmode + \mathrm{\ifx\l@nta\l@nunits pt\else\l@nunits\fi}% + \else + \ifx\l@nta\l@nunits pt\else\l@nunits\fi + \fi\fi} + +% \rndprintlength{<length>} prints the rounded value of <length> in +% the units set by \uselengthunit. Contributed by Harald Harders. +\def\@round#1.#2\@empty{#1}% +\newcommand{\rndprintlength}[1]{% + \def\l@nta{pt}\ifx\l@nta\l@nunits\the#1\else + \def\l@nta{PT}% + \setlength{\@tempdimc}{\l@nunitperpt #1}% + \addtolength{\@tempdimc}{0.5pt}% + \edef\@@round{\strip@pt\@tempdimc}% + \expandafter\@round\@@round.\@empty + \unitspace\relax\ifmmode + \mathrm{\ifx\l@nta\l@nunits pt\else\l@nunits\fi}% + \else + \ifx\l@nta\l@nunits pt\else\l@nunits\fi + \fi\fi} + +% Small space. Contributed by Harald Harders. +\newcommand{\unitspace}{\,} + +\endinput + +% USAGE: +% +% \printlength{<length>} prints the value of a LaTeX length in the +% units specified by \uselengthunit{<unit>}, where <unit> may be any TeX +% length unit except for scaled point. That is, <unit> may be any of: +% pt, pc, in, mm, cm, bp, dd or cc. When pt is set the printed length +% value will include any stretch or shrink values, otherwise these +% are not printed. The <unit> argument may also be PT, in which case +% length values will be printed in pt units but without any stretch +% or shrink values. An unknown value for <unit> is treated as though it +% had been specified as pt. +% The unit is separated from the number using the command +% \unitspace which is set to \, by default. In math mode the units are +% printed upright. +% \rndprintlength{<length>} prints the rounded value of a LaTeX length. +% Use PT instead of pt for rounded points if there are stretch or +% shrink values. +% +% The initial setting is \uselengthunit{pt} +% +% Example: +% +% The \verb|\textwidth| is \printlength{\textwidth} which is also +% \uselengthunit{in}\printlength{\textwidth} and +% \uselengthunit{mm}\printlength{\textwidth}. +% +% Changes: +% +% Version 1.1 (2001/12/09) +% o Print rounded values +% o Space between value and units +% +% Version 1.0 (2001/11/03) +% o First public release +% +% Peter W. +% Harald Harders +% 2001/12/09 +% + |