the history of tex and its recent advances

54
TeXの歴史と近年の動向 寺 田 侑 祐 (鉄緑会) 2014314日本数学会ワークショップ 数学ソフトウェアとフリードキュメント18

Upload: yusuke-terada

Post on 19-Jun-2015

28.025 views

Category:

Software


1 download

DESCRIPTION

Although TeX is a well-matured technology, various derived TeX engines and related packages have been developed and they are still advancing every day. I will give an outline of the history of TeX and the features of recent TeX-related technologies. I will focus especially on Japanese typesetting and graphics generation.

TRANSCRIPT

Page 1: The history of TeX and its recent advances

TeXの歴史と近年の動向寺 田 侑 祐 (鉄緑会)

2014年3月14日

日本数学会ワークショップ 数学ソフトウェアとフリードキュメント18

Page 2: The history of TeX and its recent advances

TeXの歴史

1978年:最初の公開版「TeX78」(SAIL言語)リリース

1982年:Pascalで再実装された「TeX82」β版リリース

1983年:TeX ver. 1.0 リリース

1990年:TeX ver. 3.1「終結宣言」

Donald E. Knuth (1938–)

Page 3: The history of TeX and its recent advances

終結宣言(1990年9月)もうこれ以上TeXは拡張しない。

もし著しい不具合があれば,ver. 3.14, 3.141, 3.1415, … とバージョン番号を進めていく。

自分の死と同時に ver. π とする。

それ以後は,どんな不具合があっても,誰もTeXに手をつけてはならない。

Page 4: The history of TeX and its recent advances

終結宣言以後の改版1990年 9月:ver. 3.1(終結宣言) 1991年 3月:ver. 3.14

1992年 3月:ver. 3.141

1993年 2月:ver. 3.1415

1995年 5月:ver. 3.14159

2002年12月:ver. 3.141592

2008年 2月:ver. 3.1415926

2014年 1月:ver. 3.14159265

πに漸近

Page 5: The history of TeX and its recent advances

終結宣言以後の改版1990年 9月:ver. 3.1(終結宣言) 1991年 3月:ver. 3.14

1992年 3月:ver. 3.141

1993年 2月:ver. 3.1415

1995年 5月:ver. 3.14159

2002年12月:ver. 3.141592

2008年 2月:ver. 3.1415926

2014年 1月:ver. 3.14159265

πに漸近24年間で7度のアップデート

十分に“枯れた”ソフトウェア

Page 6: The history of TeX and its recent advances

TeXにまつわる誤解

“TeXは作者の死後改変が禁止されるのでオープンソースではない”

Page 7: The history of TeX and its recent advances

% This program is copyright (C) 1982 by D. E. Knuth; all rights are reserved.!% Copying of this file is authorized only if (1) you are D. E. Knuth, or if!% (2) you make absolutely no changes to your copy. (The WEB system provides!% for alterations via an auxiliary file; the master file should stay intact.)!% See Appendix H of the WEB manual for hints on how to install this program.!% And see Appendix A of the TRIP manual for details about how to validate it.!

TeXはオープンソース?

tex.webより

パッチ(change file)の形で改変することは可能

Page 8: The history of TeX and its recent advances

I have put these systems (注: TeX, METAFONT, Computer Modern) into the public domain so that people everywhere can use the ideas freely if they wish.

TeXはオープンソース?

終結宣言(1990)より“TeX”という名前を使わなければ改変・配布自由

As stated on the copyright pages of Volumes B, D, and E, anybody can make use of my programs in whatever way they wish, as long as they do not use the names TeX, METAFONT, or Computer Modern. In particular, any person or group who wants to produce a program superior to mine is free to do so. However, nobody is allowed to call a system TeX or METAFONT unless that system conforms 100% to my own programs, as I have specified in the manuals for the TRIP and TRAP tests.

Page 9: The history of TeX and its recent advances

TeXはオープンソース?

オープンソースの定義に適合

ソースは公開。

TeX本体に手を入れられるのはKnuthのみ。

Knuthの死後は誰もTeX本体に手を入れてはならない。

改変部をパッチで配布するのは自由。

“TeX”という名前を使わなければ改変・配布自由。

Page 10: The history of TeX and its recent advances

実は……

今我々が使っているのは“TeX”ではない$ latex!This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)

$ platex!This is e-pTeX, Version 3.1415926-p3.4-110825-2.6 (utf8.euc) (TeX Live 2013)

我々が使っているのは“派生版TeX”“派生版TeX”は日進月歩で進化中!

Page 11: The history of TeX and its recent advances

派生版TeX       レジスタ数やプリミティブを拡張

      日本語対応版TeX (株式会社アスキー)

       pTeXにe-TeX拡張を施したもの(北川弘典氏)

      pTeXの内部処理コードをUnicodeに(田中琢爾氏)

      upTeXにe-TeX拡張を施したもの

      DVI形式を経由せず直接PDFを出力するエンジン

      システムにインストールされているフォントがそのまま使える

       TeXソース中でスクリプト言語Luaが直接使える

Page 12: The history of TeX and its recent advances

e-TeX

各レジスタ数の制限を256個から32768個まで緩和

演算用プリミティブ \numexpr,\dimexpr,\glueexpr,\muexpr

\ifdim\dimexpr(2pt-5pt)*\numexpr3-3*13/5\relax + 34pt/2<\wd20

条件判定の反転 \unless

TeXのトークン列を文字列化 \detokenize

\left, \right の間で使う \middle

Page 13: The history of TeX and its recent advances

\middle\[A=\left\{(x,\,y)\in\mathbb{R}^2\middle|0<x<\frac{1}{2}\right\}\]

Page 14: The history of TeX and its recent advances

\middle\[\left\langle\psi\middle|\frac{d}{dx}\middle|\phi\right\rangle\]

Page 15: The history of TeX and its recent advances

派生版TeX       レジスタ数やプリミティブを拡張

      日本語対応版TeX (株式会社アスキー)

       pTeXにe-TeX拡張を施したもの(北川弘典氏)

      pTeXの内部処理コードをUnicodeに(田中琢爾氏)

      upTeXにe-TeX拡張を施したもの

      DVI形式を経由せず直接PDFを出力するエンジン

      システムにインストールされているフォントがそのまま使える

       TeXソース中でスクリプト言語Luaが直接使える

Page 16: The history of TeX and its recent advances

pTeXの弱点pTeXはUTF8で入力しても,内部的にEUCに変換して処理している

$ ptex!This is e-pTeX, Version 3.1415926-p3.4-110825-2.6 (utf8.euc) (TeX Live 2013)

それゆえJIS第1, 2水準以外の文字が扱えない

髙島屋 山﨑 𠮷野家 森鷗外 内田百閒㉑❸㊃㈤⓺⒎㋐ⒶⓑCD⒠FG

中国語・韓国語など他言語との混植が容易でない

Page 17: The history of TeX and its recent advances

upTeX

2007年から田中琢爾氏が開発開始

pTeXの内部コードを全てUnicodeのままで処理

Unicode追加面も含め,JIS第3, 4水準の全ての文字が扱えるように

中国語・韓国語との混植も容易に

現在 TeX Live には標準搭載されている

Page 18: The history of TeX and its recent advances

upTeXでのコンパイルドキュメントクラス宣言:

  \documentclass[uplatex]{jsarticle}   (または ujarticle, utarticle などを使う)!

コンパイルコマンド:

   platex ! uplatex

※TeX Live の場合は ptex2pdf -l -u でPDF化するのが楽

Page 19: The history of TeX and its recent advances

upTeXでのコンパイル\documentclass[uplatex]{jsarticle}!\usepackage[X2,OT2,LGR,T1]{fontenc}!\usepackage[russian,greek,english]{babel}!\usepackage{pxbabel}!\usepackage[utf8]{inputenc}!\usepackage[prefercjkvar]{pxcjkcat}!\kcatcode`ö=15!\begin{document}!髙島屋 山﨑 𠮷野家 森鷗外 内田百閒\par!㉑50ⅡⅢⅣⅷ⒏❸㊃㈤⓺㋐Ⓐⓑ\par!Schrödinger Fréchet l'Hôpital François\par!\foreignlanguage{schinese}{已经十一月了,北京的天气应该很冷了。}\par!\foreignlanguage{korean}{늦잠을 자서 하마터면 비행기를 놓칠 뻔했어요.}\par!{\selectlanguage{russian}Оно было в начале у Бога.}\par!{\selectlanguage{greek}Ὁ βίος βραχὺς, ἡ δὲ τέχνη μακρὴ.}!\end{document}

Page 20: The history of TeX and its recent advances

upTeXでのコンパイル

Page 21: The history of TeX and its recent advances

派生版TeX       レジスタ数やプリミティブを拡張

      日本語対応版TeX (株式会社アスキー)

       pTeXにe-TeX拡張を施したもの(北川弘典氏)

      pTeXの内部処理コードをUnicodeに(田中琢爾氏)

      upTeXにe-TeX拡張を施したもの

      DVI形式を経由せず直接PDFを出力するエンジン

      システムにインストールされているフォントがそのまま使える

       TeXソース中でスクリプト言語Luaが直接使える

Page 22: The history of TeX and its recent advances

pdfTeX

DVIを経由せず,TeXソースから直接PDFを出力

欧米で現在主流

\pdfsavepos(現在の組版位置の絶対座標取得)など追加機能多数

日本語組版が十分な品質で扱えないため,日本ではあまり普及していない

Page 23: The history of TeX and its recent advances

2004年から開発開始

伝統的なtfmを使用せず,OSにインストールされたフォントを直接利用できる(従来のtfmも利用可)

Unicode全面サポート

異体字・合字などOpenTypeの先進機能を利用できる

IVS(異体字選択符号)に対応した唯一のTeXエンジン

アラビア語やヘブライ語のような,右から左に書く言語にも対応

Page 24: The history of TeX and its recent advances

IVS(Ideographic Variation Sequence)

Page 25: The history of TeX and its recent advances

XeLaTeX + bxjsarticle + zxjatype(八登崇之氏)によって和文組版可能に

pLaTeX + jsarticle + ヒラギノ明朝

XeLaTeX + bxjsarticle + zxjatype + ヒラギノ明朝

    で日本語

Page 26: The history of TeX and its recent advances

LuaTeX2007年から開発開始

pdfTeXと同様,TeXソースからDVIを経由せずPDFを直接出力

pdfTeXの後継となることが決まっている

スクリプト言語LuaのコードをTeXソース中に直接記述し実行できる

バイナリファイル解析やネットワークアクセスなど,Luaの外部ライブラリも呼び出し可能

行分割処理・出力処理など,あらゆる処理をLuaスクリプトでカスタマイズ可能

Page 27: The history of TeX and its recent advances

LuaTeX\def\Heron#1#2#3{\directlua{! function Heron(a, b, c)! local area, s! if a+b>c and b+c>a and c+a>b then! s = (a+b+c)/2! area = math.sqrt(s*(s-a)*(s-b)*(s-c))! else! area = -1 ! end! return area! end! result = Heron(#1, #2, #3)! if result > 0 then! tex.print("area = ".. result)! else! tex.print("data error")! end!}}!

\Heron{3}{4}{5}! %=> area = 6!!\Heron{3}{4}{6}! %=> area = 5.3326822519254!!\Heron{1}{2}{3}! %=> data error!

Page 28: The history of TeX and its recent advances

LuaTeX-jaLuaTeX上で日本語組版を可能にしようというプロジェクト。 2011年に北川弘典氏らによって始動された。 単位 zw は \zw と書かねばならないなど,pTeXの完全上位互換ではない。 pTeXの動作で不合理な点は積極的に改善してゆく姿勢。 グルーに優先度の概念を導入することで,JISの日本語組版規則(JIS X 4051)

へより高い水準で準拠させることが可能。 和文フォントメトリックもLuaコードで書かれているので,約物間のアキなども容易にカスタマイズできる。 コンパイル速度は遅いものの,横組みについては既に実用レベルに。

Page 29: The history of TeX and its recent advances

LuaTeX-jaはノードベース

ほげ,「ほげ」(ほげ)。!ほげ,\textgt{「ほげ」}(ほげ)。!ほげ,\textgt{\inhibitglue 「ほげ」\inhibitglue}(ほげ)。

pTeXの欠点

Page 30: The history of TeX and its recent advances

LuaTeX-jaはノードベース

ほげ,「ほげ」(ほげ)。!ほげ,\textgt{「ほげ」}(ほげ)。!ほげ,\textgt{\inhibitglue 「ほげ」\inhibitglue}(ほげ)。

LuaTeX-jaの場合

Page 31: The history of TeX and its recent advances

優先度付きグルーによる行長調整

カギ括弧の前後を優先的に詰めて行長調整

Page 32: The history of TeX and its recent advances

派生版TeX       レジスタ数やプリミティブを拡張

      日本語対応版TeX (株式会社アスキー)

       pTeXにe-TeX拡張を施したもの(北川弘典氏)

      pTeXの内部処理コードをUnicodeに(田中琢爾氏)

      upTeXにe-TeX拡張を施したもの

      DVI形式を経由せず直接PDFを出力するエンジン

      システムにインストールされているフォントがそのまま使える

       TeXソース中でスクリプト言語Luaが直接使える

Page 33: The history of TeX and its recent advances

派生版TeXの継承関係

Page 34: The history of TeX and its recent advances

派生版TeXの継承関係

現在日本 で主流

先進的 エンジン

欧米で主流

Page 35: The history of TeX and its recent advances

起動コマンド名とTeXエンジンtex Knuth’s TeX

latex e-TeX + LaTeXetex e-TeX

ptex pTeXplatex e-pTeX + LaTeX

eptex e-pTeX

uptex upTeXuplatex e-upTeX + LaTeX

euptex e-upTeX

pdftex pdfTeX pdflatex pdfTeX + LaTeX

xetex XeTeX xelatex XeTeX + LaTeX

luatex LuaTeX lualatex LuaTeX + LaTeX

Page 36: The history of TeX and its recent advances

起動コマンド名とTeXエンジンtex Knuth’s TeX

latex e-TeX + LaTeXetex e-TeX

ptex pTeXplatex e-pTeX + LaTeX

eptex e-pTeX

uptex upTeXuplatex e-upTeX + LaTeX

euptex e-upTeX

pdftex pdfTeX pdflatex pdfTeX + LaTeX

xetex XeTeX xelatex XeTeX + LaTeX

luatex LuaTeX lualatex LuaTeX + LaTeX

e-TeX拡張が有効

Page 37: The history of TeX and its recent advances

TeXの進歩KnuthオリジナルのTeXは1990年の終結宣言以来,7度しかアップデートされていない。

しかし派生版TeXは日進月歩に進化を続けている。

我々が日常的に用いているのはe-TeX拡張が有効になった派生版。

パッケージや周辺ツールも含めると,毎日のようにアップデートがある。

TeX Live なら環境を随時最新版にアップデートできる。

一昔前の“TeXの常識”が,今では時代遅れになっていることも。

Page 38: The history of TeX and its recent advances

dvipdfm か dvipdfmx かかつては……

“dvipdfmxを使う場合も\usepackage[dvipdfm]{graphicx}

と書きましょう”

現在では……

\usepackage[dvipdfmx]{graphicx}([dvipdfm] のままでは色々とトラブルの原因になります)

Page 39: The history of TeX and its recent advances

PDFプレビュー従来は TeX→DVI とした後,dviout や xdvi でプレビューするのが一般的だった。 しかしDVIのままでは図やフォントを正しくプレビューできる保証がない。 現在ではPDFの描画が高速化した。

現在ではPDFプレビューが一般的・推奨

Page 40: The history of TeX and its recent advances

PDFプレビューDVI → PDF は,dvipdfmx を用いてフォント埋め込みするのが推奨。

TeX Live 付属の ptex2pdf スクリプトを用いれば,TeX → DVI → PDF

が自動化される。

Adobe Reader / Adobe Acrobat は開いているPDFをロックしたり,開いているPDFの更新を反映しないなど,作業中のプレビュー環境としては不適当。

SumatraPDF (Windows) / Preview.app (Mac) などは自動更新対応。

TeXworks (Win,Mac,Linux) / TeXShop (Mac) などの統合環境もPDFプレビュー対応。

Page 41: The history of TeX and its recent advances

LaTeXと図版かつては……

“LaTeXに挿入する図版はEPS形式で作成”

現在では……

“図版はPDF形式で作成”

Page 42: The history of TeX and its recent advances

PDFで図版作成する理由pdfTeXやdvipdfmxによって最終出力をPDFで得るのであれば,初めからPDFで図版作成しておく方が直接的。

EPS形式で図版作成すると,PDF化のたびに毎回 ghostscript が起動してPDFへの変換を行うため,コンパイル時間が圧倒的に延びてしまう。

コンパイル時に必要に応じて extractbb が自動起動しxbbファイルを作成するので,図版のサイズも自動的に取得できる。

Illustratorなどで作成する図版はPDF形式で!+ PDFプレビュー

Page 43: The history of TeX and its recent advances

LaTeX上での図版作成⑴picture環境:LaTeX2e標準。簡単な図が描けるが制約が強い。

円板の直径は15pt以下

直線の傾きは n/m (m, nは絶対値が6以下の整数)のみ

楕円は実際には四分円と直線をつないだだけの角丸長方形

epic.sty:picture環境の制約下で任意の二点を結ぶ直線などを近似的に実現。

eepic.sty / pict2e.sty:DVIware(dvipdfmx/dvipsなど)の機能を用いてpicture環境の制約を取り払い,任意の直線や楕円を描けるように。

Page 44: The history of TeX and its recent advances

LaTeX上での図版作成⑵PSTricks:DVIファイルにPostScriptの命令を埋め込むことで描画

長所:PostScriptの高度な機能をフルに使えるため極めて高度な描画ができる。アニメーション生成すら可能。短所:DVIwareを厳しく選ぶ。PostScriptを解釈せねばならないので,dvipdfmxは不可。dvips + Adobe Distiller でPDF化するのが標準的(pdfTeXやXeTeXも可)。

Page 45: The history of TeX and its recent advances

PSTricks%% pstricks.sty / pst-3dplot.sty をロードしておく!\begin{pspicture}(-5,-5)(5,5)! \psset{Beta=20,Alpha=50,linewidth=0.1pt,linecolor=blue}! \parametricplotThreeD[xPlotpoints=500,yPlotpoints=100](80,360)(0,360){%!! /k 2 def /k2 4 def!! t cos k mul 3 u sin k mul add mul!! t sin k mul 3 u sin k mul add mul!! u cos k2 mul}! \parametricplotThreeD[yPlotpoints=200](0,360)(80,360){%!! /k 2 def /k2 4 def!! u cos k mul 3 t sin k mul add mul!! u sin k mul 3 t sin k mul add mul!! t cos k2 mul}! \parametricplotThreeD[xPlotpoints=100,yPlotpoints=2,! linecolor=red,linewidth=2pt](0,360)(80,360){%!! /k 2 def /k2 4 def!! u cos k mul 3 t sin k mul add mul!! u sin k mul 3 t sin k mul add mul!! t cos k2 mul}!\end{pspicture}

Page 46: The history of TeX and its recent advances

PSTricks

Page 47: The history of TeX and its recent advances

LaTeX上での図版作成⑶

!

picture環境 + pict2e の場合と同様に,DVIファイルにDVIwareに対する描画命令を書き込む

PSTricksと異なりPostScriptの命令は使わない

dvipdfmx / dvips / pdfTeX / XeTeX / LuaTeX の全てをサポート

PGFが描画エンジン,TikZはそのフロントエンド

自然な文法で高度な図版が描画可能

PGF / TikZ

Page 48: The history of TeX and its recent advances

PGF / TikZ

Page 49: The history of TeX and its recent advances

PGF / TikZ\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,! thick,main node/.style={circle,fill=blue!20,draw,font=\sffamily\Large\bfseries}]! \node[main node] (1) {1};! \node[main node] (2) [below left of=1] {2};! \node[main node] (3) [below right of=2] {3};! \node[main node] (4) [below right of=1] {4};! \path[every node/.style={font=\sffamily\small}]! (1) edge node [left] {0.6} (4)! edge [bend right] node[left] {0.3} (2)! edge [loop above] node {0.1} (1)! (2) edge node [right] {0.4} (1)! edge node {0.3} (4)! edge [loop left] node {0.4} (2)! edge [bend right] node[left] {0.1} (3)! (3) edge node [right] {0.8} (2)! edge [bend right] node[right] {0.2} (4)! (4) edge node [left] {0.2} (3)! edge [loop right] node {0.6} (4)! edge [bend right] node[right] {0.2} (1);!\end{tikzpicture} 完成図

Page 50: The history of TeX and its recent advances

TikZで3Dグラフ\documentclass{article}!\usepackage{tikz}!\usepackage{tikz-3dplot}!\begin{document}!\tdplotsetmaincoords{70}{135}!!\begin{tikzpicture}[line join=bevel,tdplot_main_coords,fill opacity=.7]! \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%! {5*sin(\tdplottheta)*cos(\tdplottheta)}{black}{\tdplotphi}{}{}{}%!\end{tikzpicture}!!\end{document}

Page 51: The history of TeX and its recent advances

TikZで3Dグラフ

Page 52: The history of TeX and its recent advances

TikZでこんな図も

Page 53: The history of TeX and its recent advances

参考文献1) 八登崇之『日本人の知らないTeX — TeX の過去・現在・未来』,TeXユーザの集い2010 発表資料, http://zrbabbler.sp.land.to/texconf10.html.!

2) 八登崇之. En toi Pythmeni tes TeXnopoleos[電脳世界の奥底にて].!a. BXjsarticle, http://zrbabbler.sp.land.to/bxjscls.html.!b. ZXjatype, http://zrbabbler.sp.land.to/zxjatype.html.!c. BXpict2e, http://zrbabbler.sp.land.to/bxpict2e.html.!

3) 八登崇之. マクロツイーター.!a. “zxjatype が(実は)アレな話”. http://d.hatena.ne.jp/

zrbabbler/20131204/1386178094.!b. “ギリシャ語ネタのための LaTeX”. http://d.hatena.ne.jp/

zrbabbler/20140118/1390070325.!

4) 八登崇之. “日本人のための LaTeX タブー集 ~画像読込編~”. Qiita, http://qiita.com/zr_tex8r/items/5413a29d5276acac3771.

Page 54: The history of TeX and its recent advances

参考文献5) 吉村 優. “TeX処理系御伽話”. http://qiita.com/_yyu_/items/

6404656f822ce14db935.!

6) LuaTeX-jaパッケージドキュメント. http://sourceforge.jp/projects/

luatex-ja/wiki/Documentation.!

7) upTeXドキュメント. http://homepage3.nifty.com/ttk/comp/tex/

uptex.html.!

8) “PSTricks examples”. TUG, http://tug.org/PSTricks/.!

9) “TikZ and PGF examples”. TeXample.net, http://www.texample.net/

tikz/examples/.!

10)“How to make dominoes falling?”. TeX — LaTeX Stack Exchange,

http://tex.stackexchange.com/questions/149828/how-to-make-

dominoes-falling.