2

I am creating worksheets for young children in which they'll be doing single digit operations vertically. How do I set them up vertically so that there is:

  1. An exercise worksheet with no answers.
  2. A solutions worksheet with the answers.

The package xlop only seems to be able to create the solutions worksheet. [See below.] I don't think there is a way to have it exclude the sums.

Or is there?

Or is there some other approach I should take?

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{pgf}
\usepackage{pgffor}
\usepackage{xlop}

\setlength\parindent{0pt}

\newcommand{\InitVariables}
{%
\pgfmathsetmacro{\A}{int(random(0,9)))}
\pgfmathsetmacro{\B}{int(random(0,9)))}
}

\newcommand{\VAdd}
{%
\InitVariables
\opadd[carryadd=false]{\A}{\B}}

\newcommand{\ManyVAdd}[1]
{%
\foreach \x in {1,...,#1}{\VAdd \hspace{2cm}
}}


\begin{document}

\ManyVAdd{5}

\end{document}

enter image description here

2 Answers2

2

Apparently the copy of the manual I received is rather more informative than yours. I recommend returning it to your provider and asking for another one.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgffor}
\usepackage{xlop}
\usepackage{parskip}
\newcommand{\InitVariables}{%
  \pgfmathsetmacro{\A}{int(random(0,9)))}
  \pgfmathsetmacro{\B}{int(random(0,9)))}
}
\newcommand{\VAdd}{%
  \InitVariables
  \opadd[carryadd=false, resultstyle=\leavegap, intermediarystyle=\leavegap]{\A}{\B}%
}
\newcommand*\leavegap[1]{\space}
\newcommand{\ManyVAdd}[1]{%
  \foreach \x in {1,...,#1}{\VAdd \hspace{2cm}
  }%
}

\begin{document}

\ManyVAdd{5}

\end{document}

problems without solutions

EDIT

The original question didn't mention solutions. However, in response to the comments, you might try the following. This code will typeset the solutions on a new page at the end of the document. It also eliminates the bad boxes I got otherwise.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgffor}
\usepackage{xlop}
\usepackage{parskip}
\newcommand{\InitVariables}{%
  \pgfmathsetmacro{\A}{int(random(0,9)))}%
  \pgfmathsetmacro{\B}{int(random(0,9)))}%
}
\newcommand{\VAdd}{%
  \InitVariables
  \opadd[carryadd=false, resultstyle=\leavegap, intermediarystyle=\leavegap]{\A}{\B}%
  \immediate\write\writeall{%
    \string\opadd [carryadd=false]{\A}{\B}\string\hfill%
  }
}
\newcommand*\leavegap[1]{\space}
\newcommand{\ManyVAdd}[1]{%
  \foreach \x in {1,...,#1}{\VAdd \hfill
  }\par
  \immediate\write\writeall{\string\par}%
}
\AtBeginDocument{%
  \newwrite\writeall
  \immediate\openout\writeall=\jobname.all
}
\AtEndDocument{%
  \closeout\writeall
  \clearpage
  \section*{Solutions}
  \input{\jobname.all}%
}
\begin{document}
\section*{Questions}
\ManyVAdd{5}

\end{document}

questions solutions

cfr
  • 198,882
  • Wait... I just compiled this and it doesn't come with separate solutions for the students to self-mark. Is there an easy way to do that? – WeCanLearnAnything Jan 11 '17 at 04:37
  • You can just make it conditional and compile twice. (Presumably you can set a seed.) Or you can write out a second version to another file and input it at the end. Or ... If that's your aim, though, there are already packages which have invented the wheel for you - why not use one of those? – cfr Jan 11 '17 at 16:12
  • How do you make it "conditional? And what does it mean to "set a seed"? – WeCanLearnAnything Jan 12 '17 at 04:07
  • Using a toggle? Usually, you use a seed when you only want randomisation on the first compilation, say, and for subsequent compilations to use the original randomisations. For example, you might want your multiple-choice answers to be ordered randomly, but if the solutions are typeset by a separate compilation (with solutions=true or whatever), then you don't want them to be randomised again else the answers will not be correct at all. But you can do it without this in a single run if you wish. See edit. – cfr Jan 14 '17 at 23:42
2

Here is a homegrown alternative, governed by the state of \showsums (T or F). it can handle multiple, multi-digit addends.

\documentclass{article}
\usepackage{stringstrings,stackengine}
%%% \showsum based on http://tex.stackexchange.com/questions/219090/
%%%            writing-manual-summation-of-two-numbers/219113#219113
\newcounter{mysum}
\newcommand\showsum[1]{%
  \convertchar[q]{#1}{ }{+}%
  \setcounter{mysum}{\numexpr\thestring\relax}%
  \def\stackalignment{r}%
  \if T\showsums\edef\tmp{\themysum}\else\edef\tmp{~}\fi%
  \raisebox{-\dp\strutbox}{+\,}{\stackunder{\underline{\ \Longstack{#1}}}{%
   \tmp}}%
}
\begin{document}
\def\showsums{T}
\showsum{1 2 3 4}  $\qquad$
\showsum{23 567 34 32}  $\qquad$
\showsum{1 3567 2334 3352 567}\bigskip

\def\showsums{F}
\showsum{1 2 3 4}  $\qquad$
\showsum{23 567 34 32}  $\qquad$
\showsum{1 3567 2334 3352 567}

\end{document}

enter image description here

  • I've posted a follow-up question to this answer (see: https://tex.stackexchange.com/q/527553/112503) Perhabs you would like to answer – lAtExFaN Feb 08 '20 at 18:41