[Tex/LaTex] LaTeX for elementary school mathematics

teaching

I would like to make some math worksheets for elementary school children. In particularly, I would like to have an array of simple additions and multiplications on each page. The idea is to build a diagnostic test of the children's ability.

I need to be able to set the problems in basic, elementary school, blackboard style. The math in LaTeX is normally rendered in a grown-up, inline way. But I want the grade school thing: one row per operand; draw a line between the operands and the solution; big, fat operation symbols. Long divisions that look like long divisions. That sort of thing.

Best Answer

Here's something you could try:

\documentclass{article}
\usepackage{etoolbox}
\usepackage{graphicx}

\makeatletter
\newlength\ae@top@length
\newlength\ae@bot@length

\def\ae@extra@width{1.25em}
%% the user interface for creating the problems
%% #1=+|-|\times|\div 
%% #2=number with at least as many digits as #3
%% #3=number with no more digits than #2              
\newcommand\operation[3]{%%
  \ifx#1\div
    \ae@setup@division{#1}{#2}{#3};%%
  \else
    \ae@setup@other{#1}{#2}{#3};%%
  \fi
}

%% setup if handling addition, subtraction, or multiplication
\def\ae@setup@other#1#2#3;{%%
  \let\ae@top\relax
  \let\ae@bot\relax
  \ae@format@top#2\relax;%%
  \ae@format@bot#3\relax;%%
  \settowidth\ae@top@length{\ae@top}%%%
  %% create a minipage for displaying the problem
  \begin{minipage}[b]{\dimexpr\ae@top@length+\ae@extra@width}%%
    \hspace*{\fill}%%
    \ae@top\newline
    \rule[-2pt]{\dimexpr\ae@top@length+\ae@extra@width}{0.4pt}%%
    \hspace*{-\dimexpr\ae@top@length+\ae@extra@width}%%
    $#1$
    \hspace*{\fill}%%
    \ae@bot\newline
  \end{minipage}%%
  }

%% setup if handling division
\def\ae@setup@division#1#2#3;{%%
  \let\ae@top\relax
  \let\ae@bot\relax
  \ae@format@top#2\relax;%%
  \ae@format@bot#3\relax;%%
  \settowidth\ae@top@length{\ae@top}%%%
  \settowidth\ae@bot@length{\ae@bot}%%
  %% create a minipage for displaying the problem
  \begin{minipage}[b]{\dimexpr\ae@top@length+\ae@bot@length+4pt+0.4pt}%%
    \hspace*{\fill}%%
    \ae@bot
    \hspace{2pt}%%
      \rule[-2pt]{0.4pt}{\dimexpr2.5ex+2pt}%%
      \rule[\dimexpr2.5ex]{\dimexpr\ae@top@length+4pt}{0.4pt}%%
    \hspace*{-\dimexpr\ae@top@length+4pt}%%
    \hspace{2pt}%%
    \ae@top
  \end{minipage}%%
}

%% a command to format the digits so they line up nicely
\def\ae@digit#1{\scalebox{1.25}{\makebox[6pt]{#1}}}

%% a command to read in the digits
\def\ae@format@the@digits#1#2#3;{%%
  \def\ae@continue{}%%
  \ifx#1\relax
    \def#1{\ae@digit{#2}}%%
  \else
    \edef#1{\expandonce#1\noexpand\ae@digit{#2}}%%
  \fi
  \ifx#3\relax
  \else
    \def\ae@continue{\ae@format@the@digits#1#3;}%%
  \fi
  \ae@continue
}

\def\ae@format@top#1#2;{\ae@format@the@digits\ae@top#1#2;}
\def\ae@format@bot#1#2;{\ae@format@the@digits\ae@bot#1#2;}

\makeatother

\newlength\aetmp
\begin{document}

\operation{\times}{346}{23}

\operation{\times}{634}{213}

\operation{+}{1364}{23}

\operation\div{1364}{23}

\end{document}

which results in

enter image description here

Here I assume that you the second argument will always have at least as many digits as the third argument.