📝

卒論を支える技術

に公開

私が学部の卒論を書くにあたって利用した技術を雑に紹介します。

組版システム

組版システムには Typst を利用しました。

Typstは、一言で言うと、爆速でコンパイル可能なMarkdown風の文法を持つLaTeXです。


文法がLaTeXとかなり違うため最初は戸惑うかもしれませんが、リアルタイムコンパイルから得られる体験は素晴らしいです。タイプした瞬間にプレビューが更新されるのは非常に快適です。コンパイルに10秒以上待たされるLaTeXにはもう戻れません。

https://typst.app/

有志による日本語訳:

https://typst-jp.github.io/docs/

テンプレート

私が自分用に作成している次のテンプレートをベースに、適宜カスタマイズする形で執筆しました。

https://github.com/r4ai/rjs

実際に私が卒論で利用したテンプレートを以下に示します:

PDF: https://r4ai.github.io/rjs/thesis.pdf

https://github.com/r4ai/rjs/blob/main/examples/thesis/main.typ

コードブロック

コードブロックの装飾にはCodlyを利用しました。

Codlyは、Typst用のコードブロック装飾パッケージで、行番号の表示や、いい感じにインデントする機能などを提供してくれます。

Typstのデフォルトのコードブロックはかなり質素な見た目なので、こういった装飾パッケージを併用するのがおすすめです。

https://typst.app/universe/package/codly/

疑似コード

疑似コードの記述にはalgorithmicを利用しました。

algorithmicは、Typst用の疑似コード記述パッケージで、Typst内で疑似コードが書けるようになります。LaTeXの algorithmicx のTypst版みたいなイメージです。

特にこだわりはないですが、一番メンテナンスされてそうだったので選びました。

https://typst.app/universe/package/algorithmic/

環境構築

環境構築には Devcontainer を利用しました。

締め切りが近くなるとパソコンは壊れるものなので、再現性のある開発環境をあらかじめ構築しておきましょう。

https://containers.dev/

次に、実際に利用したDevcontainerの設定ファイルを参考までに示します:

{
  "name": "COMPILER",
  "build": {
    "dockerfile": "./Dockerfile",
    "context": "..",
    "args": {
      "USERNAME": "vscode",
      "USER_UID": "1000",
      "USER_GID": "1000"
    }
  },
  "remoteUser": "vscode",
  "mounts": [
    "source=${localWorkspaceFolder}/.devcontainer/.zshrc,target=/home/vscode/.zshrc,type=bind,consistency=cached",
    "source=${localWorkspaceFolder}/.devcontainer/.codex,target=/home/vscode/.codex,type=bind,consistency=cached",
    "source=${localWorkspaceFolder}/.devcontainer/.claude,target=/home/vscode/.claude,type=bind,consistency=cached"
  ],
  "customizations": {
    "vscode": {
      "extensions": [
        "llvm-vs-code-extensions.vscode-clangd",
        "ms-azuretools.vscode-docker",
        "EditorConfig.EditorConfig",
      ],
      "settings": {
        "terminal.integrated.defaultProfile.linux": "zsh"
      }
    }
  },
  "features": {
    "ghcr.io/devcontainers/features/github-cli:1": {},
    "ghcr.io/jungaretti/features/ripgrep:1": {},
    "ghcr.io/jsburckhardt/devcontainer-features/bat:1": {},
    "ghcr.io/devcontainers-extra/features/hyperfine:1": {},
    "ghcr.io/devcontainers/features/common-utils:2": {
      "installOhMyZsh": true,
      "installZsh": true,
      "configureZshAsDefaultShell": true
    },
    "ghcr.io/devcontainers-extra/features/fzf:1": {}
  }
}

ClaudeやCodexのセッションが永続化されるように、~/.claude などは .devcontainer/.claude にバインドマウントしています。また、zshやripgrep、fzfなどの便利ツールはDevcontainerのFeaturesを利用してインストールしています。

CI/CD

CIにはGitHub Actionsを利用しました。

実行環境は、devcontainers/ci を使い、Devcontainerをそのまま利用しました。
こういった点でも、Devcontainerは作っておくと便利です。

https://github.com/devcontainers/ci

次に、実際に利用したワークフローファイルを参考までに示します:

# .github/workflows/ci.yml

name: CI

on:
  push:
    branches:
      - main
  pull_request:

permissions:
  contents: read
  packages: write

jobs:
  ci:
    runs-on: ubuntu-24.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Free disk space
        run: |
          df -h
          sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache /usr/local/share/powershell
          sudo apt-get clean
          docker system prune -af
          df -h

      - name: Cache compiler build outputs
        uses: actions/cache@v4
        with:
          path: |
            compiler/.build.dir
            compiler/install
          key: ${{ runner.os }}-compiler-build-${{ hashFiles('compiler/CMakeLists.txt', 'compiler/**/CMakeLists.txt', 'compiler/**/*.cmake', 'compiler/Makefile') }}-v1
          restore-keys: |
            ${{ runner.os }}-compiler-build-

      - name: Create necessary dirs
        run: |
          mkdir -p .devcontainer/.codex
          mkdir -p .devcontainer/.claude

      - name: Run in devcontainer
        uses: devcontainers/ci@v0.3
        with:
          configFile: .devcontainer/devcontainer.json
          imageName: ghcr.io/${{ github.repository }}-devcontainer
          cacheFrom: ghcr.io/${{ github.repository }}-devcontainer
          push: always
          runCmd: |
            npm ci

            # Build
            just build-compiler || { echo "Build failed"; exit 1; }

            # Unit Tests
            just test-compiler || { echo "Unit Tests failed"; exit 1; }

            # E2E Tests
            SKIP_BUILD=1 just test-e2e || { echo "E2E Tests failed"; exit 1; }

なお、普通に実行した際にディスク容量不足によるエラーが発生したため、不要なファイルを削除するステップを追加しています。

文章校正

文書校正には Textlint を利用しました。

https://textlint.org/

https://github.com/textlint/textlint-plugin-typst

また、Textlint では対応できない文脈を考慮した校正はClaudeにやってもらいました[1]。

校正のためのプロンプトは、次のページを参考に作成しました。

https://kazov.site/Nis/study/JIS/editing.html

脚注
  1. ChatGPTやGeminiもありますが、自然な日本語の文章作成能力はClaudeが一番高いと感じたため、Claudeを採用しました。 ↩︎

Discussion