Skip to content

Instantly share code, notes, and snippets.

@mokztk
Last active February 25, 2023 22:29
Show Gist options
  • Save mokztk/610b83cd520e3f71c9165a6645b441a4 to your computer and use it in GitHub Desktop.
Save mokztk/610b83cd520e3f71c9165a6645b441a4 to your computer and use it in GitHub Desktop.
jupyter/r-notebook に日本語環境と自動補完の jupyterlab-lsp を導入した作業用イメージ

About this image

jupyter/r-notebook に日本語環境と自動補完の jupyterlab-lsp を導入したもの

  • 日本語ロケール他:Ubuntu の language-pack-ja-base パッケージ
  • TZ は Asia/Tokyo に変更
  • 日本語フォントとして Noto Sans/Serif CJK JP:fonts-noto-cjk
  • 日本語を含むノートブックをPDFエクスポートできるよう日本語TeX環境:texlive-lang-japanese
    • Bxjsarticle + Zxjafont で Noto CJK フォントを使用するようテンプレート(index.tex.j2)を修正
    • IPA (ex|) Gothic/Mincho も導入されているので、jafont= の設定を変えれば IPAフォントも可

Jupyter Lab の設定

  • --LabApp.token='' でパスワードなしとする
  • 対応するカッコを自動で閉じる、コードセルの行番号、日本語表示などは overrides.json でまとめて設定
version: "3"
services:
jupyter:
image: "mokztk/r-notebook:latest"
container_name: "jupyter"
command: >
start.sh
jupyter lab
--no-browser
--LabApp.token=''
ports:
- "8888:8888"
volumes:
# Settings
- .\overrides.json:/opt/conda/share/jupyter/lab/settings/overrides.json
# Data
FROM jupyter/r-notebook:latest
# 日本語環境の導入(ロケール、TimeZone、フォント、TeX環境)
USER root
RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
language-pack-ja-base \
fonts-noto-cjk \
texlive-lang-japanese \
&& /usr/sbin/update-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP:ja" \
&& /bin/bash -c "source /etc/default/locale" \
&& ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Jupyter Lab extensions のインストール
# 日本語表示の有効化などは、/opt/conda/share/jupyter/lab/settings/overrides.json で
USER ${NB_UID}
RUN set -x \
&& mamba install -y \
jupyterlab-language-pack-ja-jp \
jupyter-lsp \
nodejs \
&& jupyter labextension install @krassowski/jupyterlab-lsp \
&& mamba install -y \
python-lsp-server \
r-languageserver \
&& mamba clean --all -f -y \
&& fix-permissions "${CONDA_DIR}" \
&& fix-permissions "/home/${NB_USER}"
# 日本語を含む文書をPDFエクスポートできるよう、TeX template を上書き
# Bxjsarticle, Zxjafont で Noto CJK fonts を使用する設定
COPY --chown=${NB_UID}:${NB_GID} index.tex.j2 /opt/conda/share/jupyter/nbconvert/templates/latex/
ENV LANG=ja_JP.UTF-8 \
LANGUAGE=ja_JP.UTF-8 \
LC_ALL=ja_JP.UTF-8 \
TZ=Asia/Tokyo
((=- Default to the notebook output style -=))
((*- if not cell_style is defined -*))
((* set cell_style = 'style_jupyter.tex.j2' *))
((*- endif -*))
((=- Inherit from the specified cell style. -=))
((* extends cell_style *))
%===============================================================================
% Latex Article
%===============================================================================
((*- block docclass -*))
%\documentclass[11pt]{article}
\documentclass[a4paper,xelatex,ja=standard,jafont=noto,nothreeweight]{bxjsarticle}
((*- endblock docclass -*))
{
// 言語設定
"@jupyterlab/translation-extension:plugin": {
"locale": "ja_JP"
},
// テーマ設定
"@jupyterlab/apputils-extension:themes": {
"theme": "JupyterLab Dark",
"overrides": {
"content-font-size1": "18px",
"code-font-size": "16px"
}
},
// コード記載部分:カッコを自動で閉じる設定、タブ、行番号など
"@jupyterlab/notebook-extension:tracker": {
"codeCellConfig": {
"autoClosingBrackets": true,
"lineNumbers": true,
"matchBrackets": true,
"insertSpaces": true,
"tabSize": 4
},
"markdownCellConfig": {
"autoClosingBrackets": true,
"lineNumbers": true,
"matchBrackets": true,
"insertSpaces": true,
"tabSize": 4
}
},
"@jupyterlab/console-extension:tracker": {
"promptCellConfig": {
"autoClosingBrackets": true,
"matchBrackets": true,
"insertSpaces": true,
"tabSize": 4
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment