/***************************************************************************
printing.h - header file for pretty-printing expressions in Latex format
-------------------
begin : Sat Mar 2 2002
copyright : (C) 2002 by Jan Rheinlaender
email : jrheinlaender@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/**
@short This file contains routines for pretty-printing expressions in Latex format.
@author Jan Rheinlaender
The routines in this file will become obsolete if the print_latex printing context is updated. The difference
is that in the GiNaC print() functions, setting of parentheses is solved by using precedence() and level.
This approach does not give nice Latex output, because it is impossible to put brackets in the case of
x * (3+4i) but not in the case of x^{3+4i}. In the latter case the {}-brackets are completely sufficient and
x^{(3+4i)} looks ugly. Therefore another approach to bracketing is implemented in this code.
**/
#ifndef PRINTING_H
#define PRINTING_H
#include "unit.h"
#include "func.h" // *** added in 0.5
#include "expression.h"
#include "optstack.h"
#include <iostream>
#include <string>
#include <stdexcept>
#include <ginac/ginac.h>
using namespace GiNaC;
/// Printing class for iMath
class imathprint : public print_dflt {
GINAC_DECLARE_PRINT_CONTEXT(imathprint, print_dflt)
public:
optstack* poptions; // iMath-specific print options *** added in 1.4.1
imathprint(std::ostream & os, optstack* popt, unsigned opt = 0) : print_dflt(os, opt), poptions(popt) {};
static void init();
};
// *** structure quantity_format introduced in 0.3, removed in 1.1
void print_power_ltx(const power &p, const print_latex &c, unsigned level);
/**
* Print an add. This method splits the add into positive and negative operands and prints them
* using the functionality of clas operands.
* @param a The add to be printed
* @param os The stream to print on
* @param toplevel True if we are printing at the top nesting level
* @param opnum The operand count to start at (for splitting equations across lines)
*/
void print_ltx(const add &a, std::ostream &os, const bool toplevel, const int opnum);
/**
* Print an expression
* @param e The ex to be printed
* @param os The stream to print on
* @param toplevel A boolean indicating whether we are at top level. This makes a difference when printing
* quantities, i.e., we do not want to print something like "x = \mm", but rather "x = 1 \mm". But we do want
* to print "x = a" and not "x = 1 a"! And again, we don't want to print "x = 1 \mm 1 \N". The toplevel parameter
* is an attempt to solve this dilemma.
*/
void print_ltx(const ex &e, std::ostream &os, const bool toplevel = false);
/** *** added in 0.5
* Print a func
* @param f The function to be printed
* @param os The stream to print on
*/
void print_ltx(const func &f, std::ostream &os);
/**
* Print a function.
* @param f The function to be printed
* @param os The stream to print on
*/
void print_ltx(const function &f, std::ostream &os);
/**
* Print an integral
* @param i The integral to be printed
* @param os The stream to print on
*/
void print_ltx(const integral &i, std::ostream &os);
/** *** added in 0.5
* Print a GiNaC list
* @param l The list to be printed
* @param os The stream to print on
*/
void print_ltx(const lst &l, std::ostream &os);
/** *** added in 1.0
* Print a GiNaC matrix
* @param m The matrix to be printed
* @param os The stream to print on
*/
void print_ltx(const matrix &m, std::ostream &os);
/**
* Print a mul. This method splits the mul into positive and negative powers and prints it using the
* functionality of class operands. The mul is printed as a \\frac{}{} if appropriate.
* @param m The mul to be printed
* @param os The stream to print on
* @param toplevel True if we are printing at the top nesting level
* @param opnum The operand count to start at (for splitting equations across lines)
*/
void print_ltx(const mul &m, std::ostream &os, const bool toplevel, const int opnum);
/**
* Print a numeric. This code is mostly copied from numeric.cpp (source version 1.0.5). Basically,
* the only change is that no brackets are printed in this method.
* @param n The numeric to be printed
* @param os The stream to print on
*/
void print_ltx(const numeric &n, std::ostream &os);
/**
* Print a power. A Latex \\frac{}{} or \\sqrt[]{} statement is used if
* appropriate.
* @param p The power to be printed
* @param os The stream to print on
*/
void print_ltx(const power &p, std::ostream &os);
/** *** added in 1.3.0
* Print a relational.
* @param r The relational to be printed
* @param os The stream to print on
*/
void print_ltx(const relational &r, std::ostream &os);
/**
* Print a symbol. This is just a wrapper function for the GiNaC printing routine provided for
* consistency's sake.
* @param s The symbol to be printed
* @param os The stream to print on
*/
void print_ltx(const symbol &s, std::ostream &os);
/**
* Print a unit.
* @param u The unit to be printed
* @param os The stream to print on
* @param toplevel A boolean indicating whether we are at top level (see print_ltx(ex &e, ...)
*/
void print_ltx(const Unit &u, std::ostream &os, const bool toplevel = false);
#endif