00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00019 #ifndef _ARAGELI_texout_hpp_
00020 #define _ARAGELI_texout_hpp_
00021
00022 #include "config.hpp"
00023
00024 #include <cstddef>
00025 #include <iostream>
00026 #include <sstream>
00027
00028 #include "big_int.hpp"
00029 #include "rational.hpp"
00030 #include "vector.hpp"
00031 #include "matrix.hpp"
00032 #include "sparse_polynom.hpp"
00033
00034 #include "std_import.hpp"
00035
00036
00037 namespace Arageli
00038 {
00039
00041
00042 enum ex_environ_priority
00043 {
00044 eep_alone,
00045 eep_add,
00046 eep_mul
00047 };
00048
00050
00051 template <typename Out, typename T>
00052 inline void output_latex_verb
00053 (
00054 Out& out,
00055 const T& x,
00056 bool in_math = false,
00057 ex_environ_priority eep = eep_alone
00058 )
00059 { out << "\\verb\"" << x << '"'; }
00060
00062
00067 template <typename Out, typename T>
00068 inline void output_latex
00069 (
00070 Out& out,
00071 const T& x,
00072 bool in_math = false,
00073 ex_environ_priority eep = eep_alone
00074 )
00075 { output_latex_verb(out, x, in_math, eep); }
00076
00077
00079 template <typename Out, typename T>
00080 inline void output_latex_math
00081 (
00082 Out& out,
00083 const T& x,
00084 bool in_math = false,
00085 ex_environ_priority eep = eep_alone
00086 )
00087 {
00088 if(!in_math)out << '$' << x << '$';
00089 else out << x;
00090 }
00091
00092
00093 #define ARAGELI_TEXOUT_NUMBER(TYPE) \
00094 template <typename Out> \
00095 inline void output_latex \
00096 ( \
00097 Out& out, \
00098 const TYPE& x, \
00099 bool in_math = false, \
00100 ex_environ_priority eep = eep_alone \
00101 ) \
00102 { output_latex_math(out, x, in_math, eep); }
00103
00105
00107
00108 ARAGELI_TEXOUT_NUMBER(signed int)
00109 ARAGELI_TEXOUT_NUMBER(unsigned int)
00110 ARAGELI_TEXOUT_NUMBER(signed short int)
00111 ARAGELI_TEXOUT_NUMBER(unsigned short int)
00112 ARAGELI_TEXOUT_NUMBER(signed long int)
00113 ARAGELI_TEXOUT_NUMBER(unsigned long int)
00114 ARAGELI_TEXOUT_NUMBER(float)
00115 ARAGELI_TEXOUT_NUMBER(double)
00116 ARAGELI_TEXOUT_NUMBER(long double)
00117 ARAGELI_TEXOUT_NUMBER(big_int)
00118
00119 #ifdef ARAGELI_INT64_SUPPORT
00120 ARAGELI_TEXOUT_NUMBER(signed __int64)
00121 ARAGELI_TEXOUT_NUMBER(unsigned __int64)
00122 #endif
00123
00124 #ifdef ARAGELI_LONG_LONG_SUPPORT
00125 ARAGELI_TEXOUT_NUMBER(signed long long)
00126 ARAGELI_TEXOUT_NUMBER(unsigned long long)
00127 #endif
00128
00130
00131 #undef ARAGELI_TEXOUT_NUMBER
00132
00133
00135
00142 template <typename Out, typename T>
00143 void output_latex
00144 (
00145 Out& out,
00146 const rational<T>& x,
00147 bool in_math,
00148 ex_environ_priority eep,
00149 std::size_t minlensimple,
00150 bool externsign = true
00151 );
00152
00153 template <typename Out, typename T>
00154 inline void output_latex
00155 (
00156 Out& out,
00157 const rational<T>& x,
00158 bool in_math,
00159 ex_environ_priority eep
00160 )
00161 { return output_latex(out, x, in_math, eep, 3, true); }
00162
00163 template <typename Out, typename T>
00164 inline void output_latex
00165 (
00166 Out& out,
00167 const rational<T>& x,
00168 bool in_math
00169 )
00170 { return output_latex(out, x, in_math, eep_alone, 3, true); }
00171
00172 template <typename Out, typename T>
00173 inline void output_latex
00174 (
00175 Out& out,
00176 const rational<T>& x
00177 )
00178 { return output_latex(out, x, false, eep_alone, 3, true); }
00179
00181 template <typename Out, typename T, bool REFCNT>
00182 void output_latex
00183 (
00184 Out& out,
00185 const vector<T, REFCNT>& x,
00186 bool in_math,
00187 ex_environ_priority eep,
00188 bool hor,
00189 const char* first_bracket = "(",
00190 const char* second_bracket = ")",
00191 const char* delim = ","
00192 );
00193
00194 template <typename Out, typename T, bool REFCNT>
00195 inline void output_latex
00196 (
00197 Out& out,
00198 const vector<T, REFCNT>& x,
00199 bool in_math,
00200 ex_environ_priority eep
00201 )
00202 {
00203
00204 output_latex(out, x, in_math, eep, true, "(", ")", ",");
00205 }
00206
00207 template <typename Out, typename T, bool REFCNT>
00208 inline void output_latex
00209 (
00210 Out& out,
00211 const vector<T, REFCNT>& x,
00212 bool in_math
00213 )
00214 {
00215
00216 output_latex(out, x, in_math, eep_alone, true, "(", ")", ",");
00217 }
00218
00219 template <typename Out, typename T, bool REFCNT>
00220 inline void output_latex
00221 (
00222 Out& out,
00223 const vector<T, REFCNT>& x
00224 )
00225 {
00226
00227 output_latex(out, x, false, eep_alone, true, "(", ")", ",");
00228 }
00229
00231 template <typename Out, typename T, bool REFCNT>
00232 void output_latex
00233 (
00234 Out& out,
00235 const matrix<T, REFCNT>& x,
00236 bool in_math,
00237 ex_environ_priority eep,
00238 bool transposed,
00239 const char* first_bracket = "(",
00240 const char* second_bracket = ")"
00241 );
00242
00243
00244 template <typename Out, typename T, bool REFCNT>
00245 inline void output_latex
00246 (
00247 Out& out,
00248 const matrix<T, REFCNT>& x
00249 )
00250 {
00251
00252 output_latex(out, x, false, eep_alone, false, "(", ")");
00253 }
00254
00255
00256 template <typename Out, typename T, bool REFCNT>
00257 inline void output_latex
00258 (
00259 Out& out,
00260 const matrix<T, REFCNT>& x,
00261 bool in_math
00262 )
00263 {
00264
00265 output_latex(out, x, in_math, eep_alone, false, "(", ")");
00266 }
00267
00268
00269 template <typename Out, typename T, bool REFCNT>
00270 inline void output_latex
00271 (
00272 Out& out,
00273 const matrix<T, REFCNT>& x,
00274 bool in_math,
00275 ex_environ_priority eep
00276 )
00277 {
00278
00279 output_latex(out, x, in_math, eep, false, "(", ")");
00280 }
00281
00282
00284 template <typename Out, typename F, typename I>
00285 void output_latex
00286 (
00287 Out& out,
00288 const monom<F, I>& x,
00289 bool in_math,
00290 ex_environ_priority eep,
00291 bool first,
00292 const char* var = "x"
00293 );
00294
00295 template <typename Out, typename F, typename I>
00296 inline void output_latex
00297 (
00298 Out& out,
00299 const monom<F, I>& x,
00300 bool in_math,
00301 ex_environ_priority eep
00302 )
00303 { return output_latex(out, x, in_math, eep, true, "x"); }
00304
00305 template <typename Out, typename F, typename I>
00306 inline void output_latex
00307 (
00308 Out& out,
00309 const monom<F, I>& x,
00310 bool in_math
00311 )
00312 { return output_latex(out, x, in_math, eep_alone, true, "x"); }
00313
00314 template <typename Out, typename F, typename I>
00315 inline void output_latex
00316 (
00317 Out& out,
00318 const monom<F, I>& x
00319 )
00320 { return output_latex(out, x, false, eep_alone, true, "x"); }
00321
00323 template <typename Out, typename F, typename I, bool REFCNT>
00324 void output_latex
00325 (
00326 Out& out,
00327 const sparse_polynom<F, I, REFCNT>& x,
00328 bool in_math,
00329 ex_environ_priority eep,
00330 const char* var
00331 );
00332
00333 template <typename Out, typename F, typename I, bool REFCNT>
00334 inline void output_latex
00335 (
00336 Out& out,
00337 const sparse_polynom<F, I, REFCNT>& x,
00338 bool in_math,
00339 ex_environ_priority eep
00340 )
00341 { return output_latex(out, x, in_math, eep, "x"); }
00342
00343 template <typename Out, typename F, typename I, bool REFCNT>
00344 inline void output_latex
00345 (
00346 Out& out,
00347 const sparse_polynom<F, I, REFCNT>& x,
00348 bool in_math
00349 )
00350 { return output_latex(out, x, in_math, eep_alone, "x"); }
00351
00352 template <typename Out, typename F, typename I, bool REFCNT>
00353 inline void output_latex
00354 (
00355 Out& out,
00356 const sparse_polynom<F, I, REFCNT>& x
00357 )
00358 { return output_latex(out, x, false, eep_alone, "x"); }
00359
00360
00361
00362
00364 enum matrix_line_type
00365 {
00366 mlt_solid,
00367 mlt_dot,
00368 mlt_hatch,
00369 mlt_chain
00370 };
00371
00373
00374 struct matrix_line
00375 {
00377 matrix_line () {}
00378
00379 matrix_line (std::size_t pos_a, matrix_line_type mlt_a = mlt_solid)
00380 : pos(pos_a), mlt(mlt_a) {}
00381
00382 std::size_t pos;
00383 matrix_line_type mlt;
00384 };
00385
00386
00388
00389 struct matrix_box
00390 {
00392 matrix_box () {}
00393
00394 matrix_box (std::size_t row_a, std::size_t col_a, matrix_line_type mlt_a = mlt_solid)
00395 : row(row_a), col(col_a), mlt(mlt_a) {}
00396
00397 std::size_t
00398 row,
00399 col;
00400 matrix_line_type mlt;
00401 };
00402
00403
00405 template
00406 <
00407 typename In_hor = const matrix_line*,
00408 typename In_ver = const matrix_line*,
00409 typename In_box = const matrix_box*
00410 >
00411 struct matrix_frames
00412 {
00413 matrix_frames
00414 (
00415 In_hor hf = 0, In_hor hl = 0,
00416 In_ver vf = 0, In_ver vl = 0,
00417 In_box bf = 0, In_box bl = 0
00418 )
00419 : hors_first(hf), hors_last(hl),
00420 vers_first(vf), vers_last(vl),
00421 boxes_first(bf), boxes_last(bl)
00422 {}
00423
00424 In_hor
00425 hors_first,
00426 hors_last;
00427 In_ver
00428 vers_first,
00429 vers_last;
00430 In_box
00431 boxes_first,
00432 boxes_last;
00433 };
00434
00435
00437
00438
00439
00440 template <typename In_hor, typename In_ver, typename In_box>
00441 inline matrix_frames<In_hor, In_ver, In_box> make_matrix_frames
00442 (
00443 In_hor hf, In_hor hl,
00444 In_ver vf, In_ver vl,
00445 In_box bf, In_box bl
00446 )
00447 { return matrix_frames<In_hor, In_ver, In_box>(hf, hl, vf, vl, bf, bl); }
00448
00449
00450 template <typename In_hor, typename In_ver>
00451 inline matrix_frames<In_hor, In_ver> make_matrix_frames
00452 (
00453 In_hor hf, In_hor hl,
00454 In_ver vf, In_ver vl
00455 )
00456 { return matrix_frames<In_hor, In_ver>(hf, hl, vf, vl); }
00457
00458
00459 template <typename In_hor>
00460 inline matrix_frames<In_hor> make_matrix_frames
00461 (
00462 In_hor hf, In_hor hl
00463 )
00464 { return matrix_frames<In_hor>(hf, hl); }
00465
00466
00467 inline matrix_frames<> make_matrix_frames ()
00468 { return matrix_frames<>(); }
00469
00470
00471 template <typename In_ver>
00472 inline matrix_frames<const matrix_line*, In_ver> make_matrix_vers
00473 (
00474 In_ver vf, In_ver vl
00475 )
00476 { return matrix_frames<const matrix_line*, In_ver>(0, 0, vf, vl); }
00477
00478
00479 template <typename In_box>
00480 inline matrix_frames<const matrix_line*, const matrix_line*, In_box>
00481 make_matrix_boxes
00482 (
00483 In_box bf, In_box bl
00484 )
00485 {
00486 return matrix_frames<const matrix_line*, const matrix_line*, In_box>
00487 (0, 0, 0, 0, bf, bl);
00488 }
00489
00490
00491 template <typename In_ver, typename In_box>
00492 inline matrix_frames<const matrix_line*, In_ver, In_box> make_matrix_vers_boxes
00493 (
00494 In_ver vf, In_ver vl,
00495 In_box bf, In_box bl
00496 )
00497 {
00498 return matrix_frames<const matrix_line*, In_ver, In_box>
00499 (0, 0, vf, vl, bf, bl);
00500
00501 }
00502
00504
00505
00507 template
00508 <
00509 typename T, bool REFCNT, typename Ch, typename ChT,
00510 typename In_hor, typename In_ver, typename In_box
00511 >
00512 void output_latex_matrix_frames
00513 (
00514 std::basic_ostream<Ch, ChT>& out,
00515 const matrix<T, REFCNT>& x,
00516 const matrix_frames<In_hor, In_ver, In_box>& mf,
00517 bool in_math = false,
00518 bool transposed = false,
00519 const char* first_bracket = "(",
00520 const char* second_bracket = ")"
00521 );
00522
00523 }
00524
00525
00526 #ifdef ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE
00527 #define ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_TEXOUT
00528 #include "texout.cpp"
00529 #undef ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_TEXOUT
00530 #endif
00531
00532
00533 #endif // #ifndef _ARAGELI_texout_hpp_