- // Then proceed with the remaining factors
- epvector::const_iterator it = seq.begin(), itend = seq.end();
- while (it != itend) {
- coeff = ex_to<numeric>(it->coeff);
- if (!first) {
- if (coeff.csgn() == -1) c.s << '-'; else c.s << '+';
- } else {
- if (coeff.csgn() == -1) c.s << '-';
- first = false;
- }
- if (!coeff.is_equal(_num1()) &&
- !coeff.is_equal(_num_1())) {
- if (coeff.is_rational()) {
- if (coeff.is_negative())
- (-coeff).print(c);
- else
- coeff.print(c);
- } else {
- if (coeff.csgn() == -1)
- (-coeff).print(c, precedence());
- else
- coeff.print(c, precedence());
- }
- if (is_a<print_latex>(c))
- c.s << ' ';
- else
- c.s << '*';
- }
+void add::do_print_csrc(const print_csrc & c, unsigned level) const
+{
+ if (precedence() <= level)
+ c.s << "(";
+
+ // Print arguments, separated by "+"
+ epvector::const_iterator it = seq.begin(), itend = seq.end();
+ while (it != itend) {
+
+ // If the coefficient is -1, it is replaced by a single minus sign
+ if (it->coeff.is_equal(_ex1)) {
+ it->rest.print(c, precedence());
+ } else if (it->coeff.is_equal(_ex_1)) {
+ c.s << "-";
+ it->rest.print(c, precedence());
+ } else if (ex_to<numeric>(it->coeff).numer().is_equal(_num1)) {
+ it->rest.print(c, precedence());
+ c.s << "/";
+ ex_to<numeric>(it->coeff).denom().print(c, precedence());
+ } else if (ex_to<numeric>(it->coeff).numer().is_equal(_num_1)) {
+ c.s << "-";
+ it->rest.print(c, precedence());
+ c.s << "/";
+ ex_to<numeric>(it->coeff).denom().print(c, precedence());
+ } else {
+ it->coeff.print(c, precedence());
+ c.s << "*";