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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to do this using macros in TeX. Something like \power{n}{k} - the power of n to the value k - but without using \multiply.

Something like this needs to be done

k_{n+1} = n^2 + k_n^2 - k_{n-1}
share|improve this question
It is unclear what your question means. Please provide some code demonstrating what you want to achieve. Do you want to typeset a formula or calculate something with a macro? – Stephan Lehmke Apr 10 '12 at 17:20
A macros in TEX that compute The power nk, but without \multiply – Andy Apr 10 '12 at 17:27
If you'd try to do it yourself (using \numexpr) and show where you get stuck, you'd give people here something to start from. Or else, explain a little more about the context you need this for. The way you ask, it looks like you're asking people here to do your homework for you. – Stephan Lehmke Apr 10 '12 at 17:30
Why without \multiply? – Joseph Wright Apr 10 '12 at 17:43

Assuming you want to work with integers, and e-TeX is available, something like

  \ifnum\numexpr#2 = 0 %
    #1 * \expandafter\poweraux
  {#1}{#2 - 1}%

seems about right. I've not tested for edge cases or made this 'maximum efficiency' as I'm not entirely sure what is required.

share|improve this answer

Use the fp package (or pgfmath from the pgf bundle) to produce floating point calculations without having to manually specify \multiply, \divide, or the like. Here's a small example:

enter image description here

\usepackage[nomessages]{fp}% http://ctan.org/pkg/fp

See the fp README for more information on the notation and usage.

share|improve this answer

Your Answer


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.