pLaTeX を使用して日本語 PDF を作成する方法
pLaTeX を使って日本語の PDF 文書を作る手順をまとめた。ひな型の構成からコンパイル、よくあるエラーの対処まで解説する。
pLaTeX とは
pLaTeX は日本語組版に対応した LaTeX の実装である。platex コマンドで .tex ファイルをコンパイルし、dvipdfmx で PDF に変換する。
TeX Live に含まれているため、インストール済みであればすぐに使える。TeX Live のインストール手順は「Linux に TeX Live 2026 をインストールする」を参照。
文書クラスの選び方
日本語文書では以下のクラスを使う。
| クラス | 用途 |
|---|---|
jarticle | 論文・レポートなど短い文書 |
jbook | 書籍・章立てのある長い文書 |
jreport | 技術報告書(abstract + chapter 構成) |
beamer | プレゼンテーション |
ひな型(jarticle)
jarticle を使った基本的なサンプルは以下のとおり。
サンプルコードを表示する
% pLaTeX サンプル文書 — 主要機能を網羅
\documentclass[a4paper,12pt]{jarticle}
%% ========== パッケージ ==========
\usepackage{amsmath, amssymb} % 数式強化
\usepackage{graphicx} % 図の取り込み
\usepackage{color} % 色指定
\usepackage{fancyhdr} % ヘッダ・フッタ
\usepackage{geometry} % ページレイアウト
\usepackage{enumerate} % 列挙カスタマイズ
\usepackage{url} % URL 表示
\usepackage{multicol} % 段組み
\usepackage{booktabs} % 高品質な表罫線
\usepackage{array} % 表列書式拡張
\usepackage{verbatim} % verbatim 環境
\usepackage{ascmac} % 囲み環境(screen, itembox など)
\usepackage{okumacro} % ルビ・圏点など(pLaTeX 定番)
\usepackage{setspace} % 行間調整
\usepackage{listings} % ソースコードリスト
\usepackage{xcolor} % 色(listings 用)
\usepackage{caption} % キャプション書式
%% ========== ページレイアウト ==========
\geometry{top=25mm, bottom=25mm, left=25mm, right=25mm}
\setlength{\headheight}{17pt}
\addtolength{\topmargin}{-5pt}
%% ========== ヘッダ・フッタ ==========
\pagestyle{fancy}
\fancyhf{}
\lhead{pLaTeX サンプル文書}
\rhead{\today}
\cfoot{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
%% ========== listings 設定 ==========
\lstset{
basicstyle=\ttfamily\small,
keywordstyle=\color{blue}\bfseries,
commentstyle=\color{green!50!black},
stringstyle=\color{red!70!black},
numbers=left,
numberstyle=\tiny\color{gray},
frame=single,
breaklines=true,
tabsize=4,
}
%% ========== タイトル情報 ==========
\title{\textbf{pLaTeX 主要機能サンプル}\\[5pt]
\large --- 日本語 \LaTeX の典型的な使い方 ---}
\author{サンプル太郎\thanks{サンプル大学 情報工学部}
\and サンプル花子}
\date{\today}
%% ================================================================
\begin{document}
%% ================================================================
\maketitle
\thispagestyle{fancy}
\begin{abstract}
本文書は pLaTeX の主要機能を一通り示すサンプルである。
文書クラス・パッケージの読み込み、日本語組版特有の機能、
数式、表、図、相互参照、脚注、ルビ、圏点、
ソースコードリスト、段組み、カスタムコマンドなど
を順を追って解説する。
\end{abstract}
\tableofcontents
\newpage
%% ================================================================
\section{日本語組版の基本}
%% ================================================================
\subsection{和文・欧文の混在}
pLaTeX は日本語と欧文を自然に混在させることができる。
たとえば「Hello, World!」や \texttt{LaTeX2e} のような
ASCII 文字は自動的に適切なスペースが挿入される。
全角文字と半角文字の間隔調整は pLaTeX が自動で行う:
日本語English日本語、数字123日本語、記号\%日本語。
\subsection{ルビ(振り仮名)}
\texttt{okumacro} パッケージの \verb|\ruby| コマンドでルビを振れる。
\begin{center}
\ruby{漢字}{かんじ}、\ruby{情報処理}{じょうほうしょり}、
\ruby{自然言語}{しぜんげんご}\ruby{処理}{しょり}
\end{center}
\subsection{圏点}
\texttt{okumacro} の \verb|\kenten| で圏点(傍点)を付ける。
\begin{center}
\kenten{重要な箇所}には圏点を打つことができる。
\end{center}
\subsection{文字サイズ}
{\tiny 極小} {\scriptsize 脚注} {\footnotesize 小} {\small やや小}
{\normalsize 標準} {\large やや大} {\Large 大} {\LARGE 特大}
{\huge 超大} {\Huge 最大}
\subsection{文字装飾}
\begin{itemize}
\item \textbf{ボールド(太字)}
\item \textit{イタリック(欧文)}
\item \textsl{スラント}
\item \textsc{Small Caps}
\item \texttt{タイプライタ体(等幅)}
\item \underline{下線付きテキスト}
\item \textcolor{red}{赤色テキスト}
\item \textcolor{blue!70!black}{青色テキスト}
\item \colorbox{yellow}{ハイライト背景}
\end{itemize}
%% ================================================================
\section{文書構造}
%% ================================================================
\subsection{見出し階層}
pLaTeX(\texttt{jarticle})では以下の見出し階層が使える:
\verb|\section|、\verb|\subsection|、\verb|\subsubsection|、
\verb|\paragraph|、\verb|\subparagraph|。
\subsubsection{サブサブセクション例}
これはサブサブセクションである。
\paragraph{パラグラフ見出し}
これはパラグラフ見出しの例。インデントなしで本文が続く。
\subsection{脚注}
本文中に脚注\footnote{これが脚注のテキストである。ページ下部に自動配置される。}
を付けることができる。複数の脚注\footnote{2つ目の脚注。番号は自動採番される。}
も使える。
\subsection{相互参照}
\verb|\label| を付けると、
\verb|\ref| や \verb|\pageref| で参照できる。
例:次節は第~\ref{sec:math}~節(\pageref{sec:math}~ページ)。
%% ================================================================
\section{数式環境}
\label{sec:math}
%% ================================================================
\subsection{インライン数式とディスプレイ数式}
インライン数式:$E = mc^2$、$\alpha + \beta = \gamma$、
$\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$。
ディスプレイ数式:
\[
\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}
\]
\subsection{equation・align 環境}
番号付き数式(\texttt{equation}):
\begin{equation}
\label{eq:euler}
e^{i\pi} + 1 = 0
\end{equation}
式~\eqref{eq:euler} はオイラーの等式である。
複数行の整列(\texttt{align}):
\begin{align}
(a+b)^2 &= a^2 + 2ab + b^2 \\
(a-b)^2 &= a^2 - 2ab + b^2 \\
(a+b)(a-b) &= a^2 - b^2
\end{align}
\subsection{行列・ベクトル}
\begin{equation}
A = \begin{pmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{pmatrix},\quad
\det(A) = a_{11}a_{22} - a_{12}a_{21}
\end{equation}
\subsection{場合分け・分数・極限}
\begin{equation}
f(x) = \begin{cases}
x^2 & (x \geq 0) \\
-x^2 & (x < 0)
\end{cases}, \qquad
\lim_{n\to\infty} \left(1 + \frac{1}{n}\right)^n = e
\end{equation}
%% ================================================================
\section{表(tabular 環境)}
%% ================================================================
\subsection{基本的な表}
\begin{table}[h]
\centering
\caption{都市別気温データ(仮)}
\label{tab:temp}
\begin{tabular}{lrrr}
\toprule
都市 & 最高気温 (°C) & 最低気温 (°C) & 平均気温 (°C) \\
\midrule
東京 & 35.2 & 25.1 & 29.8 \\
大阪 & 36.4 & 26.3 & 31.0 \\
札幌 & 28.7 & 19.5 & 23.9 \\
那覇 & 32.1 & 27.4 & 29.8 \\
\bottomrule
\end{tabular}
\end{table}
\subsection{複雑な表(\texttt{array} 拡張・セル結合)}
\begin{table}[h]
\centering
\caption{プログラミング言語比較}
\label{tab:lang}
\begin{tabular}{|l|c|c|c|}
\hline
言語 & 型付け & パラダイム & 主な用途 \\
\hline\hline
Python & 動的 & マルチ & AI/データ分析 \\
Rust & 静的 & システム & システム開発 \\
Haskell & 静的 & 関数型 & 研究・金融 \\
JavaScript & 動的 & マルチ & Web フロント \\
\hline
\end{tabular}
\end{table}
表~\ref{tab:temp} と表~\ref{tab:lang} のように \verb|\label/\ref| で参照できる。
%% ================================================================
\section{リスト環境}
%% ================================================================
\subsection{箇条書き(itemize)}
\begin{itemize}
\item 第一の項目
\item 第二の項目
\begin{itemize}
\item 入れ子の項目 A
\item 入れ子の項目 B
\end{itemize}
\item 第三の項目
\end{itemize}
\subsection{番号付きリスト(enumerate)}
\begin{enumerate}[(1)] % enumerate パッケージで書式指定
\item 最初のステップ
\item 次のステップ
\item 最後のステップ
\end{enumerate}
\subsection{説明リスト(description)}
\begin{description}
\item[pLaTeX] 日本語対応の \LaTeX 処理系
\item[upLaTeX] Unicode 対応の pLaTeX 後継版
\item[LuaLaTeX] Lua スクリプトが使える \LaTeX 処理系
\end{description}
%% ================================================================
\section{verbatim・ソースコード}
%% ================================================================
\subsection{verbatim 環境}
\begin{verbatim}
#include <stdio.h>
int main(void) {
printf("Hello, pLaTeX!\n");
return 0;
}
\end{verbatim}
\subsection{listings によるシンタックスハイライト}
\begin{lstlisting}[language=Python, caption={フィボナッチ数列(Python)}]
def fibonacci(n: int) -> int:
"""再帰でフィボナッチ数を計算する"""
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
# 最初の 10 項を出力
for i in range(10):
print(f"F({i}) = {fibonacci(i)}")
\end{lstlisting}
%% ================================================================
\section{囲み・強調ボックス}
%% ================================================================
\texttt{ascmac} パッケージの \texttt{itembox}、\texttt{screen} 等を活用できる。
\begin{itembox}[l]{重要なポイント}
\begin{itemize}
\item pLaTeX は \texttt{jarticle} / \texttt{jbook} 文書クラスを使う
\item \texttt{okumacro} でルビ・圏点が使える
\item \texttt{platex + dvipdfmx} で PDF を生成する
\end{itemize}
\end{itembox}
\vspace{5pt}
\begin{screen}
\texttt{screen} 環境:端末表示風の囲み枠。ソース例や出力例の表示に使う。
\end{screen}
%% ================================================================
\section{段組み}
%% ================================================================
\texttt{multicol} パッケージで途中から 2 段組みに切り替えられる。
\begin{multicols}{2}
\noindent
これは 2 段組みの左カラムである。
日本語の段組みも pLaTeX は自然に処理する。
長い文章でも自動的に均等に振り分けられるため、
新聞・雑誌スタイルの組版に適している。
\columnbreak
\noindent
こちらが右カラムである。
\verb|\columnbreak| で強制的に段を切り替えることもできる。
数式 $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$
もインラインで使える。
\end{multicols}
%% ================================================================
\section{行間・スペーシング調整}
%% ================================================================
\subsection{水平スペース}
単語間の空白:a\,b(\verb|\,| 細空白)、
a\enspace b(\verb|\enspace|)、
a\quad b(\verb|\quad|)、
a\qquad b(\verb|\qquad|)。
\subsection{垂直スペース}
\verb|\vspace| で垂直スペースを追加できる。
\vspace{5mm}
上から 5mm の垂直スペースを挿入した後のテキスト。
\vspace{5mm}
\subsection{行間}
{\setstretch{1.8}
この段落は \texttt{setspace} パッケージの
\texttt{setstretch} で行間を 1.8 倍に広げている。
日本語文書では 1.5〜2.0 程度の行間が読みやすいとされる。
}
%% ================================================================
\section{カスタムコマンドと環境}
%% ================================================================
\subsection{カスタムコマンド定義}
\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\highlight}[1]{\colorbox{yellow!60}{#1}}
\newcommand{\term}[1]{\textbf{\textit{#1}}} % 用語強調
定義した例:$\R$(実数体)、$\N$(自然数)。
\highlight{ハイライトされたテキスト}。
\term{機械学習}(Machine Learning)は人工知能の一分野である。
\subsection{カスタム環境定義}
\newenvironment{mybox}[1]{%
\begin{center}\begin{tabular}{|p{0.85\linewidth}|}
\hline\vspace{1pt}
\textbf{#1}\\[2pt]
}{%
\\\hline\end{tabular}\end{center}
}
\begin{mybox}{自作の囲み枠}
\verb|\newenvironment| を使って独自の環境を定義できる。
引数も受け取れるので柔軟な再利用が可能。
\end{mybox}
%% ================================================================
\section{参考文献}
%% ================================================================
文献引用は \verb|\cite| コマンドで行う~\cite{knuth1984,lamport1994,okumura2020}。
文末に参考文献リストが出力される。
%% ================================================================
%% 参考文献リスト(thebibliography 環境)
%% ================================================================
\begin{thebibliography}{99}
\bibitem{knuth1984}
D.~E. Knuth,
\textit{The \TeX book},
Addison-Wesley, 1984.
\bibitem{lamport1994}
L.~Lamport,
\textit{\LaTeX: A Document Preparation System}, 2nd ed.,
Addison-Wesley, 1994.
\bibitem{okumura2020}
奥村晴彦・黒木裕介,
『\LaTeXe 美文書作成入門』第 8 版,
技術評論社, 2020.
\end{thebibliography}
\end{document}
コンパイル手順
基本(platex + dvipdfmx)
相互参照や目次を正しく解決するため、platex を 2 回実行してから dvipdfmx で PDF 化する。
platex -interaction=nonstopmode -kanji=utf8 document.tex
platex -interaction=nonstopmode -kanji=utf8 document.tex
dvipdfmx document.dvi
ptex2pdf
platex + dvipdfmx の 2 ステップを 1 コマンドにまとめた ptex2pdf を使う方法もある。
基本コマンド
ptex2pdf -l -ot "-kanji=utf8 -interaction=nonstopmode" document.tex
| オプション | 意味 |
|---|---|
-l | latex ベースのエンジン(platex)を使用 |
-ot "..." | platex に渡すオプション |
-kanji=utf8 | 入力エンコーディングを UTF-8 に指定 |
-interaction=nonstopmode | エラー時も停止せずに処理を続行 |
手順
-
ptex2pdf を 2 回実行する(相互参照・目次の解決のため)
ptex2pdf -l -ot "-kanji=utf8 -interaction=nonstopmode" document.tex
ptex2pdf -l -ot "-kanji=utf8 -interaction=nonstopmode" document.tex -
結果を確認する
- 成功:
document.pdfが生成される - エラー:
.logの!で始まる行とその前後 3 行を確認する - 警告のみ: Overfull/Underfull hbox、未定義参照などを確認する
- 成功:
-
BibTeX が必要な場合(
.bibファイルが存在する、または\bibliographyコマンドが含まれる場合)ptex2pdf -l -ot "-kanji=utf8 -interaction=nonstopmode" document.tex
bibtex document
ptex2pdf -l -ot "-kanji=utf8 -interaction=nonstopmode" document.tex
ptex2pdf -l -ot "-kanji=utf8 -interaction=nonstopmode" document.texbibtexの後にptex2pdfを 2 回実行するのは、参考文献リストと本文中の引用番号の相互参照を解決するためである。
よくあるエラーと対処
Undefined control sequence
! Undefined control sequence.
l.42 \somecommand
未定義のコマンドを使っている。パッケージの読み込み忘れか typo が原因である。
Missing $ inserted
! Missing $ inserted.
数式モード外で _(下付き)や ^(上付き)などの数式記号を使っている。$...$ で囲む。
File not found
! LaTeX Error: File `image.png' not found.
\includegraphics で指定したファイルのパスが誤っている。.tex ファイルからの相対パスを確認する。
Overfull \hbox
Overfull \hbox (12.3pt too wide) in paragraph at lines 55--60
エラーではなく警告である。行が指定幅に収まっていない。長い URL や英単語が原因のことが多く、\allowbreak や \url{} パッケージで対処できる。
ログの確認
コンパイル後に生成される .log ファイルにはエラーと警告の詳細が記録されている。エラーは ! で始まる行、警告は Warning を含む行である。
grep -n "^!" document.log # エラー行を抽出
grep -n "Warning" document.log # 警告行を抽出
中間ファイルの削除
コンパイルで生成される中間ファイルは多い。PDF を残してクリーンアップするには以下を実行する。
rm -f document.aux document.log document.dvi \
document.toc document.lof document.lot \
document.out document.bbl document.blg \
document.synctex.gz
すべて削除する場合は .pdf も加える。

読み込み中...