Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

One of the arithmetic instructions (\divide) does not even have an equivalent in standard LaTeX. The inx expressions can be used in arguments to macros (the calc package doesn't employ category code changes to achieve its goals)

share|improve this question
3  
... and the question is? \newcommand\mydivide[3]{\edef#1{\number\numexpr(#2)/(#3)\relax}} will divide the second by the third argument and store the result in a macro whose name is the first argument. –  Stephan Lehmke Apr 10 '12 at 17:27
add comment

2 Answers

There are a number of libraries that can be used for calculations with LaTeX perhaps the best being the fp package. There is also an equivalent available in LaTeX3. To divide you type:

   \FPdiv\result{3}{7}

With the result being available in \result.

Here is a full minimal:

\documentclass{article}
\usepackage{fp}
\begin{document}
\FPdiv\result{3}{7}
\result
\end{document}
share|improve this answer
add comment

This would be the implementation of \divide in LaTeX:

\newcommand{\dividecounter}[2]{%
  \global\divide\csname c@#1\endcsname#2\relax}

Now \dividecounter{page}{3} will store in the counter page the result of the division.

Similarly one could implement \multiply. But LaTeX counters are not meant for doing arithmetic, but rather to index something. TeX counters should be used for (local) arithmetic manipulations.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.