Skip to content

Instantly share code, notes, and snippets.

@nagae
Last active September 27, 2015 23:48
Show Gist options
  • Save nagae/1350983 to your computer and use it in GitHub Desktop.
Save nagae/1350983 to your computer and use it in GitHub Desktop.
OTFパッケージ確認用のTeXサンプル
\documentclass[10pt,a4paper]{jsarticle}
\title{\tt{otf}パッケージのフォント設定}
\author{長江 剛志}
\date{}
\usepackage[expert,deluxe]{otf}
\usepackage{listings}
\lstset{
language={TeX},
basicstyle=\ttfamily,
columns=[l]{fullflexible}
}
\usepackage{colortbl}
\newcommand{\jugem}{寿限無 寿限無 五劫の摺り切れ 海砂利水魚の 水行末 雲来末 
風来末 食う寝る所に住む所, Supercalifragilisticexpialidocious!}
\newcommand{\GC}{\cellcolor[gray]{.8}}
\begin{document}
\maketitle
\section{準備}
\verb|\documentclass{jsarticle}|と\verb|\begin{document}|の間に以下を記述しておく.
\begin{lstlisting}[frame=single]
\usepackage[expert,deluxe]{otf}
\end{lstlisting}
{\tt dvipdfmx}でPDF化する際に,
{\tt dvipdfmx -f otf-hiragino}などとフォントマップを指定する必要がある.
フォントを埋め込んだPDFの再配布には注意が必要.
\section{フォントの指定方法}
\label{sec:font}
フォントは「family」「series」「shape」の3つを組合せて指定する.書式は以下の通り
\begin{lstlisting}[frame=single]
{\**family \**series \**shape テキスト}
\end{lstlisting}
\begin{description}
\item[family] 明朝/ゴシックといったフォントの「体」に相当する.
欧文と和文でそれぞれ個別に指定できるが,
{\tt otf}パッケージを使う場合,欧文を指定すると,
それに追従して和文も変更される.逆に,和文を指定した
だけでは欧文は追従変更されず,デフォルト(Roman体)のままとなる.
デフォルトは欧文はRoman体({\tt rm-}), 和文は明朝体({\tt mc-}).
\begin{table}[h]
\begin{tabular}{cc}
\begin{minipage}[t]{0.5\textwidth}
\centering
欧文(追従する和文)\\
\begin{tabular}{rl}
\hline
\tt{\textbackslash{}rmfamily} & {\rmfamily Roman (明朝体)}\\
\tt{\textbackslash{}sffamily} & {\sffamily Sans-serif (ゴシック体)}\\
\tt{\textbackslash{}ttfamily} & {\ttfamily Typewriter (ゴシック体)}\\
\hline
\end{tabular}\\
\end{minipage}
&
\begin{minipage}[t]{0.5\textwidth}
\centering
和文(追従する欧文)\\
\begin{tabular}{rl}
\hline
\tt{\textbackslash{}mcfamily} & {\mcfamily 明朝体 (Roman)}\\
\tt{\textbackslash{}gtfamily} & {\gtfamily ゴシック体 (Roman)}\\
\tt{\textbackslash{}mgfamily} & {\mgfamily 丸文字ゴシック体 (Roman)}\\
\hline
\end{tabular}
\end{minipage}
\end{tabular}
\end{table}
\item[series] フォントの「太さ」を指定する.
「普通」「太字」「極太字」の3種類があるが,
上述の{\tt family}ごとに使える太さに限りがある.
デフォルトは「普通({\tt medium-})」.
\begin{table}[h]
\centering
\begin{tabular}{rllllll}
\hline
& {\tt\textbackslash{}rmfamily}
& {\tt\textbackslash{}sffamily}
& {\tt\textbackslash{}ttfamily}
\\
\hline
{\tt\textbackslash{}mdseries} & {\mdseries medium} &
{\sffamily\mdseries medium} & {\ttfamily\mdseries medium} \\
{\tt\textbackslash{}bfseries} & {\bfseries bold} &
{\sffamily\bfseries bold} & \GC{\ttfamily\bfseries bold} \\
{\tt\textbackslash{}ebseries} & \GC{\ebseries extra bold} &
\GC{\sffamily\ebseries extra bold}& \GC{\ttfamily\ebseries extra bold}\\
\hline
& {\tt\textbackslash{}mcfamily}
& {\tt\textbackslash{}gtfamily}
& {\tt\textbackslash{}mgfamily}
\\
\hline
{\tt\textbackslash{}mdseries} & {\mcfamily\mdseries 標準の太さ}&
{\gtfamily\mdseries 標準の太さ}& {\mgfamily\mdseries 標準の太さ}\\
{\tt\textbackslash{}bfseries} & {\mcfamily\bfseries 太字} &
{\gtfamily\bfseries 太字} & \GC{\mgfamily\bfseries 太字} \\
{\tt\textbackslash{}ebseries} & \GC{\mcfamily\ebseries 極太字} &
{\gtfamily\ebseries 極太字} & \GC{\mgfamily\ebseries 極太字} \\
\hline
\end{tabular}
\end{table}
\pagebreak
\item[shape] フォントの「修飾」を指定する.和文フォントには影響しない.
\begin{table}[h]
\centering
\begin{tabular}{rl}
\hline
{\tt\textbackslash{}upshape} & {\upshape 直立体(default)}\\
{\tt\textbackslash{}itshape} & {\itshape 斜体(italic)}\\
{\tt\textbackslash{}slshape} & {\slshape 傾斜体(slant).直立体を傾けただけ}\\
{\tt\textbackslash{}scshape} & {\scshape スモールキャピタル体(small
capital)}\\
\hline
\end{tabular}
\end{table}
\end{description}
\section{フォント設定の短縮形定義}
family, series, shape をそれぞれ設定するのは面倒.
そこで,よく使う以下の5つの組み合わせについては短縮形が定義されている.
\begin{lstlisting}[frame=single]
{\rm テキスト} = {\rmfamily\mediumseries\upshape テキスト}
{\bf テキスト} = {\rmfamily\bfseries \upshape テキスト}
{\sf テキスト} = {\sffamily\mediumseries\upshape テキスト}
{\tt テキスト} = {\ttfamily\mediumseries\upshape テキスト}
{\it テキスト} = {\rmfamily\mediumseries\itshape テキスト}
\end{lstlisting}
\begin{description}
\item [{\tt\textbackslash{}rm}(Roman/明朝)] \ \\{\rm \jugem}
\item [{\tt\textbackslash{}bf}(Roman/明朝+太字)] \ \\{\bf \jugem}
\item [{\tt\textbackslash{}sf}(Sans-serif/ゴシック) ] \ \\{\sf \jugem}
\item [{\tt\textbackslash{}tt}(Typewriter/ゴシック) ] \ \\{\tt \jugem}
\item [{\tt\textbackslash{}it}(Roman/明朝+斜体)] \ \\{\it \jugem}
\end{description}
\end{document}
@nagae
Copy link
Author

nagae commented Nov 9, 2011

platex と dvipdfm のテスト.TeX Live 2013 をインストールし,ヒラギノフォントへのリンクが適切に貼られているとする.

curl -LO https://gist.github.com/nagae/1350983/raw/sample.tex
platex sample.tex
dvipdfm -f otf-hiragino -o sample_hiragino_minimum.pdf sample.dvi
dvipdfm -f otf-ipaex -o sample_hiragino_ipeex.pdf sample.dvi
dvipdfm -o sample_default.pdf sample.dvi
open sample*.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment