I am typing elementary arithmetics, is there any one knows how to type this ?

enter image description here

I know perhaps there's a package "polynom" could solve this problem, but is there any method that could work without calling external packages?

Thank you.


Not going into deep explanations, but this uses only Plain TeX macros. ;-)



    \def\short@div@strut{\vrule width0pt height\ht\z@ depth\dp\z@}%


  \advance\dimen@ .5em
    % last step
  \dimen@=1em \ifdim\wd\z@>1em \dimen@=\wd\z@ \advance\dimen@ .5em \fi
  \vrule\kern-0.4pt\vtop{\hbox to \dimen@{$\,\short@div@strut#1$\hss}\hrule}%


enter image description here


Adapting my answer at Division with remainders displayed on side. EDITED to adapt its use to arguments with descenders AND to extend the horizontal rule length AND use math mode for the arguments AND to take box measurements in math mode AND extended the strutheight to the above line.

EDITED again to automate the indents. The indent is reset to 0pt following each invocation of \remainder{} or alternately by passing an optional [0] to the first invocation of \mydiv (the optional argument is the indent level).

EDITED to remove version that uses packages.

Here, I took the \stackengine macro, and condensed it down by hardwiring all the parameters to fit the current problem. Thus, I call it \dumbstackengine.

\def\rlwd{.5pt} \def\rlht{\dimexpr\dp\strutbox+\ht\strutbox} \def\rldp{.75ex}
        \setlength{\@boxshift}{\dimexpr-\dp\@anchorbox -\ht\@addedbox -#1}%
\mydiv{2}{a} \\
\mydiv{2}{b} \\
\mydiv{2}{c} \\
\mydiv{3}{d} \\
\mydiv{3}{e} \\
\mydiv{5}{34689} \\
\mydiv{5}{g} \\

enter image description here


Depending on your exact spacing needs some variation of the following might work.

\setbox\leftbox\hbox{#1}\unhcopy\leftbox\vrule height 2ex depth 1pt width .5pt
\setbox\rightbox\hbox{#2}\vrule height-.5pt depth1pt width\wd\rightbox\hskip-\wd\rightbox\unhcopy\rightbox\par}
  • This throws an error: ! Undefined control sequence. \div ...th\wd \rightbox \hskip -\wd \rightbox \un \^^Mhcopy\rightbox \par l.9 \div{2}{a} ? And the output is strange: 2Lhcopyj 3Lhcopyj 123Lhcopyj – AboAmmar Jul 10 '15 at 17:10
  • AboAmmar: fixed now – hkBst Jul 10 '15 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.