# Drawing a circle around the numbers in xlop package

I am writing something about base conversion (from decimal system to other bases). I am using the xlop package for producing a sequence of long divisions. The result is good, but it would be perfect if I could draw a circle around the remainders (and the last division's quotient) which are the digits of the converted number. That is, I want something like this:

My code is

    \begin{align*}
\opidiv[displayintermediary=all,voperation=top]{196101}{16}
\opidiv[displayintermediary=all,voperation=top]{12256}{16}
\opidiv[displayintermediary=all,voperation=top]{766}{16}
\opidiv[displayintermediary=all,voperation=top]{47}{16}
\end{align*}


I know there are should be methods like using pstricks and such packages, but I do not know how to use them. I hope someone helps me in this.

Here is a solution with TiKz that uses the stylization of digits allowed by xlop with operandstyle, remainderstyle parameters.

With xlop, when the style of a digit is applied by a macro, the last argument (the digit to be stylized) is provided by xlop itself to this macro.

Thus, the macro is declared with 2 arguments, but only the first one is provided to its call, xlop itself providing the last one.

I created two macros:

• The first macro called \chiffre creates a node centered on the digit itself with TiKz.
• the second one called \entoure creates a shape node that surrounds both nodes given as arguments. It uses the tikz libraries fit and shapes.

These commands require a double compilation to place the nodes in the right place.

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{fit,shapes}
\usepackage{xlop}

\newcommand{\chiffre}[2]{\tikz[remember picture] \node[inner sep=0pt](#1){#2};}

\newcommand{\entoure}[2]{\tikz[remember picture,overlay] \node[preaction={draw=black,ultra thick,opacity=.2,
transform canvas={xshift=1.5pt,yshift=-1.5pt}},draw,ellipse,ultra thick,inner sep=.5em,fit=(#1.center)(#2.center)]{} ;}

\begin{document}

\begin{align*}
\opidiv[displayintermediary=all,voperation=top,remainderstyle.5.1=\chiffre{A}]{196101}{16}
\entoure{A}{A}
\opidiv[displayintermediary=all,voperation=top,remainderstyle.3=\chiffre{B}]{12256}{16}
\entoure{B}{B}
\opidiv[displayintermediary=all,voperation=top,remainderstyle.2.1=\chiffre{C},remainderstyle.2.2=\chiffre{D}]{766}{16}
\entoure{C}{D}
\opidiv[displayintermediary=all,voperation=top,remainderstyle.1.1=\chiffre{E},remainderstyle.1.2=\chiffre{F},resultstyle.1=\chiffre{G}]{47}{16}
\entoure{F}{E}
\entoure{G}{G}
\end{align*}

\end{document}


Output:

Actually, it's not easy. Draw a circle (or an ellipse) around one digit is straight (with pstricks and I'm sure with TikZ too). Draw an ellipse around two digits is more difficult since there are plenty operations between type a digit and type the next one. Here is a possible answer:

\documentclass{article}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage{xlop}

\begin{document}

\begin{center}
\psset{boxsep=false,framesep=1pt, linecolor=red, linewidth=1.5pt}
\opset{displayintermediary=all, voperation=top}%
\opidiv[remainderstyle.5=\psovalbox]{196101}{16}%
\opidiv[remainderstyle.3=\psovalbox]{12256}{16}%
\opidiv[remainderstyle.2.1={\pnode(-1.5\opcolumnwidth,0.5ex){L}},
remainderstyle.2.2={\pnode(2.2\opcolumnwidth,0.5ex){R}}]
{766}{16}%
\psRelNode(L)(R){0.5}{M}
\psccurve(L)([offset=-1.5ex]M)(R)([offset=1.5ex]M)