How to display a fraction as a mixed number in maxima?

て烟熏妆下的殇ゞ 提交于 2021-02-19 03:00:31

问题


I'm giving a course where students are used to the mixed number notation. However, all the calculations that maxima does, use the more traditional notation of fractions. Is it possible to present 3/2 as 1 1/2. I need this for the latex output only.

(%i4) tex(3/2);
$${{3}\over{2}}$$
(%o4)                                false

So instead of this I would like to get:

(%i4) tex(3/2);
$$1 {{1}\over{2}}$$
(%o4)                                false

Is this possible?


回答1:


You can assign TeX properties via texput. Rational numbers are represented as ((RAT) mmm nnn) which you can see via :lisp $x where x is a Maxima variable which is a rational number. So, you can set the TeX property by:

texput (?rat, texrat);

where your function texrat is defined as (for example):

texrat(x) := block ([i, r], 
                    i:floor(x), 
                    r:x-i, 
                    sconcat ("{", i, "} {{", num(r), "}\\over{", denom(r), "}}"));

Example:

(%i11) tex(sin(12/7));
$$\sin \left({1} {{5}\over{7}}\right)$$

Note that the new function is applied to a rational even when it's inside another operator.

Of course you can change the output of texrat to make it whatever you want.

Note that the ? before rat is necessary in the call to texput.

Some of this stuff is undocumented; sorry about that.




回答2:


I don't think that there is an option for this, but it's easy to make your own function.

For example:

texixed(a):= tex(printf(false, "~a ~a", a-mod(a,1) , mod(a,1)));
texixed(5/3);
   $$\mbox{{}1 2/3{}}$$
texixed(7/2);
   $$\mbox{{}3 1/2{}}$$


来源:https://stackoverflow.com/questions/45915359/how-to-display-a-fraction-as-a-mixed-number-in-maxima

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