General ⇒ problem division with macros
-
- Posts: 2
- Joined: Sat Jan 16, 2010 5:49 pm
problem division with macros
i need some little math operation in my tex code, i wana do some operation as follows:
\newcommand \NumAA{aa}
\newcommand \NumAA{ab}
\newcommand \NumAA{ba}
\newcommand \NumAA{bb}
%where aa,ab,ba,bb some numerical values
\newcommand \z {\NumAA + \NumAB}
\newcommand \n {\NumBA + \NumBB}
\newcommand \q{\z / \n}
The Problem is, that latex just replaces the macros and calculates instead of
(aa + ab) / (ba + bb) -> aa + ab / ba + bb
which is common knowledge not the same... is there a possibility to use some kind of "()" or is there some kind of float register available. Thanks for ur help..
Looking forward to hearing from you.. sry, my english is not very well...
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
problem division with macros
Code: Select all
\documentclass{article}
\usepackage{fp-basic}
\begin{document}
\newcommand{\MyOp}[4]{%
\FPadd\Numerator{#1}{#2}%
\FPadd\Denominator{#3}{#4}%
\FPdiv\Result\Numerator\Denominator}
\MyOp{1.2}{22.3}{45.2}{36.21}
\FPprint\Result
\FPset\NumAA{11.21} \FPset\NumAB{23.4}
\FPset\NumBA{2.45} \FPset\NumBB{3.43}
\MyOp{\NumAA}{\NumAB}{\NumBA}{\NumBB}
\FPprint\Result
\end{document}
-
- Posts: 2
- Joined: Sat Jan 16, 2010 5:49 pm
Re: problem division with macros
that is exactly what im looking for! Thank u guys!!