[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.3.2 Print methods for functions
Symbolic functions employ a print method dispatch mechanism similar to the
one used for classes. The methods are specified with print_func<C>()
function options. If you don't specify any special print methods, the function
will be printed with its name (or LaTeX name, if supplied), followed by a
comma-separated list of arguments enclosed in parentheses.
For example, this is what GiNaC's ‘abs()’ function is defined like:
static ex abs_eval(const ex & arg) { ... } static ex abs_evalf(const ex & arg) { ... } static void abs_print_latex(const ex & arg, const print_context & c) { c.s << "{|"; arg.print(c); c.s << "|}"; } static void abs_print_csrc_float(const ex & arg, const print_context & c) { c.s << "fabs("; arg.print(c); c.s << ")"; } REGISTER_FUNCTION(abs, eval_func(abs_eval). evalf_func(abs_evalf). print_func<print_latex>(abs_print_latex). print_func<print_csrc_float>(abs_print_csrc_float). print_func<print_csrc_double>(abs_print_csrc_float)); |
This will display ‘abs(x)’ as ‘|x|’ in LaTeX mode and fabs(x)
in non-CLN C source output, but as abs(x)
in all other formats.
There is currently no equivalent of set_print_func()
for functions.