TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


  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?

share|improve this question
up vote 13 down vote accepted



alt text

See manual of polynomial for more options.


share|improve this answer
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

    \ifx\temp\MinusOne -\else #2\fi#1^2\fi
    \ifx\temp\MinusOne -\else+#3\fi#1\fi
  \ifx\relax#4\relax\else+ #4\fi}


share|improve this answer
@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:

\newcommand{\qec}[4]{#1 #4^2 + #2 #4+ #3}
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.