Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Wolfram Language #1014

Merged
merged 1 commit into from
Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]