I generally am fine with using the \polylongdiv{<dividend>}{<divisor>} macro from the polynom package: \polylongdiv{6x^3 + 5x^2 - 7}{3x^2 - 2x - 1}

but I was wondering,

How do I programmatically typeset Polynomial Long Division with connected parenthesis and line? (Possibly using TikZ)

Similar to this TeX.SX answer which is implemented in the longdivision package for arithmetic long division.

enter image description here

but also programmatically typeset the whole division process like \polylongdiv and preferably make the parenthesis curve look centered(?) with respect to the divisor and flush left the quotient result on top / align with the leading coefficient of the dividend.

How can I achieve and define this, let's say, \mypolylongdiv{<dividend>}{<divisor>} macro? Thank you.


1 Answer 1


Short answer:


        \coordinate (A) at (0,-3pt);
        \coordinate (B) at (0,\normalbaselineskip-0.8pt);
        \draw (A) to[in=-40, out=40, looseness=1] (B);




enter image description here

Detailed answer:

In order to figure out how to solve the problem, you might need to look up the source code to see how it's implemented in the first place.

Obviously, by default it prints just a parenthesis ), so I decided to make a simple search with ) query in


your path with installed latex packages might differ though

Apparently, in the source code there are no that much parentheses, so I managed to locate it pretty quickly

enter image description here

so now it's only the matter of changing that bit. Since it sits inside the definition of the whole \pld@ArrangeResult command you have to paste that whole chunk of code with whole definition of that command in your preamble and adding the desired changes, replacing that


Alternatively, there is a way to avoid that copy pasting by using \patchcmd command from etoolbox package


It allows to find and replace the searched part and redefine the whole command automatically.

Now let's talk about the implementation the visual changes. As you suggested I used tikz for that because you have much more control on the line drawing and the behavior itself.

You can adjust in, out, looseness parameters in the path to achieve the desired curve. Here are some examples

\draw (A) to[in=-20, out=20, looseness=1.5] (B);

enter image description here

\draw (A) to[in=-50, out=20, looseness=1] (B);

enter image description here

\draw (A) to[in=-15, out=45, looseness=1] (B);

enter image description here

Also you can tweak (A) coordinate to make the curve look centered as you wish

\coordinate (A) at (0,-5pt);

enter image description here

\coordinate (A) at (0,0);

enter image description here

  • Thank you so much! Commented Jun 30, 2022 at 4:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .