Code and comments

Practical and theoretical aspects of software development

Typesetting vertical arithmetic in LaTeX using xlop

with 2 comments

If the question involves mathematical typesetting, then you can be sure that the answer is LaTeX. But if you are off the beaten path, LaTeX can be both the solution and a new problem.

I was interested in typesetting some elementary-school style vertical arithmetic problems. You know, like:

  28
+ 15
----

 
Except with better readability.

This can be done by hand, using some sort of array, but this introduces various types of pain, which could result in something like:

\begin{tabular}{ccc}
  & 2 & 8 \\
+ & 1 & 5 \\
\hline
\end{tabular}

 
Ugly. Numbers need to be split into their digits, and different sizes of numbers require different sizes of arrays.

What to do? Not surprisingly, the solution is out there, and it solves problems I wasn’t even yet aware of. Just include the xlop package, and the above reduces to:

\opadd{28}{15}

 
…almost. The eXtra Large OPerator package includes the answer by default, and any digits that are carried in the operation. The easiest way to eliminate them that I found was to set a resultstyle and carrystyle that would make them invisible.

It’s a shame to not include some pretty typesetting in this post, but it seems that there is no obvious way to get MathJax,xlop, and WordPress.com to work together. Rather than shave that yak, I thought I would briefly mention that if you are looking for something like xlop, then good news, it’s out there, and it’s easy to use.

Advertisements

Written by Eric Wilson

September 19, 2011 at 12:29 pm

Posted in how-to

Tagged with ,

2 Responses

Subscribe to comments with RSS.

  1. This would be a much handier post with a snippet of how you made the answers invisible…

    Jason

    July 27, 2012 at 1:46 pm

    • Good point, updated.

      Eric Wilson

      July 28, 2012 at 2:39 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: