[-- Attachment #1: Type: text/plain, Size: 744 bytes --] Hello, As far as I can find, there is no babel support for Mathematica. So I wrote one and share it in case other people are interested: https://github.com/tririver/wy-els/blob/master/ob-mathematica.el It is also discussed in this blog http://cosmosimple.blogspot.co.uk/2014/01/evaluate-mathematica-code-in-emacs-org.html While writing this extension, I have a question: How to add font-lock mode in org code blocks? I had a read of ob-C and ob-python code and didn't find out how they do font-lock. Note that the font lock support for Mathematica is available as mma-mode at https://github.com/skaslev/emacs.d/blob/master/progmodes/mma.el For my case in a .m file I have font lock from mma.el, but not src code blocks. Best wishes, Yi [-- Attachment #2: Type: text/html, Size: 1231 bytes --]

Hi Yi, Yi Wang <tririverwangyi@gmail.com> writes: > As far as I can find, there is no babel support for Mathematica. So I > wrote one and share it in case other people are interested: > > https://github.com/tririver/wy-els/blob/master/ob-mathematica.el Nice, thanks for sharing! (By the way, you should fix the .el header, it says that the file is part of Emacs while it's not.) > While writing this extension, I have a question: How to add font-lock > mode in org code blocks? (setq org-src-fontify-natively t) HTH, -- Bastien

```
Hi Bastien,
Bastien wrote:
>> While writing this extension, I have a question: How to add font-lock
>> mode in org code blocks?
>
> (setq org-src-fontify-natively t)
Shouldn't that be enabled by default, now, as there so many users who
seems to be unaware of that?
Or is there a fear of impacts on overall performance?
Best regards,
Seb
--
Sebastien Vauban
```

Hi Sébastien, "Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org> writes: >> (setq org-src-fontify-natively t) > > Shouldn't that be enabled by default, now, as there so many users who > seems to be unaware of that? Well, I'm all for it. > Or is there a fear of impacts on overall performance? No, I don't think so. Can you create a separate thread and poll the user for whether they want this to be the default for the next major release? Thanks! -- Bastien

[-- Attachment #1: Type: text/plain, Size: 1111 bytes --] Hi, Bastien, > (By the way, you should fix the .el header, it says that the file is > part of Emacs while it's not.) Sorry I thought it was general GPL... Now it is updated. Thank you for pointing that out! > (setq org-src-fontify-natively t) Yes, I already set this. But curiously the Mathematica code is still not highlighted like other codes. I wonder there may be some non-standard things inside mma.el (the Mathematica package file major mode) then? Best, Yi On Thu, Jan 9, 2014 at 10:28 AM, Bastien <bzg@gnu.org> wrote: > Hi Yi, > > Yi Wang <tririverwangyi@gmail.com> writes: > > > As far as I can find, there is no babel support for Mathematica. So I > > wrote one and share it in case other people are interested: > > > > https://github.com/tririver/wy-els/blob/master/ob-mathematica.el > > Nice, thanks for sharing! > > (By the way, you should fix the .el header, it says that the file is > part of Emacs while it's not.) > > > While writing this extension, I have a question: How to add font-lock > > mode in org code blocks? > > (setq org-src-fontify-natively t) > > HTH, > > -- > Bastien > [-- Attachment #2: Type: text/html, Size: 2743 bytes --]

```
Yi Wang <tririverwangyi@gmail.com> writes:
> Yes, I already set this. But curiously the Mathematica code is still
> not highlighted like other codes. I wonder there may be some
> non-standard things inside mma.el (the Mathematica package file major
> mode) then?
I don't think so, you may just have to check that the mode defined in
mma.el is automatically boundled with .m files -- which is not the case
with a default Emacs installation, where .m files are open with
objc-mode.
--
Bastien
```

[-- Attachment #1: Type: text/plain, Size: 1359 bytes --] > I don't think so, you may just have to check that the mode defined in > mma.el is automatically boundled with .m files -- which is not the case > with a default Emacs installation, where .m files are open with > objc-mode. I already have this line in my configuration file: (add-to-list 'auto-mode-alist '("\\.m\\'" . mma-mode)) Now I have (1) If I open a .m file, there is font lock. Thus the problem shouldn't be binding between mma.el and .m files. (2) If I insert a src block of C or python code in org mode, there is font lock. Thus the problem shouldn't be org-src-fontify-natively (and I checked it is indeed t). This is why I am confused. Actually I don't badly need this feature. Just it would be a little better to have things work properly. Best, Yi On Thu, Jan 9, 2014 at 10:55 AM, Bastien <bzg@altern.org> wrote: > Yi Wang <tririverwangyi@gmail.com> writes: > > > Yes, I already set this. But curiously the Mathematica code is still > > not highlighted like other codes. I wonder there may be some > > non-standard things inside mma.el (the Mathematica package file major > > mode) then? > > I don't think so, you may just have to check that the mode defined in > mma.el is automatically boundled with .m files -- which is not the case > with a default Emacs installation, where .m files are open with > objc-mode. > > -- > Bastien > [-- Attachment #2: Type: text/html, Size: 3089 bytes --]

```
Yi Wang <tririverwangyi@gmail.com> writes:
> (1) If I open a .m file, there is font lock. Thus the problem
> shouldn't be binding between mma.el and .m files.
> (2) If I insert a src block of C or python code in org mode, there is
> font lock. Thus the problem shouldn't be org-src-fontify-natively
> (and I checked it is indeed t).
What happen if you C-c ' on a .m block?
--
Bastien
```

[-- Attachment #1: Type: text/plain, Size: 916 bytes --] Ah, now the problem appears. It says "No such language mode: mathematica-mode". So there is a mismatch between the name mathematica (which I used as name in org-babel extension) and the name mma-mode (which is provided by mma.el). However, as auto-mode-alist suggests (where there is ("\\.m\\'" . mma-mode), and no entry with mathematica-mode), I still have no idea why org-edit-special looks for mathematica-mode instead of mma-mode. On Thu, Jan 9, 2014 at 11:15 AM, Bastien <bzg@altern.org> wrote: > Yi Wang <tririverwangyi@gmail.com> writes: > > > (1) If I open a .m file, there is font lock. Thus the problem > > shouldn't be binding between mma.el and .m files. > > (2) If I insert a src block of C or python code in org mode, there is > > font lock. Thus the problem shouldn't be org-src-fontify-natively > > (and I checked it is indeed t). > > What happen if you C-c ' on a .m block? > > -- > Bastien > [-- Attachment #2: Type: text/html, Size: 1482 bytes --]

[-- Attachment #1: Type: text/plain, Size: 1190 bytes --] Now it worked. I added (add-to-list 'org-src-lang-modes '("mathematica" . "mma")). After that font lock and edit source works. Thank @Bastien for the help! On Thu, Jan 9, 2014 at 11:31 AM, Yi Wang <tririverwangyi@gmail.com> wrote: > Ah, now the problem appears. It says "No such language mode: > mathematica-mode". > > So there is a mismatch between the name mathematica (which I used as name > in org-babel extension) and the name mma-mode (which is provided by > mma.el). > > However, as auto-mode-alist suggests (where there is ("\\.m\\'" . > mma-mode), and no entry with mathematica-mode), I still have no idea > why org-edit-special looks for mathematica-mode instead of mma-mode. > > > On Thu, Jan 9, 2014 at 11:15 AM, Bastien <bzg@altern.org> wrote: > >> Yi Wang <tririverwangyi@gmail.com> writes: >> >> > (1) If I open a .m file, there is font lock. Thus the problem >> > shouldn't be binding between mma.el and .m files. >> > (2) If I insert a src block of C or python code in org mode, there is >> > font lock. Thus the problem shouldn't be org-src-fontify-natively >> > (and I checked it is indeed t). >> >> What happen if you C-c ' on a .m block? >> >> -- >> Bastien >> > > [-- Attachment #2: Type: text/html, Size: 2094 bytes --]

I recently saw this posting about org support for Mathematica. Thanks for writing this! Unfortunately, while I can get it to work for simple things (e.g., 2+3), even slightly more complex things don't seem to work. For example, suppose I'd like to define a function f(x) = x + 3, and then calculate f(5). In a MMA notebook, if I type f[x_] := x+3 f[5] I get the answer 8. If I try the same code in an org-mode code block, here's what happens: #+BEGIN_SRC mathematica f[x_] := x+3 f[5] #+END_SRC #+RESULTS: : Null Am I missing something obvious here? Thanks very much. Richard Stanton

I wonder if this is an output vs value issue on the return of the block. If you set :results output does anything change? or, is there a way to specify a return value? or specifically print something? Richard Stanton writes: > I recently saw this posting about org support for Mathematica. Thanks for writing this! > > Unfortunately, while I can get it to work for simple things (e.g., 2+3), even slightly more complex things don't seem to work. For example, suppose I'd like to define a function f(x) = x + 3, and then calculate f(5). In a MMA notebook, if I type > > f[x_] := x+3 > f[5] > > I get the answer 8. If I try the same code in an org-mode code block, here's what happens: > > #+BEGIN_SRC mathematica > f[x_] := x+3 > f[5] > #+END_SRC > > #+RESULTS: > : Null > > Am I missing something obvious here? > > Thanks very much. > > Richard Stanton -- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu

[-- Attachment #1: Type: text/plain, Size: 1860 bytes --] Dear Richard, You can do: #+BEGIN_SRC mathematica f[x_] := x+3; f[5] #+END_SRC Here are explanations: I actually put everything in the SRC block into a Print[...]. So in the second example, what actually runs is Print[f[x_] := x+3 f[5]] This does not return any value. Because what it really does is print the value of "f[x_] := x+3 f[5]" Here is the code: (concat (mapconcat ;; define any variables (lambda (pair) (format "%s=%s;" (car pair) (org-babel-mathematica-var-to-mathematica (cdr pair)))) vars "\n") "\nPrint[\n" body "\n]\n") If anybody has idea to improve it, I will be happy to see and work it out! Best, Yi On Sat, Mar 14, 2015 at 7:09 AM John Kitchin <jkitchin@andrew.cmu.edu> wrote: > I wonder if this is an output vs value issue on the return of the > block. If you set :results output does anything change? or, is there a > way to specify a return value? or specifically print something? > > Richard Stanton writes: > > > I recently saw this posting about org support for Mathematica. Thanks > for writing this! > > > > Unfortunately, while I can get it to work for simple things (e.g., 2+3), > even slightly more complex things don't seem to work. For example, suppose > I'd like to define a function f(x) = x + 3, and then calculate f(5). In a > MMA notebook, if I type > > > > f[x_] := x+3 > > f[5] > > > > I get the answer 8. If I try the same code in an org-mode code block, > here's what happens: > > > > #+BEGIN_SRC mathematica > > f[x_] := x+3 > > f[5] > > #+END_SRC > > > > #+RESULTS: > > : Null > > > > Am I missing something obvious here? > > > > Thanks very much. > > > > Richard Stanton > > -- > Professor John Kitchin > Doherty Hall A207F > Department of Chemical Engineering > Carnegie Mellon University > Pittsburgh, PA 15213 > 412-268-7803 > @johnkitchin > http://kitchingroup.cheme.cmu.edu > [-- Attachment #2: Type: text/html, Size: 3986 bytes --]

[-- Attachment #1: Type: text/plain, Size: 2454 bytes --] Thanks. After a bit of experimentation, I found that you can have a block outputting several lines, but you need to manually add commas and carriage returns, e.g., #+BEGIN_SRC mathematica :results output f[x_] := 3*x^2+3; f[8], "\n", D[f[x],x] #+END_SRC #+RESULTS: : 195 : 6*x > On Mar 13, 2015, at 4:16 PM, Yi Wang <tririverwangyi@gmail.com> wrote: > > Dear Richard, > > You can do: > > #+BEGIN_SRC mathematica > f[x_] := x+3; > f[5] > #+END_SRC > > Here are explanations: I actually put everything in the SRC block into a Print[...]. > > So in the second example, what actually runs is > > Print[f[x_] := x+3 > f[5]] > > This does not return any value. Because what it really does is print the value of "f[x_] := x+3 f[5]" > > Here is the code: > > (concat > (mapconcat ;; define any variables > (lambda (pair) > (format "%s=%s;" > (car pair) > (org-babel-mathematica-var-to-mathematica (cdr pair)))) > vars "\n") "\nPrint[\n" body "\n]\n") > > If anybody has idea to improve it, I will be happy to see and work it out! > > Best, > Yi > > > > > On Sat, Mar 14, 2015 at 7:09 AM John Kitchin <jkitchin@andrew.cmu.edu <mailto:jkitchin@andrew.cmu.edu>> wrote: > I wonder if this is an output vs value issue on the return of the > block. If you set :results output does anything change? or, is there a > way to specify a return value? or specifically print something? > > Richard Stanton writes: > > > I recently saw this posting about org support for Mathematica. Thanks for writing this! > > > > Unfortunately, while I can get it to work for simple things (e.g., 2+3), even slightly more complex things don't seem to work. For example, suppose I'd like to define a function f(x) = x + 3, and then calculate f(5). In a MMA notebook, if I type > > > > f[x_] := x+3 > > f[5] > > > > I get the answer 8. If I try the same code in an org-mode code block, here's what happens: > > > > #+BEGIN_SRC mathematica > > f[x_] := x+3 > > f[5] > > #+END_SRC > > > > #+RESULTS: > > : Null > > > > Am I missing something obvious here? > > > > Thanks very much. > > > > Richard Stanton > > -- > Professor John Kitchin > Doherty Hall A207F > Department of Chemical Engineering > Carnegie Mellon University > Pittsburgh, PA 15213 > 412-268-7803 > @johnkitchin > http://kitchingroup.cheme.cmu.edu <http://kitchingroup.cheme.cmu.edu/> [-- Attachment #2: Type: text/html, Size: 6036 bytes --]