jfontsパッケージ

はじめに

LaTeXでPDFに和文フォントを埋め込む際、いちいちmapファイルを書き換えるのは面倒である。そこでjfontsパッケージというLaTeXパッケージを作った。簡単な工夫だが、役に立つ。

jfontsパッケージは、otfパッケージと併用することを前提としている。フォントを変えたいときはフォントのファイル名を書き換えればよい。

jfonts.sty

%
% jfonts.sty
%

\NeedsTeXFormat{pLaTeX2e}
\ProvidesPackage{jfonts}

\def\jf@hminl{ToppanBunkyuMincho-Regular.otf}
\def\jf@hminr{HiraMinProN-W3.otf}
\def\jf@hminb{HiraMinProN-W6.otf}
\def\jf@hgothr{HiraKakuProN-W3.otf}
\def\jf@hgothb{HiraKakuProN-W6.otf}
\def\jf@hgotheb{HiraKakuStdN-W8.otf}
\def\jf@hmgothr{HiraMaruPro-W4.otf}

\AtBeginDvi{%
    % TEXT, 90JIS
    \special{pdf:mapline hminl-h H \jf@hminl}%
    \special{pdf:mapline hminl-v V \jf@hminl}%
    \special{pdf:mapline hminr-h H \jf@hminr}%
    \special{pdf:mapline hminr-v V \jf@hminr}%
    \special{pdf:mapline hminb-h H \jf@hminb}%
    \special{pdf:mapline hminb-v V \jf@hminb}%
    \special{pdf:mapline hgothr-h H \jf@hgothr}%
    \special{pdf:mapline hgothr-v V \jf@hgothr}%
    \special{pdf:mapline hgothb-h H \jf@hgothb}%
    \special{pdf:mapline hgothb-v V \jf@hgothb}%
    \special{pdf:mapline hgotheb-h H \jf@hgotheb}%
    \special{pdf:mapline hgotheb-v V \jf@hgotheb}%
    \special{pdf:mapline hmgothr-h H \jf@hmgothr}%
    \special{pdf:mapline hmgothr-v V \jf@hmgothr}%
    % TEXT, JIS04
    \special{pdf:mapline hminln-h H \jf@hminl}%
    \special{pdf:mapline hminln-v V \jf@hminl}%
    \special{pdf:mapline hminrn-h H \jf@hminr}%
    \special{pdf:mapline hminrn-v V \jf@hminr}%
    \special{pdf:mapline hminbn-h H \jf@hminb}%
    \special{pdf:mapline hminbn-v V \jf@hminb}%
    \special{pdf:mapline hgothrn-h H \jf@hgothr}%
    \special{pdf:mapline hgothrn-v V \jf@hgothr}%
    \special{pdf:mapline hgothbn-h H \jf@hgothb}%
    \special{pdf:mapline hgothbn-v V \jf@hgothb}%
    \special{pdf:mapline hgothebn-h H \jf@hgotheb}%
    \special{pdf:mapline hgothebn-v V \jf@hgotheb}%
    \special{pdf:mapline hmgothrn-h H \jf@hmgothr}%
    \special{pdf:mapline hmgothrn-v V \jf@hmgothr}%
    % CID
    \special{pdf:mapline otf-cjml-h Identity-H \jf@hminl}%
    \special{pdf:mapline otf-cjml-v Identity-V \jf@hminl}%
    \special{pdf:mapline otf-cjmr-h Identity-H \jf@hminr/AJ16}%
    \special{pdf:mapline otf-cjmr-v Identity-V \jf@hminr/AJ16}%
    \special{pdf:mapline otf-cjmb-h Identity-H \jf@hminb/AJ16}%
    \special{pdf:mapline otf-cjmb-v Identity-V \jf@hminb/AJ16}%
    \special{pdf:mapline otf-cjgr-h Identity-H \jf@hgothr}%
    \special{pdf:mapline otf-cjgr-v Identity-V \jf@hgothr}%
    \special{pdf:mapline otf-cjgb-h Identity-H \jf@hgothb}%
    \special{pdf:mapline otf-cjgb-v Identity-V \jf@hgothb}%
    \special{pdf:mapline otf-cjge-h Identity-H \jf@hgotheb/AJ16}%
    \special{pdf:mapline otf-cjge-v Identity-V \jf@hgotheb/AJ16}%
    \special{pdf:mapline otf-cjmgr-h Identity-H \jf@hmgothr/AJ16}%
    \special{pdf:mapline otf-cjmgr-v Identity-V \jf@hmgothr/AJ16}%
    % Unicode 90JIS
    \special{pdf:mapline otf-ujml-h UniJIS-UTF16-H \jf@hminl}%
    \special{pdf:mapline otf-ujml-v UniJIS-UTF16-V \jf@hminl}%
    \special{pdf:mapline otf-ujmr-h UniJIS-UTF16-H \jf@hminr}%
    \special{pdf:mapline otf-ujmr-v UniJIS-UTF16-V \jf@hminr}%
    \special{pdf:mapline otf-ujmb-h UniJIS-UTF16-H \jf@hminb}%
    \special{pdf:mapline otf-ujmb-v UniJIS-UTF16-V \jf@hminb}%
    \special{pdf:mapline otf-ujgr-h UniJIS-UTF16-H \jf@hgothr}%
    \special{pdf:mapline otf-ujgr-v UniJIS-UTF16-V \jf@hgothr}%
    \special{pdf:mapline otf-ujgb-h UniJIS-UTF16-H \jf@hgothb}%
    \special{pdf:mapline otf-ujgb-v UniJIS-UTF16-V \jf@hgothb}%
    \special{pdf:mapline otf-ujge-h UniJIS-UTF16-H \jf@hgotheb}%
    \special{pdf:mapline otf-ujge-v UniJIS-UTF16-V \jf@hgotheb}%
    \special{pdf:mapline otf-ujmgr-h UniJIS-UTF16-H \jf@hmgothr}%
    \special{pdf:mapline otf-ujmgr-v UniJIS-UTF16-V \jf@hmgothr}%
    % Unicode JIS04
    \special{pdf:mapline otf-ujmln-h UniJIS2004-UTF16-H \jf@hminl}%
    \special{pdf:mapline otf-ujmln-v UniJIS2004-UTF16-V \jf@hminl}%
    \special{pdf:mapline otf-ujmrn-h UniJIS2004-UTF16-H \jf@hminr}%
    \special{pdf:mapline otf-ujmrn-v UniJIS2004-UTF16-V \jf@hminr}%
    \special{pdf:mapline otf-ujmbn-h UniJIS2004-UTF16-H \jf@hminb}%
    \special{pdf:mapline otf-ujmbn-v UniJIS2004-UTF16-V \jf@hminb}%
    \special{pdf:mapline otf-ujgrn-h UniJIS2004-UTF16-H \jf@hgothr}%
    \special{pdf:mapline otf-ujgrn-v UniJIS2004-UTF16-V \jf@hgothr}%
    \special{pdf:mapline otf-ujgbn-h UniJIS2004-UTF16-H \jf@hgothb}%
    \special{pdf:mapline otf-ujgbn-v UniJIS2004-UTF16-V \jf@hgothb}%
    \special{pdf:mapline otf-ujgen-h UniJIS2004-UTF16-H \jf@hgotheb}%
    \special{pdf:mapline otf-ujgen-v UniJIS2004-UTF16-V \jf@hgotheb}%
    \special{pdf:mapline otf-ujmgrn-h UniJIS2004-UTF16-H \jf@hmgothr}%
    \special{pdf:mapline otf-ujmgrn-v UniJIS2004-UTF16-V \jf@hmgothr}%
}%
\if@otf@uplatex
    \AtBeginDvi{%
        % TEXT, 90JIS
        \special{pdf:mapline uphminl-h UniJIS-UTF16-H \jf@hminl}%
        \special{pdf:mapline uphminl-v UniJIS-UTF16-V \jf@hminl}%
        \special{pdf:mapline uphminr-h UniJIS-UTF16-H \jf@hminr}%
        \special{pdf:mapline uphminr-v UniJIS-UTF16-V \jf@hminr}%
        \special{pdf:mapline uphminb-h UniJIS-UTF16-H \jf@hminb}%
        \special{pdf:mapline uphminb-v UniJIS-UTF16-V \jf@hminb}%
        \special{pdf:mapline uphgothr-h UniJIS-UTF16-H \jf@hgothr}%
        \special{pdf:mapline uphgothr-v UniJIS-UTF16-V \jf@hgothr}%
        \special{pdf:mapline uphgothb-h UniJIS-UTF16-H \jf@hgothb}%
        \special{pdf:mapline uphgothb-v UniJIS-UTF16-V \jf@hgothb}%
        \special{pdf:mapline uphgotheb-h UniJIS-UTF16-H \jf@hgotheb}%
        \special{pdf:mapline uphgotheb-v UniJIS-UTF16-V \jf@hgotheb}%
        \special{pdf:mapline uphmgothr-h UniJIS-UTF16-H \jf@hmgothr}%
        \special{pdf:mapline uphmgothr-v UniJIS-UTF16-V \jf@hmgothr}%
        % TEXT, JIS04
        \special{pdf:mapline uphminln-h UniJIS2004-UTF16-H \jf@hminl}%
        \special{pdf:mapline uphminln-v UniJIS2004-UTF16-V \jf@hminl}%
        \special{pdf:mapline uphminrn-h UniJIS2004-UTF16-H \jf@hminr}%
        \special{pdf:mapline uphminrn-v UniJIS2004-UTF16-V \jf@hminr}%
        \special{pdf:mapline uphminbn-h UniJIS2004-UTF16-H \jf@hminb}%
        \special{pdf:mapline uphminbn-v UniJIS2004-UTF16-V \jf@hminb}%
        \special{pdf:mapline uphgothrn-h UniJIS2004-UTF16-H \jf@hgothr}%
        \special{pdf:mapline uphgothrn-v UniJIS2004-UTF16-V \jf@hgothr}%
        \special{pdf:mapline uphgothbn-h UniJIS2004-UTF16-H \jf@hgothb}%
        \special{pdf:mapline uphgothbn-v UniJIS2004-UTF16-V \jf@hgothb}%
        \special{pdf:mapline uphgothebn-h UniJIS2004-UTF16-H \jf@hgotheb}%
        \special{pdf:mapline uphgothebn-v UniJIS2004-UTF16-V \jf@hgotheb}%
        \special{pdf:mapline uphmgothrn-h UniJIS2004-UTF16-H \jf@hmgothr}%
        \special{pdf:mapline uphmgothrn-v UniJIS2004-UTF16-V \jf@hmgothr}%
    }%
\fi

追記

いまだとTeX Liveに収録されているpxchfonパッケージがあるので、これを使って次のように書くのがラクである。

\usepackage[noalphabet]{pxchfon}
\setlightminchofont{ToppanBunkyuMincho-Regular.otf}
\setmediumminchofont{HiraMinProN-W3.otf}
\setboldminchofont{HiraMinProN-W6.otf}
\setmediumgothicfont{HiraKakuProN-W3.otf}
\setboldgothicfont{HiraKakuProN-W6.otf}
\setxboldgothicfont{HiraKakuStdN-W8.otf}
\setmarugothicfont{HiraMaruPro-W4.otf}
schedule 2019年3月30日
update 2021年12月5日
local_offer #LaTeX #LaTeXパッケージ #font