# polynom division without package polynom

I am quite new to TeX, so i don't know how to represent polynom division in latex. I can't use package polynom, since I don't have a polynom with numbers so this is a generic solution for this fraction (x_1^n-x_0^n)/(x_1-x_0)

I would appreciate some help to represent this somehow like this:

A similar question was answered there: How to draw polynom division? but i want to picture polynom division in more convinient style

like the package polynom does it and don't know how to tune that solution for my purposes

This is using the under-development tabstackengine package, first introduced here at Writing a table with equally spaced columns, based on the widest column (source code available at Measuring align).

The package extends the stackengine package by adding tabbing capability. This answer, Can I tab inside of align environment?, gives some of the syntax of the package. I apologize that I have been lax in completing the package and getting it out the door, so the only way to see it in action is by searching this site for tabstackengine.

In this particular answer, I set up the polynomial division with a tabular stack, where I set the alignments of each column. The only twist is the introduction of the macro \rl{} which give a rule corresponding to the typeset contents of the mathematical argument (extended with a llap and \rlap to make smooth transitions).

The answer below has been EDITED in response to Barbara'a comment, through a redefinition of \rl{}. My earlier solution artificially extended the horizontal gap between stacked columns, which was a proper criticism. An additional criticism levied had to do with the unequal spacings around the math operators. To a large extent, this edit corrects much of that. However, residual asymmetries about the - and + characters are notably due to the alignment requirements of the columns. For example, in the middle rows, there is more space prior to the 7x than after the preceding -x^2. This occurs because the 7x must achieve right-alignment with the somewhat wider (4x three rows later. In essence, mathrel spacings are sacrificed in order to maintain column alignments, which is considered essential to this problem.

\documentclass{article}
\usepackage{fixltx2e}
\usepackage{tabstackengine}
\stackMath
\newsavebox\tempbox
\newlength\templen
\def\rl#1{%
\sbox\tempbox{$#1$}%
\setlength\templen{\wd\tempbox}%
\llap{\rule{1.5pt}{.1ex}}\rule{\templen}{.1ex}\rlap{\rule{1.5pt}{.1ex}}}
\setstacktabulargap{0pt}
\begin{document}
\tabularShortstack{crcrcrcrl}{
&(3x^3&-&10x^2&+&7x &-&12&): (x-3) = 3x^2 -x + 4\\
-&(3x^3&-&9x^2 &)&   & &  &\\
\rl{-}&\rl{(3x^3}&\rl{-}&\rl{-(x^2}&\rl{+}&&&&\\
&     & &-x^2 &+&7x & &  &\\
&     &-&(-x^2&+&3x &)&  &\\
&&\rl{-}&\rl{-(x^2}&\rl{+}&\rl{(7x}&\rl{-}&&\\
&     &&      & &4x &-&12&\\
&     &&      &-&(4x&-&12&)\\
&&&&\rl{+}&\rl{(7x}&\rl{-}&\rl{12}&\rl{)}\\
&&&&&&&0&
}
\end{document}


Here is an example of another problem cited by the OP. The only differences here were the need to use \rlap if an entry was to be allowed to cross column boundaries, and I also changed the column alignment to l for the polynomial entries, as opposed to r in the last example, which had constant coefficients.

\documentclass{article}
\usepackage{fixltx2e}
\usepackage{tabstackengine}
\stackMath
\newsavebox\tempbox
\newlength\templen
\def\rl#1{%
\sbox\tempbox{$#1$}%
\setlength\templen{\wd\tempbox}%
\llap{\rule{2.1pt}{.1ex}}\rule{\templen}{.1ex}\rlap{\rule{2.1pt}{.1ex}}}
\setstacktabulargap{0pt}
\begin{document}
\tabularShortstack{crllclcl}{
&(x^n&-&x_0^n&)%
\rlap{$:(x-x_0) = x^{n+1} + x_0x^{n-2} + x_0^2x^{n-3} + \ldots$}&&&\\
-&(x^n&-&x_0x^{n-1} &)&   & &\\
\rl{-}&\rl{(x^n}&\rl{-(}&\rl{(x_0x^{n-1}}&\rl{+}&&&\\
&     & &x_0x^{n-1} &-&x_0^n & &\\
&     &-(&x_0x^{n-1}&-&x_0^2x^{n-2} &)&\\
&&\rl{-(}&\rl{(x_0x^{n-1}}&\rl{+}&\rl{x_0^2x^{n-2}}&\rl{-}&\\
&     &&      & &x_0^2x^{n-2}&-&x_0^n\\
\rule{0ex}{3ex}&&&&&\rlap{...................}&&
}
\end{document}


• there-s really too much space after many of the minus signs. both operations and unary minus signs are affected. – barbara beeton Jan 23 '14 at 16:50
• @barbarabeeton Please see edited answer. – Steven B. Segletes Jan 23 '14 at 18:23
• Thanks for answering my question! I wonder though if I can put that minus sign between the lines? – Danny Lo Jan 23 '14 at 18:28
• @DanyloEsterman You are most welcome. What do you mean "between the lines"? Do you mean to shift the leading minus vertically, horizontally, or something completely different? – Steven B. Segletes Jan 23 '14 at 18:30
• better. not perfect, but i expect the extra space between minus/plus signs and a following element is an accommodation to line up with later lines that have parentheses in those locations. still, the initial minus signs pre-parentheses should really be spaced as unary, not binary; that would compensate somewhat for the extra space inserted on account of the open parentheses. (this is rather a tricky situation, and you may have already made the best of it.) – barbara beeton Jan 23 '14 at 18:44