How to make a traditional division
One option would be to use the xlop
package:
\documentclass{report}
\usepackage{xlop}
\begin{document}
\opidiv{25}{7}\qquad\opdiv{25}{7}
\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}
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
.