[pstricks] Complex computations with Latex lengths

Denis Girou Denis.Girou at idris.fr
Sun Nov 25 20:48:48 CET 2001


>>>>> "Jay.Bloodworth" == Jay Bloodworth <jbloodworth at sc.rr.com> writes: 
 
    Jay.Bloodworth> I used the FP fixed-point arithmetic package a lot to do
calculations 
    Jay.Bloodworth> within a document of where to put things. This works great
if all of 
    Jay.Bloodworth> the values used in the calculations are user supplied
values. But I 
    Jay.Bloodworth> have a situation where I need to measure the dimensions of
a box (using 
    Jay.Bloodworth> \settowidth) and then use that value in an FP
computation. Can anyone 
    Jay.Bloodworth> tell me how to get the value of a latex length register
into an FP
    Jay.Bloodworth> variable? 
 
    Jay.Bloodworth> I could probably also do what I need to if someone can
suggest a way to 
    Jay.Bloodworth> use the max (or min) of two latex lengths. 
 
\documentclass[a4paper]{article}

\usepackage{fp-basic}
\usepackage{fp-addons}
\usepackage{ifthen}

\FPmessagesfalse

\newlength{\LengthA}
\newlength{\LengthB}
\newlength{\LengthC}

% Return in #3 the minimum of the two lengths #1 and #2
\newcommand{\MinLength}[3]{%
\ifthenelse{\lengthtest{\the#1<\the#2}}
           {\setlength{#3}{#1}}
           {\setlength{#3}{#2}}}

% Return in #3 the maximum of the two lengths #1 and #2
\newcommand{\MaxLength}[3]{%
\ifthenelse{\lengthtest{\the#1>\the#2}}
           {\setlength{#3}{#1}}
           {\setlength{#3}{#2}}}

\pagestyle{empty}

\begin{document}

\setlength{\LengthA}{2cm}
\setlength{\LengthB}{21mm}

\makeatletter

\FPadd{\Result}{\strip at pt\LengthA}{\strip at pt\LengthB}
\typeout{The sum of `\the\LengthA' and `\the\LengthB' is `\Result'.}

\FPmin{\Result}{\strip at pt\LengthA}{\strip at pt\LengthB}
\typeout{The minimum of `\the\LengthA' and `\the\LengthB' is `\Result'.}

\makeatother

\MinLength{\LengthA}{\LengthB}{\LengthC}
\typeout{The minimum of `\the\LengthA' and `\the\LengthB' is `\the\LengthC'.}

\setlength{\LengthA}{3.4cm}

\MinLength{\LengthA}{\LengthB}{\LengthC}
\typeout{The minimum of `\the\LengthA' and `\the\LengthB' is `\the\LengthC'.}

\MaxLength{\LengthA}{\LengthB}{\LengthC}
\typeout{The maximum of `\the\LengthA' and `\the\LengthB' is `\the\LengthC'.}

\end{document}

    Jay.Bloodworth> This is not a purely pstricks issue, but I this is the
best forum I know
    Jay.Bloodworth> to ask and I think it likely that other pstricks users
might sometime 
    Jay.Bloodworth> need to do something like this.

  Nevertheless, I clearly think personally that the interest of such mailing
lists is to concentrate on their specialized topics. For questions like your
one, the general Usenet comp.text.tex forum group would be a more appropriate
place.

D.G.



More information about the PSTricks mailing list