*Babel language support for Mathematica@ 2014-01-09 3:46 Yi Wang2014-01-09 10:28 ` Bastien 0 siblings, 1 reply; 14+ messages in thread From: Yi Wang @ 2014-01-09 3:46 UTC (permalink / raw) To: emacs-orgmode;+Cc:Yi Wang [-- 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 --] ^ permalink raw reply [flat|nested] 14+ messages in thread

*

**Re: Babel language support for Mathematica**2014-01-09 3:46 Babel language support for Mathematica Yi Wang**@ 2014-01-09 10:28 ` Bastien**2014-01-09 10:34 ` Sebastien Vauban 2014-01-09 10:51 ` Yi Wang 0 siblings, 2 replies; 14+ messages in thread From: Bastien @ 2014-01-09 10:28 UTC (permalink / raw) To: Yi Wang;**+Cc:**emacs-orgmode 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 ^ permalink raw reply [flat|**nested**] 14+ messages in thread*

**Re: Babel language support for Mathematica**2014-01-09 10:28 ` Bastien**@ 2014-01-09 10:34 ` Sebastien Vauban**2014-01-09 10:39 ` Bastien 2014-01-09 10:51 ` Yi Wang 1 sibling, 1 reply; 14+ messages in thread From: Sebastien Vauban @ 2014-01-09 10:34 UTC (permalink / raw) To: emacs-orgmode-mXXj517/zsQ 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 ^ permalink raw reply [flat|**nested**] 14+ messages in thread*

**Re: Babel language support for Mathematica**2014-01-09 10:34 ` Sebastien Vauban**@ 2014-01-09 10:39 ` Bastien**0 siblings, 0 replies; 14+ messages in thread From: Bastien @ 2014-01-09 10:39 UTC (permalink / raw) To: Sebastien Vauban;**+Cc:**public-emacs-orgmode-mXXj517/zsQ 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 ^ permalink raw reply [flat|**nested**] 14+ messages in thread

*

**Re: Babel language support for Mathematica**2014-01-09 10:28 ` Bastien 2014-01-09 10:34 ` Sebastien Vauban**@ 2014-01-09 10:51 ` Yi Wang**2014-01-09 10:55 ` Bastien 1 sibling, 1 reply; 14+ messages in thread From: Yi Wang @ 2014-01-09 10:51 UTC (permalink / raw) To: Bastien;**+Cc:**emacs-orgmode [-- 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 --] ^ permalink raw reply [flat|**nested**] 14+ messages in thread*

**Re: Babel language support for Mathematica**2014-01-09 10:51 ` Yi Wang**@ 2014-01-09 10:55 ` Bastien**2014-01-09 11:03 ` Yi Wang 0 siblings, 1 reply; 14+ messages in thread From: Bastien @ 2014-01-09 10:55 UTC (permalink / raw) To: Yi Wang;**+Cc:**emacs-orgmode 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 ^ permalink raw reply [flat|**nested**] 14+ messages in thread*

2014-01-09 10:55 ` Bastien**Re: Babel language support for Mathematica****@ 2014-01-09 11:03 ` Yi Wang**2014-01-09 11:15 ` Bastien 0 siblings, 1 reply; 14+ messages in thread From: Yi Wang @ 2014-01-09 11:03 UTC (permalink / raw) To: Bastien;**+Cc:**emacs-orgmode [-- 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 --] ^ permalink raw reply [flat|**nested**] 14+ messages in thread*

**Re: Babel language support for Mathematica**2014-01-09 11:03 ` Yi Wang**@ 2014-01-09 11:15 ` Bastien**2014-01-09 11:31 ` Yi Wang 0 siblings, 1 reply; 14+ messages in thread From: Bastien @ 2014-01-09 11:15 UTC (permalink / raw) To: Yi Wang;**+Cc:**emacs-orgmode 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 ^ permalink raw reply [flat|**nested**] 14+ messages in thread*

**Re: Babel language support for Mathematica**2014-01-09 11:15 ` Bastien**@ 2014-01-09 11:31 ` Yi Wang**2014-01-09 11:49 ` Yi Wang 0 siblings, 1 reply; 14+ messages in thread From: Yi Wang @ 2014-01-09 11:31 UTC (permalink / raw) To: Bastien;**+Cc:**emacs-orgmode [-- 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 --] ^ permalink raw reply [flat|**nested**] 14+ messages in thread*

**Re: Babel language support for Mathematica**2014-01-09 11:31 ` Yi Wang**@ 2014-01-09 11:49 ` Yi Wang**0 siblings, 0 replies; 14+ messages in thread From: Yi Wang @ 2014-01-09 11:49 UTC (permalink / raw) To: Bastien;**+Cc:**emacs-orgmode [-- 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 --] ^ permalink raw reply [flat|**nested**] 14+ messages in thread

*Re: Babel language support for Mathematica@ 2015-03-13 23:06 Richard Stanton2015-03-13 23:09 ` John Kitchin 0 siblings, 1 reply; 14+ messages in thread From: Richard Stanton @ 2015-03-13 23:06 UTC (permalink / raw) To: emacs-orgmode;+Cc:tririverwangyi 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 ^ permalink raw reply [flat|nested] 14+ messages in thread

*

**Re: Babel language support for Mathematica**2015-03-13 23:06 Richard Stanton**@ 2015-03-13 23:09 ` John Kitchin**2015-03-13 23:16 ` Yi Wang 0 siblings, 1 reply; 14+ messages in thread From: John Kitchin @ 2015-03-13 23:09 UTC (permalink / raw) To: Richard Stanton;**+Cc:**emacs-orgmode, tririverwangyi 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 ^ permalink raw reply [flat|**nested**] 14+ messages in thread*

**Re: Babel language support for Mathematica**2015-03-13 23:09 ` John Kitchin**@ 2015-03-13 23:16 ` Yi Wang**2015-03-15 17:26 ` Richard Stanton 0 siblings, 1 reply; 14+ messages in thread From: Yi Wang @ 2015-03-13 23:16 UTC (permalink / raw) To: John Kitchin, Richard Stanton;**+Cc:**emacs-orgmode [-- 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 --] ^ permalink raw reply [flat|**nested**] 14+ messages in thread*

**Re: Babel language support for Mathematica**2015-03-13 23:16 ` Yi Wang**@ 2015-03-15 17:26 ` Richard Stanton**0 siblings, 0 replies; 14+ messages in thread From: Richard Stanton @ 2015-03-15 17:26 UTC (permalink / raw) To: Yi Wang;**+Cc:**emacs-orgmode, John Kitchin [-- 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 --] ^ permalink raw reply [flat|**nested**] 14+ messages in thread

end of thread, other threads:[~2015-03-15 17:27 UTC | newest]Thread overview:14+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-01-09 3:46 Babel language support for Mathematica Yi Wang 2014-01-09 10:28 ` Bastien 2014-01-09 10:34 ` Sebastien Vauban 2014-01-09 10:39 ` Bastien 2014-01-09 10:51 ` Yi Wang 2014-01-09 10:55 ` Bastien 2014-01-09 11:03 ` Yi Wang 2014-01-09 11:15 ` Bastien 2014-01-09 11:31 ` Yi Wang 2014-01-09 11:49 ` Yi Wang -- strict thread matches above, loose matches on Subject: below -- 2015-03-13 23:06 Richard Stanton 2015-03-13 23:09 ` John Kitchin 2015-03-13 23:16 ` Yi Wang 2015-03-15 17:26 ` Richard Stanton

Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).