use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class List method convert.
/** {@inheritDoc} */
public boolean convert(final StringBuffer buf, final IAST ast, final int precedence) {
int[] dims = ast.isMatrix();
if (dims != null) {
// create a LaTeX matrix
buf.append("\\left(\n\\begin{array}{");
for (int i = 0; i < dims[1]; i++) {
buf.append("c");
}
buf.append("}\n");
if (ast.size() > 1) {
for (int i = 1; i < ast.size(); i++) {
IAST row = ast.getAST(i);
for (int j = 1; j < row.size(); j++) {
fFactory.convert(buf, row.get(j), 0);
if (j < row.size() - 1) {
buf.append(" & ");
}
}
if (i < ast.size() - 1) {
buf.append(" \\\\\n");
} else {
buf.append(" \n");
}
}
}
buf.append("\\end{array}\n\\right) ");
// \begin{pmatrix} x & y \\ u & v \end{pmatrix}
// buf.append("\\begin{pmatrix} ");
// if (ast.size() > 1) {
// for (int i = 1; i < ast.size(); i++) {
// IAST row = ast.getAST(i);
// for (int j = 1; j < row.size(); j++) {
// fFactory.convert(buf, row.get(j), 0);
// if (j < row.size() - 1) {
// buf.append(" & ");
// }
// }
// if (i < ast.size() - 1) {
// buf.append(" \\\\ ");
// }
// }
// }
// buf.append(" \\end{pmatrix} ");
} else if ((ast.getEvalFlags() & IAST.IS_VECTOR) == IAST.IS_VECTOR) {
// create a LaTeX row vector
// \begin{pmatrix} x & y \end{pmatrix}
buf.append("\\begin{pmatrix} ");
if (ast.size() > 1) {
for (int j = 1; j < ast.size(); j++) {
fFactory.convert(buf, ast.get(j), 0);
if (j < ast.size() - 1) {
buf.append(" & ");
}
}
}
buf.append(" \\end{pmatrix} ");
} else {
buf.append("\\{");
if (ast.size() > 1) {
fFactory.convert(buf, ast.arg1(), 0);
for (int i = 2; i < ast.size(); i++) {
buf.append(',');
fFactory.convert(buf, ast.get(i), 0);
}
}
buf.append("\\}");
}
return true;
}
use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class Plus method convert.
/** {@inheritDoc} */
@Override
public boolean convert(final StringBuffer buf, final IAST f, final int precedence) {
IExpr expr;
precedenceOpen(buf, precedence);
final Times timesConverter = new org.matheclipse.core.form.tex.reflection.Times();
timesConverter.setFactory(fFactory);
for (int i = 1; i < f.size(); i++) {
expr = f.get(i);
if ((i > 1) && (expr instanceof IAST) && expr.isTimes()) {
timesConverter.convertTimesFraction(buf, (IAST) expr, fPrecedence, Times.PLUS_CALL);
} else {
if (i > 1) {
if (expr.isNumber() && (((INumber) expr).complexSign() < 0)) {
buf.append("-");
expr = ((INumber) expr).negate();
} else if (expr.isNegativeSigned()) {
} else {
buf.append("+");
}
}
fFactory.convert(buf, expr, fPrecedence);
}
}
precedenceClose(buf, precedence);
return true;
}
use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class OutputFormFactory method convertPlusArgument.
public void convertPlusArgument(final Appendable buf, IExpr plusArg, boolean caller) throws IOException {
if (plusArg.isTimes()) {
final IAST timesAST = (IAST) plusArg;
// IExpr arg1 = timesAST.arg1();
final InfixOperator TIMES_OPERATOR = (InfixOperator) ASTNodeFactory.MMA_STYLE_FACTORY.get("Times");
convertTimesFraction(buf, timesAST, TIMES_OPERATOR, ASTNodeFactory.TIMES_PRECEDENCE, caller);
} else {
if (plusArg.isNegativeSigned()) {
// special case negative number or -Infinity...
convert(buf, plusArg);
} else {
if (caller == PLUS_CALL) {
append(buf, "+");
}
convert(buf, plusArg, ASTNodeFactory.PLUS_PRECEDENCE, false);
}
}
}
use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class OutputFormFactory method convertPlusOperatorReversed.
private void convertPlusOperatorReversed(final Appendable buf, final IAST plusAST, final InfixOperator oper, final int precedence) throws IOException {
int operPrecedence = oper.getPrecedence();
if (operPrecedence < precedence) {
append(buf, "(");
}
String operatorStr = oper.getOperatorString();
IExpr plusArg;
int size = plusAST.size() - 1;
// print Plus[] in reverse order (i.e. numbers at last)
for (int i = size; i > 0; i--) {
plusArg = plusAST.get(i);
if (plusArg.isTimes()) {
final String multCh = ASTNodeFactory.MMA_STYLE_FACTORY.get("Times").getOperatorString();
boolean showOperator = true;
final IAST timesAST = (IAST) plusArg;
IExpr arg1 = timesAST.arg1();
if (arg1.isNumber() && (((INumber) arg1).complexSign() < 0)) {
if (((INumber) arg1).isOne()) {
showOperator = false;
} else {
if (arg1.isMinusOne()) {
append(buf, "-");
showOperator = false;
} else {
convertNumber(buf, (INumber) arg1, operPrecedence, NO_PLUS_CALL);
}
}
} else {
if (i < size) {
append(buf, operatorStr);
}
convert(buf, arg1, ASTNodeFactory.TIMES_PRECEDENCE, false);
}
IExpr timesArg;
for (int j = 2; j < timesAST.size(); j++) {
timesArg = timesAST.get(j);
if (showOperator) {
append(buf, multCh);
} else {
showOperator = true;
}
convert(buf, timesArg, ASTNodeFactory.TIMES_PRECEDENCE, false);
}
} else {
if (plusArg.isNumber() && (((INumber) plusArg).complexSign() < 0)) {
// special case negative number:
convert(buf, plusArg);
} else {
if (i < size) {
append(buf, operatorStr);
}
convert(buf, plusArg, ASTNodeFactory.PLUS_PRECEDENCE, false);
}
}
}
if (operPrecedence < precedence) {
append(buf, ")");
}
}
use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class Plus method convert.
/*
* (non-Javadoc)
*
* @see org.matheclipse.core.form.mathml.IConverter#convert(java.lang.StringBuffer, org.matheclipse.parser.interfaces.IAST, int)
*/
@Override
public boolean convert(final StringBuffer buf, final IAST f, final int precedence) {
IExpr expr;
fFactory.tagStart(buf, fFirstTag);
precedenceOpen(buf, precedence);
final Times timesConverter = new org.matheclipse.core.form.mathml.reflection.Times();
timesConverter.setFactory(fFactory);
int size = f.size() - 1;
for (int i = size; i > 0; i--) {
expr = f.get(i);
if ((i < size) && (expr instanceof IAST) && ((IAST) expr).head().equals(F.Times)) {
timesConverter.convertTimesFraction(buf, (IAST) expr, fPrecedence, Times.PLUS_CALL);
} else {
if (i < size) {
if ((expr instanceof ISignedNumber) && (((ISignedNumber) expr).isNegative())) {
fFactory.tag(buf, "mo", "-");
expr = ((ISignedNumber) expr).negate();
} else {
fFactory.tag(buf, "mo", "+");
}
}
fFactory.convert(buf, expr, fPrecedence);
}
}
precedenceClose(buf, precedence);
fFactory.tagEnd(buf, fFirstTag);
return true;
}
Aggregations