# What is the simplest way to make a command that produces a quadratic expression?

I want to have a command that accepts 1 optional argument and 3 mandatory ones.

Example:

1. \qe{a}{b}{c} produces ax^2+bx+c
2. \qe[y]{-1}{0}{-c} produces -y^2-c

How to make this command?

-

\documentclass{article}
\usepackage{polynomial}

\begin{document}
$\polynomial{\frac12,0,-1,1}$

$\polynomial[reciprocal]{\frac12,0,-1,1}$
\end{document}

See manual of polynomial for more options.

http://www.ctan.org/tex-archive/help/Catalogue/entries/polynomial.html

-
I think this one should be the accepted answer. –  Ryan Reich Jan 22 '11 at 16:37
Worth also to have a look at ctan.org/tex-archive/macros/latex/contrib/cool –  Yiannis Lazarides Jan 22 '11 at 16:55
@Yiannis: Yes. cool package is rather useful for those who use special math functions heavily. However, it doesn't deal with such polinomials. –  Leo Liu Jan 22 '11 at 17:22
\documentclass{article}
\usepackage{amsmath}

\def\MinusOne{-1}
\newcommand\qec[4][x]{%
\ifx\relax#2\relax\else\def\temp{#2}
\ifx\temp\MinusOne -\else #2\fi#1^2\fi
\ifx\relax#3\relax\else\def\temp{#3}
\ifx\temp\MinusOne -\else+#3\fi#1\fi
\ifx\relax#4\relax\else+ #4\fi}
\begin{document}

\begin{align}
\qec{a}{b}{c}\\
\qec[y]{-1}{}{-c}\\
\qec[y]{-1}{}{}\\
\qec{}{1}{2}
\end{align}

\end{document}
-
@xport: see edit. However, it makes no real sense, because it becomes more and more complecated. +-c and +1x is also not a nice output. It is easier to type it as it is ... –  Herbert Jan 22 '11 at 16:24
The only one of your test cases which actually looks right is the first. –  Ryan Reich Jan 22 '11 at 16:36
@Ryan, edited the code –  Herbert Jan 22 '11 at 17:24

what about what follows as a first attempt:

\documentclass{book}
\newcommand{\qec}[4]{#1 #4^2 + #2 #4+ #3}
\begin{document}
$$\qec{a}{b}{c}{y}$$
$$\qec{1}{2}{3}{p}$$
\end{document}
-