1
1

typst フォント まとめ

Last updated at Posted at 2024-04-20

はじめに

typst で用いることができる日本語フォントをまとめました.

結果

以下の通り.
一部のフォントでは,対応する日本語フォントが存在しないため,デフォルトのフォントで出力されている.

fonts1.png

fonts2.png

fonts3.png

fonts4.png

fonts5.png

fonts6.png

方法

方法についても記載しておく.
typst をインストールしたのち,コマンドラインから以下を実行してフォント一覧を得る.

typst fonts > fonts.txt

python で適当にフォーマットし,jsonファイルにする.
なお,エンコーディングを指定しているのは,Windows 環境では cp932 云々のエラーがごちゃごちゃぬかしたため.

format.py
import json

def txt_to_json(input_file, output_file, encoding='utf-8'):
    # テキストファイルを読み込み
    with open(input_file, 'r', encoding=encoding) as f:
        lines = f.readlines()

    # JSON形式に整形
    entries = [{"name": line.strip()} for line in lines]

    # JSONファイルに書き込み
    with open(output_file, 'w', encoding=encoding) as f:
        json.dump({"entries": entries}, f, indent=4, ensure_ascii=False)

# 入力ファイルと出力ファイルを指定して実行
input_file = "fonts.txt"
output_file = "fonts.json"
txt_to_json(input_file, output_file, encoding='utf-8')  # エンコーディングを適切に指定する

最後に次の typ ファイルをコンパイルすれば,ok.
fonts.typ のコードは 参考文献[1] を参考にさせていただきました.ありがとうございます.

fonts.typ
== フォント
#let text_example = "Hello World! 木曾路はすべて山の中である。"
#for entry in json("fonts.json").at("entries") {
  text(
    font:entry.name,
    [- #entry.name : #text_example]
    )
}

今回は png 形式で出力する.

typst compile fonts.typ fonts{n}.png

参考文献

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1