# How to display the greatest common divisor by long division?

How can I draw the following scheme?

Something like this?

\documentclass{article}
\usepackage{array,booktabs}
\newcommand\ml[1]{\multicolumn{1}{l}{#1}}
\newcommand\lparen{\mkern1mu(\mkern1mu}
\newcommand\rparen{\mkern1mu)\mkern1mu}
\newcommand\pp{\phantom{\lparen}}

\begin{document}
$\setlength\arraycolsep{0pt} \begin{array}{ *{11}{r} } 198 & \rparen & 360 & \lparen & \ml{1} \\ && 198 & \pp \\ \cmidrule{3-4} && 162 & \rparen & 198 & \lparen & \ml{1} \\ &&&& 162 & \pp \\ \cmidrule{5-6} &&&& 36 & \rparen & 162 & \lparen & \ml{4} \\ &&&&&& 144 & \pp \\ \cmidrule{7-8} &&&&&& 18 & \rparen & 36 & \lparen & \ml{2} \\ &&&&&&&& 36 & \pp\\ \cmidrule{9-10} &&&&&&&& \multicolumn{2}{c}{\times} \end{array}$
\end{document}

• Thanks, It works. May 7, 2020 at 10:33

This is typical example for doing macros recursive:

\def\divi #1)#2/#3=#4{#1)%
\vtop{\hbox{#2}\hbox{#3}\smallskip\hrule width1.5em\smallskip\hbox{#4}}}
\def\0{\phantom0}

\divi 198)360(1/190={%
\divi 162)198(1/162={%
\divi \036)162(4/144={%
\divi \018)36(2/36={%
$\0\times$}}}}

\bye