Open11

Windowsのフォントを楽に扱うLuaTeX-ja on WSL環境の構築めも

leviosa42leviosa42

モチベーション

  • latexでレポートを書きたい
  • Windows上にtexliveをインストールしたくない
    • Windows環境が汚れない
    • タイプセットが早くなる(らしい)
  • Windowsのフォントを使いたい
    • DockerコンテナからOSのフォント扱う方法がよく分かってない
    • WSL2なら/mmt/c/fontsからアクセスできる
leviosa42leviosa42

WSLのUbuntu-24.04の初期セットアップした直後のデータを複製して、新規ディストリビューションUbuntu-24.04-TL24で作業する。

とりあえず、Ubuntuのapt mirrorの設定って結局どうすればいいの?を参考にミラーサーバーを日本の速そうなところにしてaptの更新諸々を済ませる。

$ sudo sed -i.bak -r 's@http://(jp\.)?archive\.ubuntu\.com/ubuntu/?@https://ftp.udx.icscoe.jp/Linux/ubuntu/@g' /etc/apt/sources.list.d/ubuntu.sources
$ sudo apt update && sudo apt upgrade -y
leviosa42leviosa42
適当な作業用ディレクトリを用意して移動
$ mkdir /tmp/install-tl24 && cd $_ 
インストーラーをダウンロードして展開
$ wget http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz -O - | tar -xz --strip-components 1
インストーラーを起動した様子
$ perl install-tl
======================> TeX Live installation procedure <=====================

======>   Letters/digits in <angle brackets> indicate   <=======
======>   menu items for actions or customizations      <=======
= help>   https://tug.org/texlive/doc/install-tl.html   <=======

 Detected platform: GNU/Linux on x86_64

 <B> set binary platforms: 1 out of 15

 <S> set installation scheme: scheme-full

 <C> set installation collections:
     40 collections out of 41, disk space required: 8404 MB (free: 977133 MB)

 <D> set directories:
   TEXDIR (the main TeX directory):
     !! default location: /usr/local/texlive/2024
     !! is not writable or not allowed, please select a different one!
   TEXMFLOCAL (directory for site-wide local files):
     /usr/local/texlive/texmf-local
   TEXMFSYSVAR (directory for variable and automatically generated data):
     /usr/local/texlive/2024/texmf-var
   TEXMFSYSCONFIG (directory for local config):
     /usr/local/texlive/2024/texmf-config
   TEXMFVAR (personal directory for variable and automatically generated data):
     ~/.texlive2024/texmf-var
   TEXMFCONFIG (personal directory for local config):
     ~/.texlive2024/texmf-config
   TEXMFHOME (directory for user-specific files):
     ~/texmf

 <O> options:
   [ ] use letter size instead of A4 by default
   [X] allow execution of restricted list of programs via \write18
   [X] create all format files
   [X] install macro/font doc tree
   [X] install macro/font source tree
   [ ] create symlinks to standard directories

 <V> set up for portable installation

Actions:
 <I> start installation to hard disk
 <P> save installation profile to 'texlive.profile' and exit
 <Q> quit

Enter command:
leviosa42leviosa42
B set binary platforms: (デフォルトは1)
 <B> set binary platforms: 1 out of 15
===============================================================================
Available platforms:

   a [ ] Cygwin on x86_64 (x86_64-cygwin)
   b [ ] MacOSX current (10.14-) on ARM/x86_64 (universal-darwin)
   c [ ] MacOSX legacy (10.6-) on x86_64 (x86_64-darwinlegacy)
   d [ ] FreeBSD on x86_64 (amd64-freebsd)
   e [ ] FreeBSD on Intel x86 (i386-freebsd)
   f [ ] GNU/Linux on ARM64 (aarch64-linux)
   g [ ] GNU/Linux on RPi(32-bit) and ARMv7 (armhf-linux)
   h [ ] GNU/Linux on Intel x86 (i386-linux)
   i [X] GNU/Linux on x86_64 (x86_64-linux)
   j [ ] GNU/Linux on x86_64 with musl (x86_64-linuxmusl)
   k [ ] NetBSD on x86_64 (amd64-netbsd)
   l [ ] NetBSD on Intel x86 (i386-netbsd)
   m [ ] Solaris on Intel x86 (i386-solaris)
   o [ ] Solaris on x86_64 (x86_64-solaris)
   p [ ] Windows (64-bit) (windows)

Actions: (disk space required: 8404 MB)
 <-> deselect all
 <+> select all
 <R> return to main menu
 <Q> quit

Enter letter(s) to (de)select platforms:
<S> set installation scheme: (デフォルトはscheme-full)
 <S> set installation scheme: scheme-full
===============================================================================
Select scheme:

 a [X] full scheme (everything)
 b [ ] medium scheme (small + more packages and languages)
 c [ ] small scheme (basic + xetex, metapost, a few languages)
 d [ ] basic scheme (plain and latex)
 e [ ] minimal scheme (plain only)
 f [ ] infrastructure-only scheme (no TeX at all)
 g [ ] book publishing scheme (core LaTeX and add-ons)
 h [ ] ConTeXt scheme
 i [ ] GUST TeX Live scheme
 j [ ] teTeX scheme (more than medium, but nowhere near full)
 k [ ] custom selection of collections

Actions: (disk space required: 8404 MB)
 <R> return to main menu
 <Q> quit

Enter letter to select scheme:
<C> set installation collections:
 <C> set installation collections:
     40 collections out of 41, disk space required: 8404 MB (free: 977133 MB)
===============================================================================
Select collections:

 a [X] Essential programs and files      w [X] Italian
 b [X] BibTeX additional styles          x [X] Japanese
 c [X] TeX auxiliary programs            y [X] Korean
 d [X] ConTeXt and packages              z [X] Other languages
 e [X] Additional fonts                  A [X] Polish
 f [X] Recommended fonts                 B [X] Portuguese
 g [X] Graphics and font utilities       C [X] Spanish
 h [X] Additional formats                D [X] LaTeX fundamental packages
 i [X] Games typesetting                 E [X] LaTeX additional packages
 j [X] Humanities packages               F [X] LaTeX recommended packages
 k [X] Arabic                            G [X] LuaTeX packages
 l [X] Chinese                           H [X] MetaPost and Metafont packages
 m [X] Chinese/Japanese/Korean (base)    I [X] Music packages
 n [X] Cyrillic                          J [X] Graphics, pictures, diagrams
 o [X] Czech/Slovak                      K [X] Plain (La)TeX packages
 p [X] US and UK English                 L [X] PSTricks
 s [X] Other European languages          M [X] Publisher styles, theses, etc.
 t [X] French                            N [X] Windows-only support programs
 u [X] German                            O [X] XeTeX and packages
 v [X] Greek
 P [X] Mathematics, natural sciences, computer science packages
 S [X] TeXworks editor; TL includes only the Windows binary

Actions: (disk space required: 8404 MB)
 <-> deselect all
 <+> select all
 <R> return to main menu
 <Q> quit

Enter letter(s) to (de)select collection(s):

::: <D>

 <D> set directories:
   TEXDIR (the main TeX directory):
     !! default location: /usr/local/texlive/2024
     !! is not writable or not allowed, please select a different one!
   TEXMFLOCAL (directory for site-wide local files):
     /usr/local/texlive/texmf-local
   TEXMFSYSVAR (directory for variable and automatically generated data):
     /usr/local/texlive/2024/texmf-var
   TEXMFSYSCONFIG (directory for local config):
     /usr/local/texlive/2024/texmf-config
   TEXMFVAR (personal directory for variable and automatically generated data):
     ~/.texlive2024/texmf-var
   TEXMFCONFIG (personal directory for local config):
     ~/.texlive2024/texmf-config
   TEXMFHOME (directory for user-specific files):
     ~/texmf
===============================================================================
Directories customization:

!! The default location as given below is forbidden or
!! can't be written to.
!! Either change the destination directory using <1> or create it
!! outside this script.
 <1> TEXDIR:         /usr/local/texlive/2024
     main tree:      /usr/local/texlive/2024/texmf-dist

 <2> TEXMFLOCAL:     /usr/local/texlive/texmf-local
 <3> TEXMFSYSVAR:    /usr/local/texlive/2024/texmf-var
 <4> TEXMFSYSCONFIG: /usr/local/texlive/2024/texmf-config

 <5> TEXMFVAR:       ~/.texlive2024/texmf-var
 <6> TEXMFCONFIG:    ~/.texlive2024/texmf-config
 <7> TEXMFHOME:      ~/texmf

 Note: ~ will expand to $HOME (or to %USERPROFILE% on Windows)

Actions:
 <R> return to main menu
 <Q> quit

Enter command:
<O> options:
 <O> options:
   [ ] use letter size instead of A4 by default
   [X] allow execution of restricted list of programs via \write18
   [X] create all format files
   [X] install macro/font doc tree
   [X] install macro/font source tree
   [ ] create symlinks to standard directories
===============================================================================
Options customization:

 <P> use letter size instead of A4 by default: [ ]
 <E> execution of restricted list of programs: [X]
 <F> create all format files:                  [X]
 <D> install font/macro doc tree:              [X]
 <S> install font/macro source tree:           [X]
 <L> create symlinks in standard directories:  [ ]
            binaries to:
            manpages to:
                info to:

Actions: (disk space required: 8404 MB)
 <R> return to main menu
 <Q> quit

Enter command:

Vは普通の(==ハードディスクへ)インストールするかポータブルインストールか切り替える用。Vを選択すると文面が切り替わる。

<V> set up for portable installation
<V> set up for regular installation to hard disk

デフォルトだと普通のインストールになる(はず)

leviosa42leviosa42

<B> binary platoforms

  • 弄らなくてok
  • デフォルトで i [X] GNU/Linux on x86_64 (x86_64-linux)が選択されている

<S> scheme

  • スキームはscheme-customにする
    • サイズがデカい(約8GB)、今回は大学のレポート用に使うので不必要なパッケージも多い
    • キーストロークはメニュー画面からS<Enter>k<Enter>R<Enter>
    • メニュー画面で<S> set installation scheme: scheme-customになっていれば変更できている

<C> collections

コレクションの選択画面 (-afmxDEFGJP を選択した状態)
===============================================================================
Select collections:

 a [X] Essential programs and files      w [ ] Italian
 b [ ] BibTeX additional styles          x [X] Japanese
 c [ ] TeX auxiliary programs            y [ ] Korean
 d [ ] ConTeXt and packages              z [ ] Other languages
 e [ ] Additional fonts                  A [ ] Polish
 f [X] Recommended fonts                 B [ ] Portuguese
 g [ ] Graphics and font utilities       C [ ] Spanish
 h [ ] Additional formats                D [X] LaTeX fundamental packages
 i [ ] Games typesetting                 E [X] LaTeX additional packages
 j [ ] Humanities packages               F [X] LaTeX recommended packages
 k [ ] Arabic                            G [X] LuaTeX packages
 l [ ] Chinese                           H [ ] MetaPost and Metafont packages
 m [X] Chinese/Japanese/Korean (base)    I [ ] Music packages
 n [ ] Cyrillic                          J [X] Graphics, pictures, diagrams
 o [ ] Czech/Slovak                      K [ ] Plain (La)TeX packages
 p [ ] US and UK English                 L [ ] PSTricks
 s [ ] Other European languages          M [ ] Publisher styles, theses, etc.
 t [ ] French                            N [ ] Windows-only support programs
 u [ ] German                            O [ ] XeTeX and packages
 v [ ] Greek
 P [X] Mathematics, natural sciences, computer science packages
 S [ ] TeXworks editor; TL includes only the Windows binary

Actions: (disk space required: 1297 MB)
 <-> deselect all
 <+> select all
 <R> return to main menu
 <Q> quit

Enter letter(s) to (de)select collection(s):

<O> options

  • ドキュメントやソースのファイルはインストールしなくても動くみたいなのでインストールさせない
  • キーストロークはメニュー画面からO<Enter>D<Enter>S<Enter>R<Enter>
  • 3088 MBから1087 MBまで減る(ドキュメントで3GBくらい持ってかれるみたい)

ドキュメントファイルやソースファイルのインストール有無:4. ソースとドキュメントを除く(texmf-dist/src, texmf-dist/doc)
texadvent2017-tl16frozen.profile で以下のようにしています。

option_doc 0
option_src 0

これらのオプションはデフォルトで 1 となっています。
どーせ、みんな、ググっちゃうから、ディスクの肥やしになる!?ドキュメントもソースも要らんかもですねー ;-)
https://qiita.com/munepi/items/f2eaa30f0cd00a9a68f8

<D> directries

<V> portable

  • 弄らない
  • メニューに <V> set up for portable installationが表示されていればいい

<P>を選択すると設定した情報がプロファイルtexlive.profileに書き込まれて終了するようなので見てみる

texlive.profile
# texlive.profile written on Fri Jul  5 15:15:24 2024 UTC
# It will NOT be updated and reflects only the
# installation profile at installation time.
selected_scheme scheme-custom
TEXDIR /usr/local/texlive/2024
TEXMFCONFIG ~/.texlive2024/texmf-config
TEXMFHOME ~/texmf
TEXMFLOCAL /usr/local/texlive/texmf-local
TEXMFSYSCONFIG /usr/local/texlive/2024/texmf-config
TEXMFSYSVAR /usr/local/texlive/2024/texmf-var
TEXMFVAR ~/.texlive2024/texmf-var
binary_x86_64-linux 1
collection-basic 1
collection-fontsrecommended 1
collection-langcjk 1
collection-langjapanese 1
collection-latex 1
collection-latexextra 1
collection-latexrecommended 1
collection-luatex 1
collection-mathscience 1
collection-pictures 1
instopt_adjustpath 0
instopt_adjustrepo 1
instopt_letter 0
instopt_portable 0
instopt_write18_restricted 1
tlpdbopt_autobackup 1
tlpdbopt_backupdir tlpkg/backups
tlpdbopt_create_formats 1
tlpdbopt_desktop_integration 1
tlpdbopt_file_assocs 1
tlpdbopt_generate_updmap 0
tlpdbopt_install_docfiles 0
tlpdbopt_install_srcfiles 0
tlpdbopt_post_code 1
tlpdbopt_sys_bin /usr/local/bin
tlpdbopt_sys_info /usr/local/share/info
tlpdbopt_sys_man /usr/local/share/man
tlpdbopt_w32_multi_user 1
leviosa42leviosa42
$ sudo ./install-tl -profile texlive.profile -repository http://ftp.jaist.ac.jp/pub/CTAN/systems/texlive/tlnet/

でインストールしたら一時間ほどかかった。

以下のコマンドでtlmgrなどにパスが通せる。

$ /usr/local/texlive/2024/bin/x86_64-linux/tlmgr path add
leviosa42leviosa42

補足すると、インストール開始50分前後で一度CTRL+Cで無理やり停止させた後、もう一度上記のコマンドを実行した。既にインストールしてあるパッケージは再ダウンロードしない処理みたいなので、インストールを途中で停止させても続きからインストールできる(※各パッケージがインストールされているかどうか確認は入るので多少遅くなっているかも)

leviosa42leviosa42

手元のレポートをタイプセットしようとしてエラーが起きていたのでメモ。

表で siunitx を使用する際のクラッシュ #11と同様のエラーが起きてタイプセットが通らない。

\documentclass{ltjsarticle}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{S}
  1
\end{tabular}
\end{document}
出力結果
出力結果
This is LuaHBTeX, Version 1.18.0 (TeX Live 2024)
 restricted system commands enabled.
(./main.tex
LaTeX2e <2024-06-01> patch level 2
L3 programming layer <2024-05-27>
 (/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/ltjsarticle.cls
Document Class: ltjsarticle 2022/09/12 ltjsclasses
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/luatexja.sty
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/luatexja-core.sty
(/usr/local/texlive/2024/texmf-dist/tex/generic/infwarerr/infwarerr.sty)
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexbase/luatexbase.sty
(/usr/local/texlive/2024/texmf-dist/tex/luatex/ctablestack/ctablestack.sty))
(/usr/local/texlive/2024/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty)
(/usr/local/texlive/2024/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty
(/usr/local/texlive/2024/texmf-dist/tex/generic/iftex/iftex.sty))
(/usr/local/texlive/2024/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/local/texlive/2024/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/local/texlive/2024/texmf-dist/tex/generic/xkeyval/xkvutils.tex
(/usr/local/texlive/2024/texmf-dist/tex/generic/xkeyval/keyval.tex))))
(/usr/local/texlive/2024/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/local/texlive/2024/texmf-dist/tex/latex/everyhook/everyhook.sty
(/usr/local/texlive/2024/texmf-dist/tex/latex/svn-prov/svn-prov.sty))
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/ltj-base.sty)
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/ltj-latex.sty
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/patches/lltjfont.sty
(/usr/local/texlive/2024/texmf-dist/tex/latex/base/tuenc.def))
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/patches/lltjdefs.sty
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/jfm-ujisv.lua)
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/jfm-ujis.lua))
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/patches/lltjcore.sty
(/usr/local/texlive/2024/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2024/texmf-dist/tex/latex/l3backend/l3backend-luatex.def)))

(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/patches/lltjp-atbegshi.
sty)
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/patches/lltjp-geometry.
sty (/usr/local/texlive/2024/texmf-dist/tex/generic/iftex/ifluatex.sty))))
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/luatexja-compat.sty))
(/usr/local/texlive/2024/texmf-dist/tex/platex/jsclasses/jslogo.sty)
(/usr/local/texlive/2024/texmf-dist/tex/latex/sttools/stfloats.sty)
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/patches/lltjp-stfloats.
sty)) (/usr/local/texlive/2024/texmf-dist/tex/latex/siunitx/siunitx.sty
(/usr/local/texlive/2024/texmf-dist/tex/latex/translations/translations.sty)
(/usr/local/texlive/2024/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2024/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2024/texmf-dist/tex/latex/tools/array.sty))
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/patches/lltjp-siunitx.s
ty)
(/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/patches/lltjp-array.sty
) (/usr/local/texlive/2024/texmf-dist/tex/latex/graphics/color.sty
(/usr/local/texlive/2024/texmf-dist/tex/latex/graphics-cfg/color.cfg)
(/usr/local/texlive/2024/texmf-dist/tex/latex/graphics-def/luatex.def)
(/usr/local/texlive/2024/texmf-dist/tex/latex/graphics/mathcolor.ltx))
(./main.aux) (/usr/local/texlive/2024/texmf-dist/tex/latex/base/ts1cmr.fd)
(/usr/local/texlive/2024/texmf-dist/tex/latex/translations/translations-basic-d
ictionary-english.trsl)
(/usr/local/texlive/2024/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
))
Runaway argument?
\ignorespaces 1 \end {tabular} \end {document}
! File ended while scanning use of \__siunitx_table_collect_begin:w.
<inserted text>
\par
<*> main.tex

?
issue通り、これだと通る
+\documentclass{article}
-\documentclass{ltjsarticle}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{S}
  1
\end{tabular}
\end{document}
leviosa42leviosa42

(初めて返信できることに気付いた)

latexが参照するluatexja.styをtexliveで入れたstyファイルからgit cloneしてきた自前のstyファイルに変更する必要がある。さらに今回のissueのパッチはまだリリースされていないため、パッチがコミットされているkitagawa_testブランチにcheckoutする必要もある

元々はこう
$ kpsewhich luatexja.sty
/usr/local/texlive/2024/texmf-dist/tex/luatex/luatexja/luatexja.sty
$ kpsewhich -var-value TEXMFLOCAL # TEXMFLOCALのパスを確認する
/usr/local/texlive/texmf-local
$ cd $(kpsewhich -var-value)/tex
$ sudo git clone https://github.com/luatexja/luatexja
$ sudo git checkout kitagawa_test
$ sudo mktexlsr
変更後
$ kpsewhich luatexja.sty
/usr/local/texlive/texmf-local/tex/luatexja/src/luatexja.sty
leviosa42leviosa42

ここをみてWSL2上でもWindows側のフォントが扱えるように設定する。/etc/fonts/local.confに書き込める手段なら何でもいい。今回は以下のコマンドで書き込んだ。(コピペできるように$プロンプトは省略。)

cat << EOF | sudo tee /etc/fonts/local.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <dir>/mnt/c/Windows/Fonts</dir>
</fontconfig>
EOF

fc-cache -fvするのにfontconfigをインストールした

$ sudo apt install -y fontconfig
$ sudo fc-cache -fv