# Error in polylongdiv while using spanish babel

I'm using polylongdiv from polynom package. When I use the option style=D I get

Runaway argument?

! Forbidden control sequence found while scanning use of \language@active@arg~. \par l.8 \polylongdiv[style=D]{x^5}{x^3+2x^2+9x+8} I suspect you have forgotten a }', causing me to read past where you wanted me to stop. I'll try to recover; but if the error is serious, you'd better type E' or X' now and fix your file.

I'm using Overleaf, and here is a MWE

\documentclass{article}

\usepackage[spanish]{babel}
\usepackage{polynom}

\begin{document}

\polylongdiv[style=D]{x^5}{x^3+2x^2+9x+8}

\end{document}

• Do \usepackage[spanish,es-notllde]{babel}; nowadays you can directly type ñ and Ñ, so the shorthands ~n and ~N are no longer needed. – egreg Oct 4 '20 at 12:01

You can use the es-notilde option to babel for nowadays the shorthands ~n and ~N are no longer needed, since you can directly type in ñ and Ñ.

\documentclass{article}

\usepackage[spanish,es-notilde]{babel}
\usepackage{polynom}

\begin{document}

\polylongdiv[style=D]{x^5}{x^3+2x^2+9x+8}

\end{document}


Alternatively, patch the relevant macro in polynom.sty that uses ~ (for no apparent reason) to replace it with \  (backslash-space):

documentclass{article}

\usepackage[spanish]{babel}
\usepackage{polynom}
\usepackage{regexpatch}

\makeatletter
\regexpatchcmd*{\pld@ArrangeResult}{\~}{\c{nobreakspace}}{}{}
\makeatother

\begin{document}

\polylongdiv[style=D]{x^5}{x^3+2x^2+9x+8}

\end{document}


The result is the same in both cases.

Use \shorthandoff*{~} in a group before the macro:

\documentclass{article}

\usepackage[spanish]{babel}
\usepackage{polynom}

\begin{document}

{\shorthandoff*{~}
\polylongdiv[style=D]{x^5}{x^3+2x^2+9x+8}}

\end{document}
`