Skip to content

Commit

Permalink
Add support for Wolfram Language (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
dechamps authored Dec 11, 2022
1 parent 4d0e9a8 commit c511119
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/languages.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ Jupytext works with notebooks in any of the following languages:
- TypeScript
- Haskell
- Tcl
- Wolfram Language
- Note that Jupytext uses the non-standard `.wolfram` file extension for Wolfram Language files to avoid conflicts with Matlab.

Extending Jupytext to more languages should be easy, see the sections on [contributing to](contributing.md) and [developing](developing.md) Jupytext.
4 changes: 4 additions & 0 deletions jupytext/cell_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ def parse_rmd_options(line):
def rmd_options_to_metadata(options, use_runtools=False):
"""Parse rmd options and return a metadata dictionary"""
options = re.split(r"\s|,", options, 1)
# Special case Wolfram Language, which sadly has a space in the language
# name.
if options[0:2] == ["wolfram", "language"]:
options[0:2] = ["wolfram language"]
if len(options) == 1:
language = options[0]
chunk_options = []
Expand Down
9 changes: 9 additions & 0 deletions jupytext/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"haskell",
"tcl",
"gnuplot",
"wolfram language",
]

# Supported file extensions (and languages)
Expand All @@ -47,6 +48,14 @@
".ps1": {"language": "powershell", "comment": "#"},
".q": {"language": "q", "comment": "/"},
".m": {"language": "matlab", "comment": "%"},
# Unfortunately, Wolfram Mathematica also uses the .m extension which
# conflicts with Matlab. To work around this problem we arbitrarily use a
# made-up .wolfram extension.
".wolfram": {
"language": "wolfram language",
"comment": "(*",
"comment_suffix": "*)",
},
".pro": {"language": "idl", "comment": ";"},
".js": {"language": "javascript", "comment": "//"},
".ts": {"language": "typescript", "comment": "//"},
Expand Down
122 changes: 122 additions & 0 deletions tests/notebooks/ipynb_wolfram/wolfram.ipynb

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions tests/notebooks/mirror/ipynb_to_Rmd/wolfram.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
jupyter:
kernelspec:
display_name: Wolfram Language 13.1
language: Wolfram Language
name: wolframlanguage13.1
---

**Note:** The `language_info` `file_extension` in this notebook should be `.m`, but it was deliberately changed to `.wolfram` to avoid conflicts with Matlab which is using the same extension.


We start with...

```{wolfram language}
Print["Hello, World!"];
```

Then we draw the first example plot from the [ListPlot](https://reference.wolfram.com/language/ref/ListPlot.html) reference:

```{wolfram language}
ListPlot[Prime[Range[25]]]
```

We also test the math outputs as in the [Simplify](https://reference.wolfram.com/language/ref/Simplify.html) example:

```{wolfram language}
D[Integrate[1/(x^3 + 1), x], x]
```
28 changes: 28 additions & 0 deletions tests/notebooks/mirror/ipynb_to_hydrogen/wolfram.wolfram
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(* --- *)
(* jupyter: *)
(* kernelspec: *)
(* display_name: Wolfram Language 13.1 *)
(* language: Wolfram Language *)
(* name: wolframlanguage13.1 *)
(* --- *)

(* %% [markdown] *)
(* **Note:** The `language_info` `file_extension` in this notebook should be `.m`, but it was deliberately changed to `.wolfram` to avoid conflicts with Matlab which is using the same extension. *)

(* %% [markdown] *)
(* We start with... *)

(* %% *)
Print["Hello, World!"];

(* %% [markdown] *)
(* Then we draw the first example plot from the [ListPlot](https://reference.wolfram.com/language/ref/ListPlot.html) reference: *)

(* %% *)
ListPlot[Prime[Range[25]]]

(* %% [markdown] *)
(* We also test the math outputs as in the [Simplify](https://reference.wolfram.com/language/ref/Simplify.html) example: *)

(* %% *)
D[Integrate[1/(x^3 + 1), x], x]
28 changes: 28 additions & 0 deletions tests/notebooks/mirror/ipynb_to_md/wolfram.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
jupyter:
kernelspec:
display_name: Wolfram Language 13.1
language: Wolfram Language
name: wolframlanguage13.1
---

**Note:** The `language_info` `file_extension` in this notebook should be `.m`, but it was deliberately changed to `.wolfram` to avoid conflicts with Matlab which is using the same extension.


We start with...

```wolfram language
Print["Hello, World!"];
```

Then we draw the first example plot from the [ListPlot](https://reference.wolfram.com/language/ref/ListPlot.html) reference:

```wolfram language
ListPlot[Prime[Range[25]]]
```

We also test the math outputs as in the [Simplify](https://reference.wolfram.com/language/ref/Simplify.html) example:

```wolfram language
D[Integrate[1/(x^3 + 1), x], x]
```
28 changes: 28 additions & 0 deletions tests/notebooks/mirror/ipynb_to_myst/wolfram.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
kernelspec:
display_name: Wolfram Language 13.1
language: Wolfram Language
name: wolframlanguage13.1
---

**Note:** The `language_info` `file_extension` in this notebook should be `.m`, but it was deliberately changed to `.wolfram` to avoid conflicts with Matlab which is using the same extension.

+++

We start with...

```{code-cell} mathematica
Print["Hello, World!"];
```

Then we draw the first example plot from the [ListPlot](https://reference.wolfram.com/language/ref/ListPlot.html) reference:

```{code-cell} mathematica
ListPlot[Prime[Range[25]]]
```

We also test the math outputs as in the [Simplify](https://reference.wolfram.com/language/ref/Simplify.html) example:

```{code-cell} mathematica
D[Integrate[1/(x^3 + 1), x], x]
```
28 changes: 28 additions & 0 deletions tests/notebooks/mirror/ipynb_to_percent/wolfram.wolfram
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(* --- *)
(* jupyter: *)
(* kernelspec: *)
(* display_name: Wolfram Language 13.1 *)
(* language: Wolfram Language *)
(* name: wolframlanguage13.1 *)
(* --- *)

(* %% [markdown] *)
(* **Note:** The `language_info` `file_extension` in this notebook should be `.m`, but it was deliberately changed to `.wolfram` to avoid conflicts with Matlab which is using the same extension. *)

(* %% [markdown] *)
(* We start with... *)

(* %% *)
Print["Hello, World!"];

(* %% [markdown] *)
(* Then we draw the first example plot from the [ListPlot](https://reference.wolfram.com/language/ref/ListPlot.html) reference: *)

(* %% *)
ListPlot[Prime[Range[25]]]

(* %% [markdown] *)
(* We also test the math outputs as in the [Simplify](https://reference.wolfram.com/language/ref/Simplify.html) example: *)

(* %% *)
D[Integrate[1/(x^3 + 1), x], x]
21 changes: 21 additions & 0 deletions tests/notebooks/mirror/ipynb_to_script/wolfram.wolfram
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(* --- *)
(* jupyter: *)
(* kernelspec: *)
(* display_name: Wolfram Language 13.1 *)
(* language: Wolfram Language *)
(* name: wolframlanguage13.1 *)
(* --- *)

(* **Note:** The `language_info` `file_extension` in this notebook should be `.m`, but it was deliberately changed to `.wolfram` to avoid conflicts with Matlab which is using the same extension. *)

(* We start with... *)

Print["Hello, World!"];

(* Then we draw the first example plot from the [ListPlot](https://reference.wolfram.com/language/ref/ListPlot.html) reference: *)

ListPlot[Prime[Range[25]]]

(* We also test the math outputs as in the [Simplify](https://reference.wolfram.com/language/ref/Simplify.html) example: *)

D[Integrate[1/(x^3 + 1), x], x]

0 comments on commit c511119

Please sign in to comment.