- // 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 << '*';
- }
- it->rest.print(c, precedence());
- ++it;
+void add::do_print_csrc(const print_csrc & c, unsigned level) const
+{
+ if (precedence() <= level)
+ c.s << "(";
+
+ // Print arguments, separated by "+" or "-"
+ char separator = ' ';
+ for (auto & it : seq) {
+
+ // If the coefficient is negative, separator is "-"
+ if (it.coeff.is_equal(_ex_1) ||
+ ex_to<numeric>(it.coeff).numer().is_equal(*_num_1_p))
+ separator = '-';
+ c.s << separator;
+ if (it.coeff.is_equal(_ex1) || it.coeff.is_equal(_ex_1)) {
+ it.rest.print(c, precedence());
+ } else if (ex_to<numeric>(it.coeff).numer().is_equal(*_num1_p) ||
+ ex_to<numeric>(it.coeff).numer().is_equal(*_num_1_p))
+ {
+ it.rest.print(c, precedence());
+ c.s << '/';
+ ex_to<numeric>(it.coeff).denom().print(c, precedence());
+ } else {
+ it.coeff.print(c, precedence());
+ c.s << '*';
+ it.rest.print(c, precedence());