Math & Sciencepolynom.sty : How to give more spaces in Horner Diagram?

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

polynom.sty : How to give more spaces in Horner Diagram?

Post by yoyoimut »

My problem happens only when the divisor is in the form of $ax+b$.


Here is the description of colors I used in the figure below:

Legend:
Red Circle : the top of vertical line needs to be shorten.
Red Rectangle: the bottom part of the separation line needs to be removed.

Blue Rectangle: Need more spaces "between fractions" or "between a line and a number".
horner.jpg
horner.jpg (88.78 KiB) Viewed 2158 times


Here is the modified code that is done by localghost several weeks ago.
localghost successfully changed the ) to |.

Code: Select all

\documentclass[a4paper,twoside,11pt,final,dvips]{book}
\usepackage[nomath]{kpfonts}

\usepackage{polynom}

\makeatletter
\def\pld@ArrangeResult#1{%
    \ifx\pld@remainder\@empty
        \@tempcnta\pld@maxcol\relax
        \pld@InsertItems@do\pld@lastline
            {\pld@firsttrue\pld@PLD{\pld@R{0}{1}}}%
    \fi
    \ifnum\pld@currstage>\z@
        \pld@Extend\pld@allines{\pld@lastline\cr}%
    \else
        \pld@InsertFake\pld@lastline
    \fi
    \pld@iftopresult
        \def\pld@lastline{\pld@PrintPoly\pld@divisor\,\smash{\Big|}\kern-2pt&}%
    \else
        \let\pld@lastline\@empty
        \ifx B\pld@style\else
            \def\pld@lastline{\pld@leftdelim\strut\pld@rightxdelim&}%
        \fi
    \fi
    \expandafter\pld@AR@col\expandafter\pld@PLD
                           \expandafter\pld@lastline#1+\relax+%
    \pld@SplitQuotient
    \pld@iftopresult
        \let\pld@currentline\@empty
        \expandafter\pld@AR@col\expandafter\pld@PLD
                               \expandafter\pld@currentline
                                           \pld@quotient+\relax+%
        \expandafter\pld@AR@col\expandafter\pld@XPLD
                               \expandafter\pld@currentline
                                           \pld@shadow+\relax+%
        \edef\pld@subline{%
            \noexpand\cline{\tw@-\pld@maxcol}%
            \noalign{\vskip\jot}}%
        \pld@Extend\pld@currentline{\expandafter\cr\pld@subline}%
    \else
        \@tempcnta-\@tempcnta
        \advance\@tempcnta\pld@maxcol\relax \advance\@tempcnta\@ne
        \edef\pld@span{\the\@tempcnta}%
        \ifx B\pld@style
          \pld@AddTo\pld@lastline{%
            &\multispan\pld@span${}=%
            \pld@PrintPolyWithDelims\pld@divisor
            \expandafter\pld@IfSum\expandafter{\pld@divisor}{}{\cdot}%
            \expandafter\pld@IfSum\expandafter{\pld@quotient}\pld@true
                                                             \pld@false
            \pld@if \pld@leftdelim
                    \pld@PrintPolyShadow
                    \pld@rightdelim
              \else \pld@PrintPolyShadow \fi
            \pld@firstfalse
            \expandafter\pld@PrintRemain\expandafter{\pld@remainder}$}%
        \else
          \pld@AddTo\pld@lastline{%
            &\multispan\pld@span$\pld@leftxdelim\strut\pld@rightdelim
            \pld@div
            \pld@PrintPolyWithDelims\pld@divisor=
            \pld@PrintPolyShadow
            \ifx\pld@remainder\@empty\else
                +{}%
                \setbox\z@=\hbox{$\displaystyle
                  \frac{\let\strut\@empty\pld@firsttrue \expandafter
                        \pld@PrintRemain\expandafter{\pld@remainder}}%
                       {\let\strut\@empty\pld@PrintPoly\pld@divisor}$}%
                \dp\z@=\z@\box\z@
            \fi
            $}%
        \fi
    \fi
\expandafter\pld@AR@\pld@allines\relax}
\makeatother

\begin{document}
\polylongdiv[style=A]{3x^3+x^2-1}{2x-1}

\polylongdiv[style=A]{3x^3+x^2-1}{x-1}
\end{document}
Now, I need some adjustments due to $ax+b$.

Maybe I need to 2 separate commands, one for $x+c$ and the other one for $ax+b$.
Using optional arguments (default: $x+c$) is also a good idea.


Please help me as my knowledge in TEX is still not enough to dissect the source code of the package.

Thank you in advance.



regards,

Yuko

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

polynom.sty : How to give more spaces in Horner Diagram?

Post by localghost »

The structures of the polynom package have once been modified to your wishes at that time [1]. The first part (red) would be easy, but the second part (blue) is more complicated. So I suggest to contact the package maintainer and ask for the necessary accommodations and supplements. Afterwards feel free to report new insights here.

And by the way, the representation in the picture is not a Horner scheme.

[1] View topic: Changing the brace »)« to a pipe »|« in polynom package


Best regards
Thorsten
Post Reply