[OS X TeX] Calculate with LaTeX and fp.sty
Frank STENGEL
fstengel at mac.com
Mon Feb 6 14:03:43 CET 2006
Le 5 févr. 06 à 21:58, Friedrich Vosberg a écrit :
> Morning.
>
> I've spent the whole weekend but did not find a solution.
>
> Does somebody of you have an idea, how to calculate the following
> example including the hidden part in which the result of the
> previous calculation should be processed?
Why not use \sum? The problem is that macros do not have a result per
se. \RVGInkasso onl typesets/prints the result (the contents of sum).
One way would be to have temporary macos containing the results. Say
\resultRVGInkasso etc. Your code could become:
===== 8>< =====
\documentclass{minimal}
\usepackage{fp}
\usepackage{numprint}
%
\newcommand{\rtink}[1]{%
\def\Inkasso{#1}
\def\RVGInkasso{%
\FPiflt{#1}{2500.01}
\FPset{\sum}{#1}%
\FPmul{\sum}{\sum}{.01}%
\FPround{\sum}{\sum}{2}%
\numprint{\sum}%
\else%
\FPiflt{#1}{10000.01}
\FPset{\sum}{#1}%
\FPsub{\sum}{\sum}{2500.00}%
\FPmul{\sum}{\sum}{.005}%
\FPadd{\sum}{\sum}{25.00}%
\FPround{\sum}{\sum}{2}%
\numprint{\sum}%
\else%
\FPifgt{#1}{10000.009}
\FPset{\sum}{#1}%
\FPsub{\sum}{\sum}{10000.00}%
\FPmul{\sum}{\sum}{.0025}%
\FPadd{\sum}{\sum}{62.50}%
\FPround{\sum}{\sum}{2}%
\numprint{\sum}%
\fi
\FPset{\resultRVGInkasso}{\sum}%
}%
}%
\def\jav{1234}
\def\rtrvg{%
\RVGInkasso
\FPset{\sum}{\resultRVGInkasso}%
\FPadd{\sum}{\sum}{\jav}%
\FPround{\sum}{\sum}{2}%
\numprint{\sum} % not \rtvg, otherwise endless loop!
}%
\begin{document}
\rtink{4000}
\Inkasso\\
\RVGInkasso\\
\rtrvg
\end{document}
====== ><8 =====
By the way, why repeat \numprint three times in \RVGInkasso?, why not
factor it out of the \if ... \fi? One could have also a non-\numprint
version of your macro, coupled with a version that ose the \numprint.
That would look like
\def\RVGInkasso{%
% the previous code without the \numprints
}
\def\typeRVGInkasso{%
\RVGIkasso
\numprint{\resultRVGInkasso}%
}
--
Frank STENGEL (fstengel<at>mac.com)
------------------------- Info --------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
& FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
More information about the macostex-archives
mailing list