Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Created January 20, 2023 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zr-tex8r/e0931df922f38fbb67634f05dfdaf66b to your computer and use it in GitHub Desktop.
Save zr-tex8r/e0931df922f38fbb67634f05dfdaf66b to your computer and use it in GitHub Desktop.
LuaLaTeX+LuaTeX-jaの下でイロイロな文字を出力してみるやつ
% LuaLaTeX文書; 文字コードはUTF-8
\documentclass[a4paper]{ltjsarticle}
\usepackage[noto-jp]{luatexja-preset}
% 欧文はLatin Modernのまま
\usepackage{newunicodechar,luacode}
%↓入力中のU+FFFDを一旦U+F8FDに置き換える
\begin{luacode*}
luatexbase.add_to_callback('process_input_buffer', function (s)
if s:match('\xef\xbf\xbd') then
return s:gsub('\xef\xbf\xbd', '\xef\xa3\xbd')
end
end, 'hedge_fffd')
\end{luacode*}
%
% - 基本的に"その字形があるフォント"を指定すればOK
% - "欧文側"のフォントで出したい場合は \ltjalchar"<符号値>
% - 特定の文字だけフォントを変えたい場合は \newunicodechar
% で文字を"命令化"して命令定義中でフォントを変える
%
%↓U+212Aの入力 → 'K'(U+004B)を出力
\newunicodechar{^^^^212a}{K}
%↓U+FFFDのグリフをもつフォントを用意する
\newfontface{\fRepC}{DejaVu Sans Mono}
%↓U+F8FDの入力 → U+FFFDを(欧文で, フォント変更して)出力
\newunicodechar{^^^^f8fd}{{\fRepC\ltjalchar"FFFD}}
\begin{document}
テスト。
\begin{verbatim}
U+017F -> ſ
U+212A -> K
U+FFFD -> �
\end{verbatim}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment