Long Division of Polynomials in LyX

I look here for a way to show a long division of polynomials, and I read here about polynom.sty, but my question is if there is a way that I can write the whole division and not just give two polynomials as input.

i.e. I'm looking for a way to write a long division of polynomials.

If you have any suggestions I'd like to read!!

P.S. I'm using LyX.

• If you're OK with writing it in ERTs you could look at tex.stackexchange.com/a/82027 or tex.stackexchange.com/a/79254 – Torbjørn T. Jan 10 '14 at 8:20
• Thank you @TorbjørnT. but I look for I way to write it by myself. At the first link the problem is that it's not clear... (it little it complicated...). There is no simpler way? – heblyx Jan 10 '14 at 8:40
• Both of those solutions use an array, so you could of course create an array via the LyX GUI, i.e. Insert --> Math --> Array environment. – Torbjørn T. Jan 10 '14 at 8:52
• @TorbjørnT. Thank you! but How I made the lines? This is what I look for: A way to write the long division at the array. But how can I do this? Thank you! – heblyx Jan 10 '14 at 9:55
• Hm. From a quick glance at LyX, there doesn't seem to be a way of adding a \cline in an array via the GUI. You can achieve the same effect in a normal tabular, but I didn't immediately see a way with array. Have to look at this later, don't really have time right now. – Torbjørn T. Jan 10 '14 at 10:21

I know its not the nicest way to do this, but here we go...

(I tried some time ago to find a nicer way and failed. I give you my improvised result)

Just enter the polynomials into a regular table, and use separating lines for the top and side. In LyX it looks like this:

and after compilation it looks like this:

This might help you get started, if you don't mind doing the algebra yourself.

\documentclass{article}
\usepackage{mathtools}
\usepackage{xspace,xcolor}
\usepackage[display]{texpower}
\usepackage[screen,nopanel]{pdfscreen}

\margins{0.25in}{0.25in}{0.25in}{0.25in}
\screensize{4.5in}{6in}
\backgroundcolor{lightgray}

\newcommand{\ldsym}{$\left.\mathstrut\right)$}% unbalanced )
\newlength{\ldwidth}

\newcommand{\longdivide}[2]% #1 = denominator, #2 = numerator
{\settowidth{\ldwidth}{\ldsym}
$#1\,\raisebox{1.5pt}{\ldsym}\hspace*{-.65\ldwidth}\overline{ \mathstrut\hspace*{.35\ldwidth}\ #2}$}

\begin{document}
\stepwise{
\begin{center}
\begin{tabular}{r}
\bstep[\value{step}=1]{$7x$}\bstep[\value{step}=4]{$\strut+8$}\\
\longdivide{x^{2}-4x+1}{7x^{3}-20x^{2}-25x+8}\\
\bstep[\value{step}=2]{\underline{$7x^3-28x^2+7x$}}\hphantom{$\strut+8$}\\
\bstep[\value{step}=3]{$8x^2-32x+8$}\\
\bstep[\value{step}=5]{$8x^2-32x+8$}
\end{tabular}
\end{center}
}
\end{document}


As far as I can see, there is no way to use \cline in an array environment via the LyX GUI. Therefore, to use the GUI to create the table-like structure, one has to use a tabular: Insert --> Table. It is not an ideal solution, as each cell has to be placed in (inline) math mode. The code below is a .lyx file with an example, copy the code into a text editor and save the file as something.lyx.

Things to note:

• I don't know if this is the kind of layout you'd like.
• The lines are added via the table toolbar, just select the cells you want underlined, and click the appropriate button.
• The intercolumn spacing has been removed from some of the columns, by adding a custom column declaration in the table settings. Right click a cell --> More ... --> Settings. In the LaTeX argument box you'll see something like @{}r, which creates a right aligned column with the column padding before the column removed.
• The empty braces ({}) before the plus signs is to ensure the right spacing. When writing $+4$, the plus is a unary relation, while with ${}+4$ it is a binary relation, which you want.
• I added a phantom ) in row 1, column 2, as in Peter Grill's answer, to improve alignment.
#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\textclass article
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman default
\font_sans default
\font_typewriter default
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100

\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry false
\use_amsmath 1
\use_esint 1
\use_mhchem 1
\use_mathdots 1
\cite_engine basic
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\use_refstyle 1
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false

\begin_body

\begin_layout Standard
\begin_inset Tabular
<lyxtabular version="3" rows="5" columns="4">
<features tabularvalignment="middle">
<column alignment="center" valignment="top" width="0pt" special="@{}r">
<column alignment="center" valignment="top" width="0pt" special="@{}r">
<column alignment="center" valignment="top" width="0pt" special="@{}r@{}">
<column alignment="center" valignment="top" width="0pt" special="l">
<row>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\begin_inset Formula $x^{2}$
\end_inset

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\begin_inset Formula ${}+4x\phantom{)}$
\end_inset

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\begin_inset Formula ${}+4$
\end_inset

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\begin_inset Formula ${}:x+2=x+2$
\end_inset

\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\begin_inset Formula $-(x^{2}$
\end_inset

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\begin_inset Formula ${}+2x)$
\end_inset

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\begin_inset Formula $2x$
\end_inset

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\begin_inset Formula ${}+4$
\end_inset

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\begin_inset Formula $2x$
\end_inset

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\begin_inset Formula ${}+4$
\end_inset

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\begin_inset Formula $0$
\end_inset

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset

\end_layout

\end_body
\end_document
`

Use table and borders. In LyX:

PDF output:

(After looking around on the web for some time, this was the easiest and nicest solution I could find. It was based on DalyaG's answer.)