# Hide solution when using xlop

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?

-

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:

\documentclass{article}
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{xlop}% http://ctan.org/pkg/xlop
\begin{document}
\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:

\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}
\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.

\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[resultstyle=\gobble,intermediarystyle=\gobble]{123}{456}

\bigskip

\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:

\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}

\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

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.