💭
校異源氏物語テキストDBのTEI/XMLからPDFを作成する
概要
校異源氏物語テキストDBは、『校異源氏物語』のテキストデータを公開するデータベースです。
今回、本DBに以下のようなPDFファイルを追加しました。
https://kouigenjimonogatari.github.io/output/01/main.pdf
本記事は、上記のようなPDFファイルを、XSLTとTeXを使って作成します。
リポジトリのクローン
以下のように、リポジトリをクローンします。
git clone --depth 1 https://github.com/kouigenjimonogatari/kouigenjimonogatari.github.io
そして以下のコマンドにより、xslt3をインストールします。
npm i xslt3
XSLファイルの作成
今回は、まずTEI/XMLファイルをTeXファイルに変換します。
以下のようなXSLファイルを作成しました。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/">
\documentclass[a4paper,11pt,landscape]{ltjtarticle}
\usepackage{xcolor}
\usepackage{luatexja-fontspec} % fontspec を LuaTeX-ja と共に利用
\usepackage[top=2cm,bottom=2cm,left=2cm,right=2cm,textwidth=25cm]{geometry}
% スタイル定義
\newcommand{\person}[1]{\textbf{\color{blue}#1}}
\newcommand{\place}[1]{\textit{\color{green}#1}}
% 日本語フォント設定
\setmainjfont{Noto Serif CJK JP} % 日本語フォントを指定
\title{<xsl:value-of select="//tei:title"/>}
\date{}
\begin{document}
\maketitle
% 本文
<xsl:for-each select="//tei:seg">
<xsl:apply-templates/>
\par\medskip
</xsl:for-each>
\end{document}
</xsl:template>
<!-- 人名の処理 -->
<xsl:template match="tei:persName">
\person{<xsl:value-of select="."/>}</xsl:template>
<!-- 地名の処理 -->
<xsl:template match="tei:placeName">
\place{<xsl:value-of select="."/>}</xsl:template>
</xsl:stylesheet>
先にインストールしたxslt3
を使って、以下のようにTEI/XMLファイルをTeXファイルに変換できます。
npx xslt3 -xsl:xsl/tex.xsl -s:xml/xsl/01.xml -o:output/01/main.tex
変換したTeXファイルの例(一部)は以下です。
\documentclass[a4paper,11pt,landscape]{ltjtarticle}
\usepackage{xcolor}
\usepackage{luatexja-fontspec} % fontspec を LuaTeX-ja と共に利用
\usepackage[top=2cm,bottom=2cm,left=2cm,right=2cm,textwidth=25cm]{geometry}
% スタイル定義
\newcommand{\person}[1]{\textbf{\color{blue}#1}}
\newcommand{\place}[1]{\textit{\color{green}#1}}
% 日本語フォント設定
\setmainjfont{Noto Serif CJK JP} % 日本語フォントを指定
\title{校異源氏物語・きりつぼ}
\date{}
\begin{document}
\maketitle
% 本文
いつれの御時にか女御更衣あまたさふらひ給けるなかにいとやむことなきゝは
\par\medskip
にはあらぬかすくれて時めき給ありけりはしめより我はと思あかり給へる御方
\par\medskip
...
PDFファイルの作成
以下のコマンドにより、TeXファイルをPDFファイルに変換しました。
lualatex -output-directory=output/01 main.tex
また、Noto Serif CJK JP
フォントの利用に当たり、macOS環境において、以下を行う必要がありました。
brew install --cask font-noto-serif-cjk
まとめ
以下の記事では、今回の記事で対象とした同じTEI/XMLファイルから、IIIF画像との対照表示が可能なHTMLファイルを作成しました。
このように、XSLTにより、用途に応じた出力を行うことができる点がTEI/XMLでテキストを作成する利点の一つかと思います。
TeXについて理解が乏しい点が多々ありますが、TEI/XMLの利用にあたり、参考になりましたら幸いです。
Discussion