Skip to content

Commit

Permalink
clean up TeX and MathML converter
Browse files Browse the repository at this point in the history
  • Loading branch information
axkr committed Nov 7, 2017
1 parent 9eadc83 commit f132506
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.text.NumberFormat;
import java.util.HashMap;

import org.hipparchus.fraction.BigFraction;
//import org.hipparchus.fraction.BigFraction;
import org.matheclipse.core.basic.Config;
import org.matheclipse.core.convert.AST2Expr;
import org.matheclipse.core.eval.EvalAttributes;
Expand Down Expand Up @@ -106,13 +106,13 @@ public void convertFraction(final StringBuilder buf, final IRational f, final in
tagEnd(buf, "cn");
}

public void convertFraction(final StringBuilder buf, final BigFraction f, final int precedence) {
tagStart(buf, "cn", "type=\"rational\"");
buf.append(String.valueOf(f.getNumerator().toString()));
tagStartEnd(buf, "sep");
buf.append(String.valueOf(f.getDenominator().toString()));
tagEnd(buf, "cn");
}
// public void convertFraction(final StringBuilder buf, final BigFraction f, final int precedence) {
// tagStart(buf, "cn", "type=\"rational\"");
// buf.append(String.valueOf(f.getNumerator().toString()));
// tagStartEnd(buf, "sep");
// buf.append(String.valueOf(f.getDenominator().toString()));
// tagEnd(buf, "cn");
// }

@Override
public void convertComplex(final StringBuilder buf, final IComplex c, final int precedence) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.matheclipse.core.form.tex;

import java.math.BigInteger;
import java.text.NumberFormat;
import java.util.HashMap;

import org.hipparchus.fraction.BigFraction;
//import org.hipparchus.fraction.BigFraction;
import org.matheclipse.core.basic.Config;
import org.matheclipse.core.convert.AST2Expr;
import org.matheclipse.core.expression.F;
Expand Down Expand Up @@ -140,24 +139,24 @@ public void convertFraction(final StringBuilder buf, final IFraction f, final in
}
}

public void convertFraction(final StringBuilder buf, final BigFraction f, final int precedence) {
boolean negative = f.compareTo(BigFraction.ZERO) < 0;
if (negative && (precedence > plusPrec)) {
buf.append("\\left( ");
}
if (f.getDenominator().equals(BigInteger.ONE)) {
buf.append(f.getNumerator().toString());
} else {
buf.append("\\frac{");
buf.append(f.getNumerator().toString());
buf.append("}{");
buf.append(f.getDenominator().toString());
buf.append('}');
}
if (negative && (precedence > plusPrec)) {
buf.append("\\right) ");
}
}
// public void convertFraction(final StringBuilder buf, final BigFraction f, final int precedence) {
// boolean negative = f.compareTo(BigFraction.ZERO) < 0;
// if (negative && (precedence > plusPrec)) {
// buf.append("\\left( ");
// }
// if (f.getDenominator().equals(BigInteger.ONE)) {
// buf.append(f.getNumerator().toString());
// } else {
// buf.append("\\frac{");
// buf.append(f.getNumerator().toString());
// buf.append("}{");
// buf.append(f.getDenominator().toString());
// buf.append('}');
// }
// if (negative && (precedence > plusPrec)) {
// buf.append("\\right) ");
// }
// }

@Override
public void convertComplex(final StringBuilder buf, final IComplex c, final int precedence) {
Expand Down Expand Up @@ -304,10 +303,10 @@ public void convert(final StringBuilder buf, final Object o, final int precedenc
convertSymbol(buf, (ISymbol) o);
return;
}
if (o instanceof BigFraction) {
convertFraction(buf, (BigFraction) o, precedence);
return;
}
// if (o instanceof BigFraction) {
// convertFraction(buf, (BigFraction) o, precedence);
// return;
// }
convertString(buf, o.toString());
}

Expand Down

0 comments on commit f132506

Please sign in to comment.