public function visitExpressionNode(ExpressionNode $node)
    {

        $operator = $node->getOperator();
        $left = $node->getLeft();
        $right = $node->getRight();

        switch ($operator) {
            case '+':
                $leftValue = $left->accept($this);
                $rightValue = $this->parenthesize($right, $node);

                return "$leftValue+$rightValue";

            case '-':
                if ($right) {
                    // Binary minus

                    $leftValue = $left->accept($this);
                    $rightValue = $this->parenthesize($right, $node);

                    return "$leftValue-$rightValue";
                } else {
                    // Unary minus

                    $leftValue = $this->parenthesize($left, $node);

                    return "-$leftValue";
                }

            case '*':
                $operator = '';
                if ($this->MultiplicationNeedsCdot($left, $right)) {
                    $operator = '\cdot ';
                }
                $leftValue = $this->parenthesize($left, $node);
                $rightValue = $this->parenthesize($right, $node);

                return "$leftValue$operator$rightValue";

            case '/':
                if ($this->solidus) {
                    $leftValue = $this->parenthesize($left, $node);
                    $rightValue = $this->parenthesize($right, $node);

                    return "$leftValue$operator$rightValue";
                }

                return '\frac{' . $left->accept($this) . '}{' . $right->accept($this) . '}';

            case '^':
                $leftValue = $this->parenthesize($left, $node, '', true);

                // Typeset exponents with solidus
                $this->solidus = true;
                $result = $leftValue . '^' . $this->bracesNeeded($right);
                $this->solidus = false;

                return $result;
        }
    }
public function visitExpressionNode(ExpressionNode $node)
    {

        $operator = $node->getOperator();
        $left = $node->getLeft();
        $right = $node->getRight();

        switch ($operator) {
            case '+':
                $leftValue = $left->accept($this);
                $rightValue = $this->parenthesize($right, $node);

                return "$leftValue+$rightValue";

            case '-':
                if ($right) {
                    // Binary minus

                    $leftValue = $left->accept($this);
                    $rightValue = $this->parenthesize($right, $node);

                    return "$leftValue-$rightValue";
                } else {
                    // Unary minus

                    $leftValue = $this->parenthesize($left, $node);

                    return "-$leftValue";
                }

            case '*':
                $operator = '';
                if ($this->MultiplicationNeedsCdot($left, $right)) {
                    $operator = '\cdot ';
                }
                $leftValue = $this->parenthesize($left, $node);
                $rightValue = $this->parenthesize($right, $node);

                return "$leftValue$operator$rightValue";

            case '/':
                if ($this->solidus) {
                    $leftValue = $this->parenthesize($left, $node);
                    $rightValue = $this->parenthesize($right, $node);

                    return "$leftValue$operator$rightValue";
                }

                return '\frac{' . $left->accept($this) . '}{' . $right->accept($this) . '}';

            case '^':
                $leftValue = $this->parenthesize($left, $node, '', true);

                // Typeset exponents with solidus
                $this->solidus = true;
                $result = $leftValue . '^' . $this->bracesNeeded($right);
                $this->solidus = false;

                return $result;
        }
    }
public function visitExpressionNode ( ExpressionNode $ node ) { $ operator = $ node -> getOperator ( ) ; $ left = $ node -> getLeft ( ) ; $ right = $ node -> getRight ( ) ; switch ( $ operator ) { case '+' : $ leftValue = $ left -> accept ( $ this ) ; $ rightValue = $ this -> parenthesize ( $ right , $ node ) ; return "$leftValue+$rightValue" ; case '-' : if ( $ right ) { // Binary minus $ leftValue = $ left -> accept ( $ this ) ; $ rightValue = $ this -> parenthesize ( $ right , $ node ) ; return "$leftValue-$rightValue" ; } else { // Unary minus $ leftValue = $ this -> parenthesize ( $ left , $ node ) ; return "-$leftValue" ; } case '*' : $ operator = '' ; if ( $ this -> MultiplicationNeedsCdot ( $ left , $ right ) ) { $ operator = '\cdot ' ; } $ leftValue = $ this -> parenthesize ( $ left , $ node ) ; $ rightValue = $ this -> parenthesize ( $ right , $ node ) ; return "$leftValue$operator$rightValue" ; case '/' : if ( $ this -> solidus ) { $ leftValue = $ this -> parenthesize ( $ left , $ node ) ; $ rightValue = $ this -> parenthesize ( $ right , $ node ) ; return "$leftValue$operator$rightValue" ; } return '\frac{' . $ left -> accept ( $ this ) . '}{' . $ right -> accept ( $ this ) . '}' ; case '^' : $ leftValue = $ this -> parenthesize ( $ left , $ node , '' , true ) ; // Typeset exponents with solidus $ this -> solidus = true ; $ result = $ leftValue . '^' . $ this -> bracesNeeded ( $ right ) ; $ this -> solidus = false ; return $ result ; } }
Generate LaTeX code for an ExpressionNode

Create a string giving LaTeX code for an ExpressionNode `(x op y)`
where `op` is one of `+`, `-`, `*`, `/` or `^`

### Typesetting rules:

- Adds parentheses around each operand, if needed. (I.e. if their precedence
lower than that of the current Node.) For example, the AST `(^ (+ 1 2) 3)`
generates `(1+2)^3` but `(+ (^ 1 2) 3)` generates `1^2+3` as expected.
- Multiplications are typeset implicitly `(* x y)` returns `xy` or using
`\cdot` if the first factor is a FunctionNode or the (left operand) in the
second factor is a NumberNode, so `(* x 2)` return `x \cdot 2` and `(* (sin x) x)`
return `\sin x \cdot x` (but `(* x (sin x))` returns `x\sin x`)
- Divisions are typeset using `\frac`
- Exponentiation adds braces around the power when needed.

@retval string
@param ExpressionNode $node AST to be typeset
Generate LaTeX code for an ExpressionNode