Generalproblem division with macros

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
chruschtschow
Posts: 2
Joined: Sat Jan 16, 2010 5:49 pm

problem division with macros

Post by chruschtschow »

hi guys,
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...

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

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

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

problem division with macros

Post by gmedina »

Hi,

you could try using some of the features provided by the fp or fltpoint packages.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

problem division with macros

Post by Juanjo »

Just to complete gmedina's answer, I provide an example:

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}
The fp package is divided into sub-packages. You only need one of them to get sums and divisions.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
chruschtschow
Posts: 2
Joined: Sat Jan 16, 2010 5:49 pm

Re: problem division with macros

Post by chruschtschow »

hi,
that is exactly what im looking for! Thank u guys!!
Post Reply