maxima tex output to show brackets for sin and cos

久未见 提交于 2021-01-24 09:01:05

问题


I use maxima's tex output and would like to change the way it outputs sin(x). It currently does:

tex(sin(x));
$$\sin x$$

But I would like to have brackets around the x, but not always; for instance, if i use this:

sin(x/2) already has \left( and \right)
tex(sin(x/2));
\begin{equation} \sin \left({{x}\over{2}}\right) \end{equation}

is this possible, maybe with the texput function?


回答1:


Well, if you are not adverse to putting in a little Lisp code:

(%i1) :lisp (setf (get '%sin 'tex) nil)
(%i1) :lisp (setf (get '%cos 'tex) nil)

That takes away the predefined handler function (which treats sin and cos as prefix operators). Then you get:

(%i1) tex (sin(x) + cos(y));
$$\cos \left(y\right)+\sin \left(x\right)$$



回答2:


In case your context precludes using : lisp an alternative might be to define a function like:

psin(x):=sin(x);
psintex:lambda([e],printf(false,"\\sin\\left(~a\\right)", tex1(e)));
texput('psin, psintex);

I'm not sure if this kind of aliasing is problematic for programmatic reasons; however, in terms of flexibility for tex output, I find it very useful, as one can access the preferred form simply by switching between sin(x) and psin(x).



来源:https://stackoverflow.com/questions/22355618/maxima-tex-output-to-show-brackets-for-sin-and-cos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!