11

I'm using xlop to display primary school style addition/subtraction/mul/div problems.

When using \opadd{1}{2} for example, It will solve the equation.

How do you hide the solution so it is suitable to give to a student to work out the problems?

1 Answer 1

11

You can change the colour of the output (or result) using resultstyle=\color{white}. Sure this will still print the actual output which you can copy-and-paste into a text editor and make it visible, but I don't think kids would do that in a primary school. Moreover, this may only be available electronically for you and not the kids.

Here's an example:

enter image description here

\documentclass{article} \usepackage{xcolor}% http://ctan.org/pkg/xcolor \usepackage{xlop}% http://ctan.org/pkg/xlop \begin{document} \opadd{1}{2} \quad \opadd[resultstyle=\color{white},carrystyle=\color{white}]{1}{2} \end{document}​ 

Since some operations indicate a carry in their presentation, changing carrystyle to \color{white} is perhaps also suggested, as I've done in my example.


Perhaps a more "secure" way of concealing the detail is to provide place holder macros for the bits of information you want to remove:

enter image description here

\documentclass{article} \usepackage{xcolor}% http://ctan.org/pkg/xcolor \usepackage{xlop}% http://ctan.org/pkg/xlop \newcommand\placeholder[1]{--}% Print -- regardless of input \newcommand\gobble[1]{}% Print <nothing> regardless of input \begin{document} \opadd{1234}{5678} \quad \opadd[resultstyle=\placeholder,carrystyle=\color{white}]{1234}{5678} \quad \opadd[resultstyle=\gobble,carryadd=false]{1234}{5678} \end{document}​ 

Setting carrystyle=false removes the display of carry elements.


Multiplication and division adds so-called intermediary elements to the operation. These can be removed in a similar way using an appropriate style set by intermediarystyle.

enter image description here

\documentclass{article} \usepackage{xcolor}% http://ctan.org/pkg/xcolor \usepackage{xlop}% http://ctan.org/pkg/xlop \newcommand{\placeholder}[1]{--}% Print -- regardless of the input \newcommand{\gobble}[1]{}% Print <nothing> regardless of the input \begin{document} \opmul{123}{456} \quad \opmul[resultstyle=\color{white}]{123}{456} \quad \opmul[resultstyle=\placeholder]{123}{456} \quad \opmul[resultstyle=\gobble,intermediarystyle=\placeholder,intermediarystyle.3=]{123}{456} \quad \opmul[resultstyle=\gobble,intermediarystyle=\gobble]{123}{456} \bigskip \opdiv{196}{8} \quad \opdiv[resultstyle=\color{white}]{196}{8} \quad \opdiv[resultstyle=\placeholder]{196}{8} \quad \opdiv[resultstyle=\gobble,remainderstyle.2=\placeholder]{196}{8} \quad \opdiv[resultstyle=\gobble,remainderstyle=\gobble]{196}{8} \end{document} 

Selective removal is obtained by adding an index to the intermediarystyle or remainderstyle based on the level. For example, intermediarystyle.1 refers to the style of the first intermediary step in the multiplication.

Note that styles act on elements individually. For example, resultstyle=\placeholder in the \opdiv{196}{8} example prints -- for each of 2, 4, . and 5.


If you want more control over the display created by xlop, you could create your construction and associated display macros:

enter image description here

\documentclass{article} \usepackage{pgf}% http://ctan.org/pkg/pgf \usepackage{xparse}% http://ctan.org/pkg/xparse \makeatletter \newcommand{\@op@top}[4]{% \begin{tabular}[t]{@{\ }c@{\hspace*{#1}}r} & \pgfmathprintnumber{#3} \\ \smash{\raisebox{.5\normalbaselineskip}{#2}} & \pgfmathprintnumber{#4} \\ \hline } \NewDocumentCommand{\@op@top@bottom}{m s O{1em} m m}{% \@op@top{#3}{#1}{#4}{#5}% \IfBooleanTF{#2}{}{% & \pgfmathsetmacro{\result}{#4\@@op#5}\pgfmathprintnumber{\result}% }% \end{tabular}% } \newcommand{\OpAdd}{\def\@@op{+}\@op@top@bottom{$+$}} \newcommand{\OpSub}{\def\@@op{-}\@op@top@bottom{$-$}} \newcommand{\OpMul}{\def\@@op{*}\@op@top@bottom{$\times$}} \newcommand{\OpDiv}{\def\@@op{/}\@op@top@bottom{$\div$}} \makeatother \setlength{\parindent}{0pt}% Just for this example \begin{document} \OpAdd{1234}{5678} \quad \OpAdd*{1234}{5678} \quad \OpAdd[2em]{1234}{5678} \par \bigskip \OpSub[1cm]{246}{135} \quad \OpSub*[2pt]{246}{135} \quad \OpSub{246}{135} \par \bigskip \OpMul{12}{13} \quad \OpMul*[3ex]{12}{13} \quad \OpMul*{12}{13} \par \bigskip \OpDiv*{1024}{16} \quad \OpDiv{1024}{16} \quad \OpDiv*[3ex]{1024}{16} \end{document} 

The above MWE provides \OpAdd, \OpSub, \OpMul and \OpDiv that all have the following format: \<macro>*[<len>]{<op1>}{<op2>} where the star * is optional. It sets <op1> and <op2> in a tabular with the appropriate operator. <len> manages the distance between the operator and the operands, while * regulates the display of the result/not (using pgf). Of course, other constructions for "division" is also possible.

6
  • This works wonderfully for \opadd and \opsub. How do you get rid of the solutions for \opmul and \opdiv Commented Jul 27, 2012 at 22:02
  • Also, FWIW,\opadd[resultstyle=\gobble,carrystyle=\gobble]{1234}{5678} \quad seems to be the best/most secure way to "white out" the solutions and still not have the place holders. Commented Jul 27, 2012 at 22:04
  • @jason: See my updated answer. Commented Jul 28, 2012 at 1:39
  • Sorry to be annoying, but the multiply and divide leave that whitespace where the information would otherwise be. Is there a way to get it to just be the problem without the whitespace pushing it down? Also, is there a way to get rid of the answer hline with the multiply? Commented Jul 30, 2012 at 20:57
  • @jason: See my updated answer for some manual construction of operations. Commented Jul 31, 2012 at 4:36

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.