# jupyter-JuliaFormatter: JuliaFormatter for Jupyter Notebook

**URL:** <https://discourse.julialang.org/t/jupyter-juliaformatter-juliaformatter-for-jupyter-notebook/89715>\
**Category:** Jupyter-Notebook\
**Tags:** announcement\
**Created:** [November 3, 2022, 1:59pm UTC](https://discourse.julialang.org/t/jupyter-juliaformatter-juliaformatter-for-jupyter-notebook/89715 "2022-11-03T13:59:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiangzhuochi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jiangzhuochi/32/44109_2.png) [@jiangzhuochi](https://discourse.julialang.org/u/jiangzhuochi)\
**Post date:** [November 3, 2022, 1:59pm UTC](https://discourse.julialang.org/t/jupyter-juliaformatter-juliaformatter-for-jupyter-notebook/89715/1 "2022-11-03T13:59:30Z")

</div>

GitHub repo [GitHub - jiangzhuochi/jupyter-JuliaFormatter: JuliaFormatter for Jupyter Notebook](https://github.com/jiangzhuochi/jupyter-JuliaFormatter)

# JuliaFormatter for Jupyter Notebook

Format Julia with JuliaFormatter in Jupyter Notebook

## 前置条件 pre-requisites

of course, you must have some of the corresponding packages installed:

```julia
add JuliaFormatter
add JSON

```

## 安装 Installation

```bash
jupyter nbextension install https://github.com/jiangzhuochi/jupyter-JuliaFormatter/archive/main.zip --user
jupyter nbextension enable jupyter-JuliaFormatter-main/jupyter-JuliaFormatter

```

## 功能 Features

- a toolbar button
- a keyboard shortcut for reformatting the current code-cell (default: Alt-F, Mac: Option-F)
- a keyboard shortcut for reformatting whole code-cells (default: Alt-Shift-F, Mac: Option-Shift-F, Same as vscode format shortcut)

## 配置文件 Configuration File

Support configuration files, `.JuliaFormatter.toml` must be the same as the current `.ipynb` file is in the same directory

## 自定义快捷键 Customize shortcut keys

> **[Installing jupyter\_contrib\_nbextensions — jupyter\_contrib\_nbextensions 0.5.0...](https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/install.html#enabling-disabling-extensions)**

You can then open the nbextensions tab on the tree (dashboard/file browser) notebook page to configure nbextensions. You will have access there to a dashboard where extensions can be enabled/disabled via checkboxes. Additionally a short documentation for each extension is displayed, and configuration options are presented.

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [November 13, 2022, 12:00pm UTC](https://discourse.julialang.org/t/jupyter-juliaformatter-juliaformatter-for-jupyter-notebook/89715/2 "2022-11-13T12:00:16Z")

</div>

Hi,

This looks like a very nice tool to have.

> [@jiangzhuochi](#):
>
> of course, you must have some of the corresponding packages installed:
> 
> ```julia
> add JuliaFormatter
> add JSON
> 
> ```

Do these packages need to be installed in the base (`@v1.8`) environment? Is it possible to install them in a different shared environment and specify that to the extension somehow? I prefer to keep my base environment as empty as possible.

---

<div class="post-metadata">

**Author:** ![jiangzhuochi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jiangzhuochi/32/44109_2.png) [@jiangzhuochi](https://discourse.julialang.org/u/jiangzhuochi)\
**Post date:** [November 13, 2022, 12:23pm UTC](https://discourse.julialang.org/t/jupyter-juliaformatter-juliaformatter-for-jupyter-notebook/89715/3 "2022-11-13T12:23:19Z")

</div>

Hi, digital\_carver:

I’m a novice in the julia language. I don’t know how to use the shared environment. If you install JSON and JuliaFormatter for each environment, I think it will work.

```julia
❯ mkdir MyProject
❯ cd .\MyProject\
❯ julia

julia> ]
(@v1.8) pkg> activate .
(MyProject) pkg> add JuliaFormatter
(MyProject) pkg> add JSON

ctrl + D

❯ jupyter notebook (or activate some_env then jupyter notebook)

```

---

<div class="post-metadata">

**Author:** ![jiangzhuochi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jiangzhuochi/32/44109_2.png) [@jiangzhuochi](https://discourse.julialang.org/u/jiangzhuochi)\
**Post date:** [November 13, 2022, 12:27pm UTC](https://discourse.julialang.org/t/jupyter-juliaformatter-juliaformatter-for-jupyter-notebook/89715/4 "2022-11-13T12:27:35Z")

</div>

The first time I used discourse, did you receive my reply? I don’t seem to quote your reply.

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [November 13, 2022, 5:53pm UTC](https://discourse.julialang.org/t/jupyter-juliaformatter-juliaformatter-for-jupyter-notebook/89715/5 "2022-11-13T17:53:50Z")

</div>

Thanks, I’ll try out the extension at some point and let you know how it goes.

> [@jiangzhuochi](#):
>
> The first time I used discourse, did you receive my reply? I don’t seem to quote your reply.

Yeah, Discourse seems pretty smart about it - because I’m the only other person in the thread, it marked your post as a reply and notified me.

---

<div class="post-metadata">

**Author:** ![alusiani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alusiani/32/16415_2.png) [@alusiani](https://discourse.julialang.org/u/alusiani)\
**Post date:** [May 22, 2024, 7:28am UTC](https://discourse.julialang.org/t/jupyter-juliaformatter-juliaformatter-for-jupyter-notebook/89715/6 "2024-05-22T07:28:02Z")

</div>

Hi,

does anybody have experience about whether this Julia formatter (or any other Julia formatter) works with Jupyter Lab 4.\* ? I note that the documentation installation text is out of date, using “jupyter nbextension”, so I presume that the whole package may be outdated.

Alberto

---

<div class="post-metadata">

**Author:** ![navdeeprana](https://avatars.discourse-cdn.com/v4/letter/n/3da27b/32.png) [@navdeeprana](https://discourse.julialang.org/u/navdeeprana)\
**Post date:** [May 22, 2024, 9:31am UTC](https://discourse.julialang.org/t/jupyter-juliaformatter-juliaformatter-for-jupyter-notebook/89715/7 "2024-05-22T09:31:08Z")

</div>

I just use this

```bash
jupytext --pipe "julia -e 'using JuliaFormatter; format_file(ARGS[1]; margin=150)' {}" notebook.ipynb

```
