1
$\begingroup$

I've got a simple script which runs in bash some code - I want now to get an answer in TeX Form. If I would run Mathematica code inside the interpreter, it would be easy:

Mathematica 10.0 for Linux x86 (64-bit)
Copyright 1988-2014 Wolfram Research, Inc.

In[1]:= V=(m w^2x^2)/2                                                                                                                          

           2  2
        m w  x
Out[1]= -------
           2

In[2]:= TeXForm[V]                                                                                                                              

Out[2]//TeXForm= \frac{1}{2} m w^2 x^2

But when I want to run it like a bash script ( ./code.m ), I type something like:

#!/usr/local/bin/math -script 

VO= (m w^2x^2)/2
Print[VO]
Print[TeXForm[VO]

I get:

(m*w^2*x^2)/2
TeXForm[(m*w^2*x^2)/2]

How to get proper TeXForm printing output?

$\endgroup$
1
$\begingroup$

I can reproduce your output, but I don't see how to change it using the -script option. I've always used the -run option (which I learned oh so long ago from Jens), and now I see that it is indeed different from the -script option.

I have 2 files, one is code.m that you have above (with the final closing bracket included), and another code2.m, which only has the Mathematica commands

VO= (m w^2x^2)/2
Print[VO]
Print[TeXForm[VO]]

I run this via the command math -noprompt -run "<<code2.m; Exit[]; "

Here is the difference between the two ways of running it,

enter image description here

And actually, it seems you don't even need to have a second file, you can just run the code.m that you have and it seems to ignore the first line as if it were a comment.

$\endgroup$

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.