TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

This question already has an answer here:

What would be the best way to use TeX to typeset basic arithmetic as it's done in school - for example, to typeset equations like

+ 42

written in this way?

share|improve this question

marked as duplicate by Werner, cmhughes, Adam Liter, Harish Kumar, Svend Tveskæg Mar 10 '14 at 6:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Possibly of interest: ctan.org/pkg/fc-arith (arithmetic flash cards - addition subtraction division multiplication problems), ctan.org/pkg/longdiv (solves the problems, too, but only division). Actually, ctan.org/pkg/xlop might be better. – cfr Mar 10 '14 at 3:38
up vote 9 down vote accepted

You could define a command to handle this:

                  & #2 \\
  $\ae@operation$ & #3 \\\hline
                  & \ae@result

  \arithmetic{1234}{234}     &     &    \arithmetic[-]{1234}{234}   \\[1cm]
  \arithmetic[x]{1234}{234}  & vs. &    \arithmetic[*]{1234}{234}  


enter image description here

In the above code, I assume the default operation will be addition, but I allow an optional argument be provided to change the operation. I also allow multiplication be indicated by passing * or x in the optional argument.

share|improve this answer
Very slick. I like the auto calculation. – cslstr Mar 10 '14 at 4:00

One approach would be to have the addition sign on the right (which I have seen on occasions), and would look something like this:



356  \\
42 & +\\



math equation

The code is a bit clunkier to have the addition symbol on the left side:



  & 356  \\
+ & 42\\
& 398


To get:

math with addition sign on left

share|improve this answer

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