# How to make a traditional division

How to make the traditional division? Like that:

a |b_
r  c
-
possible duplicate of Decimal Long Division – Werner May 13 '13 at 2:37
@Werner I don't think this is really a duplicate; in a comment to my answer Fabricio specified that he needed a manual way to represent the division, so the xlop option (which is the suggestion in the possible duplicate) was not really an option in this case. – Gonzalo Medina May 13 '13 at 2:59

One option would be to use the xlop package:

\documentclass{report}
\usepackage{xlop}

\begin{document}

\end{document}

Manually, you can use an array:

\documentclass{article}

\newcommand\myrule[1]{\multicolumn{1}{| l}{#1}}

\begin{document}

$\begin{array}{rl} 478 & \myrule{7} \\ \cline{2-2} 58 & 68 \\ 2 \end{array}$

\end{document}

If you are only interested in the dividend, divisor, quotient and remainder, you can define a two-argument command (quotient and remainder can be automatically calculated) along the lines of

\documentclass{article}
\usepackage{intcalc}

\newcommand\mydiv[2]{%
\ifnum#2>0
$\renewcommand\arraystretch{1.2} \begin{array}{@{}r | l} #1 & #2 \\ \cline{2-2} \multicolumn{1}{r}{\intcalcMod{#1}{#2}} & \ifnum#1>0\relax \intcalcDiv{#1}{#2} \else \number\numexpr\intcalcDiv{#1}{#2}-1\relax \fi \end{array}$
\else
\GenericWarning{}{Division Warning: "Please provide a positive integer as divisor"}
\fi
}

\begin{document}

\mydiv{478}{7}

\end{document}

-
I actualy need the manual way. Because i'm using an online latex editor to generate my outputs. – Fabricio May 13 '13 at 1:25
@Fabricio please see my updated answer. – Gonzalo Medina May 13 '13 at 1:33
Thanks......!!! – Fabricio May 13 '13 at 1:38
@Fabricio You're welcome! I did another update to my answer taht could be of interest to you. – Gonzalo Medina May 13 '13 at 1:42
@GonzaloMedina \numexpr division rounds: try \mydiv{478/8} – egreg May 13 '13 at 8:22

For the simple diagrams you can do in this way:

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\division}{smm}
{
\IfBooleanTF{#1}
{ \fabricio_division_inline:nn { #2 } { #3 } }
{ \fabricio_division:nn { #2 } { #3 } }
}

\cs_new:Npn \fabricio_division_inline:nn #1 #2
{
#1=#2\cdot\int_div_truncate:nn { #1 } { #2 }
+ \int_mod:nn { #1 } { #2 }
}
\cs_new_protected:Npn \fabricio_division:nn #1 #2
{
\begin{array}{r | l}
#1 & #2 \\
\cline{2-2}
\multicolumn{1}{r}{\int_mod:nn { #1 } { #2 }} &
\int_div_truncate:nn { #1 } { #2 }
\end{array}
}
\ExplSyntaxOff

\begin{document}
$\division*{1234}{42} \qquad \division{1234}{42}$
\end{document}

The *-form just prints the division in the form a=bq+r.

-