[go: up one dir, main page]

Menu

[r50]: / src / printing.h  Maximize  Restore  History

Download this file

206 lines (178 with data), 8.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**************************************************************************
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 "ncsymbol.h" // *** added in 1.4.3
#include <iostream>
#include <string>
#include <stdexcept>
#include <ginac/ginac.h>
using namespace GiNaC;
/*class option_is_less : public std::binary_function<option_name, option_name, bool> {
public:
bool operator()(const option_name &o1, const option_name &o2) const;
};
*/
typedef std::map<option_name, option> optionmap;
/// Printing class for iMath
class imathprint : public print_dflt {
GINAC_DECLARE_PRINT_CONTEXT(imathprint, print_dflt)
public:
optionmap* poptions; // iMath-specific print options *** added in 1.4.1
bool add_turn_around; // iMath-specific flag *** added in 1.4.5
imathprint(std::ostream & os, unsigned opt = 0) : print_dflt(os, opt) { add_turn_around = false; };
imathprint(std::ostream & os, optionmap* popt, unsigned opt = 0)
: print_dflt(os, opt), poptions(popt) { add_turn_around=false; };
static void init();
};
// iMath printing functions
class stringex;
void imathprint_add(const add& a, const imathprint& c, unsigned level);
void imathprint_constant(const constant& cn, const imathprint& c, unsigned level);
void imathprint_ex(const ex& e, const imathprint& c, unsigned level);
void imathprint_func(const func& f, const imathprint& c, unsigned level);
void imathprint_function(const function& f, const imathprint& c, unsigned level);
void imathprint_integral(const integral& i, const imathprint& c, unsigned level);
void imathprint_matrix(const matrix& m, const imathprint& c, unsigned level);
void imathprint_mul(const mul &m, const imathprint& c, unsigned level);
void imathprint_numeric(const numeric& m, const imathprint& c, unsigned level);
void imathprint_power(const power& p, const imathprint& c, unsigned level);
void imathprint_relational(const relational& r, const imathprint& c, unsigned level);
void imathprint_stringex(const stringex& s, const imathprint& c, unsigned level);
void imathprint_symbol(const symbol& s, const imathprint& c, unsigned level);
void imathprint_unit(const Unit& u, const imathprint& c, unsigned level);
// Latex printing functions
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 non-commutative mul
* @param m The ncmul 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 ncmul &m, std::ostream &os, const bool toplevel, const int opnum); // *** added in 1.4.3
/**
* Print a non-commutative symbol
* @param m The ncsymbol to be printed
* @param os The stream to print on
*/
void print_ltx(const ncsymbol &m, std::ostream &os); // *** added in 1.4.3
/**
* 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