2

In maple there is a function called latex which can convert a maple expression to an equivalent latex expression.

Unfortunately I cannot seem to properly use units with the conversion function:

> with(Units[Standard]):
> latex(Unit('m'))
{\it Unit} \left( m \right)

According to the documentation for latex I need to implement a function called latex/Unit, however:

> `latex/Unit` := proc (v) "test" end proc:
> latex(Unit('m'));
{\it Unit} \left( m \right)

How can I create a function which would properly convert expressions to latex using siunitx?

While \SI{5.523}{m} would be preferred over 5.523\si{m}, the second format is also ok.

If possible I would also like numbers to be changed to output as \num{5.5} instead of just 5.5, but I'm much more concerned about units. Of course using \meter instead of m in the unit is also preferrable, but not as important.

1

This is a Maple problem rather than a LaTeX problem.

Still, the basic issue is that Unit( 'm' ) gets evaluated before being passed to latex. Look at the effect of the uneval quotes in the following:

> latex( int( 1 / x , x ) ) ;
\ln  \left( x \right) 
> latex( 'int'(1 / x , x ) ) ;
\int \!{x}^{-1}\,{\rm d}x

So, in your case, the latex/Unit function is never called at all. You could use

> latex('Unit'('m'));

after which you still have some work to do in order to produce the results you want, but at least the function is executed. I'll try to think up a way to implement a less cumbersome syntax tomorrow.

  • If I convert from one unit to another, I get evaluated units, so I can't really do this on values I get from computations. If you could find the function that is called, it would be great. Alternatively if you know how to separate the unit from the rest of the value, I can use that to write a wrapper. – Alice Ryhl Aug 25 '16 at 17:49
  • My suggestion doesn't seem to work with Unit anyway. Perhaps the problem is caused by the fact that Unit is a module, not a procedure. In any case, I think this is one to take up with Maplesoft Technical Support. I'd be interested to see their response; my email address can be obtained from my profile page. – Ian Thompson Aug 25 '16 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.