[GiNaC-list] print methods for functions
Alexei Sheplyakov
alexei.sheplyakov at gmail.com
Wed May 4 09:56:02 CEST 2011
Hello,
On Tue, May 3, 2011 at 11:56 PM, Luke <hazelnusse at gmail.com> wrote:
> I would like to customize the latex printing of sin, cos, and tan to
> be more concise. For example, for an expression like sin(delta),
> instead of the default:
> \sin(\delta)
> I would like it to print:
> s_{\delta}
Quick and dirty solution:
DECLARE_FUNCTION_1P(my_sin)
static ex my_sin_eval(const ex& arg)
{
return my_sin(arg).hold();
}
static void my_sin_print_latex(const ex& arg, const print_context& c)
{
c.s << "s_{";
c.print(arg);
c.s << "}";
}
REGISTER_FUNCTION(my_sin, eval_func(my_sin_eval).
print_func<print_latex>(my_sin_print_latex))
And replace all instances of sin with my_sin before printing the
expression, i.e.
std::cout << latex << e.subs(sin(wild()) == my_sin(wild())) << std::endl;
> I read section 6.3.2 in the documentation about print methods for
> functions, in which there was an example for the "abs()" function. I
> am confused about what needs to go in abs_eval and abs_evalf -- I
> tried to run that example and wasn't able to get it to compile.
Anything you like, i.e.
static ex abs_eval(const ex& arg)
{
return arg;
}
static ex abs_evalf(const ex& arg)
{
return arg;
}
(it's not mathematically consistent, still it's good enough for that
particular example).
> If I only want to change the latex printing for sin/cos/tan, but leave
> everything else the same as the default, what approach should I take?
> Should I just copy the code from inifcns_trans.cpp into my own,
That would work, but it sounds like too much effort.
> or is there a way to call REGISTER_FUNCTION in a simple way that only
> modifies the latex printing?
No.
Best regards,
Alexei
More information about the GiNaC-list
mailing list