ConTeXt は Hans Hagen さんの作成した汎用的な TeX マクロパッケージです ; 人によってはこれは、LaTeX に取って代わるものでしょう。詳しくは http://www.pragma-ade.com/ を参照してください。
MetaPost は MetaFont に類似したシステムで、John Hobby さんにより作成されましたが、ポストスクリプトと pdf のファイルを出力できます。このパッケージは精巧なポストスクリプトのイラストを描くのに使えます。詳しいことについては http://cm.bell-labs.com/who/hobby/MetaPost.html を参照してください。MetaPost を使ったおもしろい作例はあちこちのサイトで見つけられます ; たとえば http://www.cs.ucc.ie/~dongen/mpost/mpost.html をご覧ください。TeXShop は MetaPost をサポートしています。
ここに MetaPost ファイルのサンプルがあります:
- prologues:=2;
- color yellow; yellow = green + red;
- def star (expr size, n, pos, color)=
- for a=0 step 360/n until 360:
- draw (origin -- (size/2,0))
- rotatedaround (origin, a)
- shifted pos withcolor color;
- endfor ;
- enddef;
- beginfig(1);
- pickup pencircle scaled 2mm; star (2cm,5,origin,red);
- endfig;
- beginfig(2);
- pickup pencircle scaled 2mm; star (2cm,7,origin,yellow);
- endfig;
- beginfig(3);
- pickup pencircle scaled 2mm; star (2cm,11,origin,green);
- endfig;
- beginfig(4);
- pickup pencircle scaled 2mm; star (2cm,13,origin,blue);
- endfig;
- end
このファイルの名前を「metademo.mp」とします。これを MetaPost で処理すると、metademo.1 ・ metademo.2 ・ metademo.3 ・ metademo.4 という4つの異なるポストスクリプト・ファイルが生成されます。ファイル名は「beginfig()」という番号パラメータで決定されています。この番号が beginfig(0) あるいは beginfig(10) というように負ではない整数(自然数)なら、結果として生じるファイルの名前は metademo.0 あるいは metademo.10 となります。もしこの番号が beginfig(-10) のように負の数だった場合には、生成されるファイルの名前は metademo.ps となり、それ以前にソースから作られていたすべての metademo.ps ファイルを上書きします。
このデフォルトの設定で、番号のひとつがゼロになっていると仮定します。TeXShop はスクリプト pstopdf を呼び出します──MetaPost が実行されたことで全番号分のポストスクリプト・ファイルが作られています。スクリプトは各ポストスクリプト・ファイルを、それぞれに pdf ファイルに変換します。最後に、ゼロ番目の pdf ファイルの名前を、ソースの名前に拡張子「pdf」を付けたもの(この例では metademo.pdf )に変え、この図をプレビュー画面に表示します。
MetaPost ファイルを編集しているときに、編集中の図の番号を正の数からゼロに変えてみてください。TeXShop はこの図をデバッグ中のものとして表示します。この図が満足のゆくものになったら、番号を正の数に戻し、他の図の番号を正の数からゼロに変えます。
いったん MetaPost ファイルが作られれば、他のイラストと同様に表示できます。イラストが pdf 形式に変換されていれば pdflatex で扱えますし、TeX+Ghostscript ならポストスクリプトのイラストを変換なしで扱えます。たとえば、上記の MetaPost ファイルから作られた4つのイラストは、次のようなファイルを TeX+Ghostscript でタイプセットすることで表示できます:
- \documentclass[11pt] {article}
- \usepackage{graphicx}
-
- \begin{document}
-
- Here are some illustrations.
- \vspace{.2in}
-
- \includegraphics[width=1cm]{metademo.1}
- \hfill
- \includegraphics[width=1cm]{metademo.2}
- \hfill
- \includegraphics[width=1cm]{metademo.3}
- \hfill
- \includegraphics[width=1cm]{metademo.4}
- \hfill
-
- \end{document}
mfpic パッケージを使うことで、MetaPost のソースコードを LaTeX 文書に直接埋め込むこともできます。この方法を用いる際には、環境設定ダイアログで、MetaPost の設定を「mptopdf」ではなく「mpost」にしておきます──このように MetaPost エンジンが選択されていると MetaPost が直接実行されます。MetaPost のソースコードを含む文書は、最初に pdflatex ないしは latex でタイプセットし、文書にあるすべてのイラストをひとまとめにした mp ソースファイルを作成します。そしてこのファイルを MetaPost でコンパイルします。最後に、文書を再度 pdflatex または latex でタイプセットしてイラストを表示します。
下にあるのは Claus Gerhardt による作例です。この例を「MetaPostTest」として保存します。ソース内の「\opengraphsfile{MetaPostTest}」と書かれた行に注目してください。mfpic パッケージはこのグラフィック・ファイルがどのような名前であってもかまわないとはいえ、TeXShop で次のような手順を踏むにあたっては、文書と同じ名前でなければなりません。いったん文書をタイプセットしたら、MetaPost に切り替えて再度タイプセットを行ない、もう一度 LaTeX に戻して最終的にタイプセットします。この過程において、1番目と3番目のステップでは、pdflatex または latex+ghostscript のいずれを用いてもかまいません。
- % This example is a shortened version of an example provided by
- % Claus Gerhardt.
- \documentclass[11pt]{article}
- \usepackage[metapost]{mfpic}
- \usepackage{amsmath}
- \opengraphsfile{MetaPostTest}
- \title{Brief Article}
- \author{The Author}
- \begin{document}
- \maketitle
- \begin{mfpic}[20]{-0.5}{11}{-0.5}{11}
- {\drawcolor{red}\function{0,10,0.05}{10-x}}
- {\drawcolor{blue}\function{0.99,10,0.05}{10/x}}
- {\drawcolor{green}\dashed\lines{(0.0,4),(10,4)}}
- \tlabelcolor{black}
- \drawcolor{black}\ymarks[4pt]{4}
- \headcolor{black}
- \drawcolor{2*black}\axes
- \tlabel{(4,6.5)}{$P_{\negthickspace c}$}
- \tlabel{(6,6.5)}{$P_{c}$}
- \tlabel(5,3.5){$A$}
- \tlabel{(-.6,3.9)}{$4$}
- \end{mfpic}
- \begin{center}
- \begin{mfpic}[15]{-2.2}{5}{-2.2}{2.2}
- \store{a}{\circle{(0,0),2}}
- \store{b}{\circle{(2 *sqrt 2,0),2}}
- \store{c}{\arc[p]{(0,0),-45,45,2}}
- \gfill[0.7white]\lclosed\mfobj{a}
- \gfill[white]\lclosed\mfobj{b}
- \draw\mfobj{a}\draw\mfobj{b}
- \tlabel(-1,-0.3){ $A$ }
- \tlabel(3,-0.3){ $B$ }
- \end{mfpic}
- \end{center}
- \closegraphsfile
- \end{document}
下の例もまた Claus Gerhardt さんの提供によるもので、MetaPost の威力を示しています。
- % This example was provided by Claus Gerhardt
- % Most of the figures and the text are taken from G.'s book
- % "Analysis I" published by International Press, Boston,
- % which will appear at the beginning of 2004.
- \documentclass[11pt]{amsart}
- \usepackage[metapost]{mfpic}
- \usepackage{amsmath}
- \usepackage{amsthm}
- \RequirePackage{amssymb}
- \RequirePackage[mathscr]{eucal}
- \opengraphsfile{MetaPostTest}
- \DeclareMathOperator*{\Au}{\forall}
- \DeclareMathOperator*{\Eu}{\exists}
- \newcommand{\msc}{\protect\mathscr}
- \newcommand\su{\subset}
- \newcommand{\pri}[1]{#1^\prime}
- \newcommand{\tit}[1]{\textit{\ignorespaces #1\ignorespaces}}
- \newcommand{\Cc}{{\protect\mathbb C}}
- \newcommand\ra{\rightarrow}
- \newcommand{\abs}[1]{\lvert#1\rvert}
- \newcommand{\fv}[2]{#1\hspace{0pt}_{|_{#2}}}
- \newcommand{\set}[2]{\{\,#1\colon #2\,\}}
- \newcommand\inn[1]{{\overset{\msp[9]\circ}{#1}}}
- \newcommand{\msp}[1][1]{\mspace{#1mu}}
- \newcommand{\Si}{\varSigma}
- \theoremstyle{remark}
- \newtheorem*{definition}{\bf Definition}
- \theoremstyle{theorem}
- \newtheorem*{theorem}{Theorem}
- \title{An Example of Using MetaPost with mfpic}
- %\author{The Author}
- \begin{document}
- \maketitle
- \thispagestyle{empty}
- \bigskip
- \begin{mfpic}[20]{-0.5}{11}{-0.5}{11}
- {\drawcolor{red}\function{0,10,0.05}{10-x}}
- {\drawcolor{blue}\function{0.99,10,0.05}{10/x}}
- {\drawcolor{green}\dashed\lines{(0.0,4),(10,4)}}
- \tlabelcolor{black}
- \drawcolor{black}\ymarks[4pt]{4}
- \headcolor{black}
- \drawcolor{2*black}\axes
- \tlabel{(4,6.5)}{$P_{\negthickspace c}$}
- \tlabel(5,3.5){$A$}
- \tlabel{(-.6,3.9)}{$4$}
- \end{mfpic}
- \bigskip
- \begin{definition}
- Let $E,\pri E$ be metric spaces and $f:E\rightarrow \pri E$ a map. $f$ is called \tit{continuous} at $x_0\in E$ if
- \begin{equation}\notag
- \Au_{\pri U\in \msc U(f(x_0))}\; \Eu_{U\in \msc U(x_0)}\quad f(U)\su \pri U.
- \end{equation}
- $f$ is called continuous in $E$ if $f$ is continuous at every point of $E$.
- \end{definition}
- \bigskip
- \begin{center}
- \begin{mfpic}[15]{-4.2}{16}{-4.2}{4.2}
- \store{R}{\rect{(-4,-4),(4,4)}}
- \store{U}{\cyclic[.75]{(-2,-2),(0,-1.5),(2,-2.4),(1.8,2),(0.5,1.8),(-2.3,1.7)}}
- \store{FU}{\shiftpath{(12,0)}\cyclic[.75]{(-1.5,-1.5),(0,-1.2),(2,-1.7),(1.8,2),(0,1.6),(-2,1)}}
- \store{UU}{\shiftpath{(12,0)}\cyclic[.75]{(-2.8,-3),(0,-2),(3,-2.4),(2.8,2.8),(0.5,2.4),(-2.9,1.7)}}
- \gfill[0.6white]\mfobj{U}
- \gfill[0.8white]\mfobj{UU}
- \gfill[0.6white]\mfobj{FU}
- \draw\mfobj{U}
- \draw\mfobj{UU}
- \draw\mfobj{R}
- \draw\mfobj{FU}
- \arrow\curve[1]{(3,2),(6,3),(9,2)}
- \point{(0,0),(12,0)}
- \shiftpath{(12,0)}\mfobj{R}
- \tlabel[tc](0,3.5){$E$}
- \tlabel[tc](12,3.5){$E'$}
- \tlabel[tl](-2,0){$U$}
- \tlabel[tl](10.1,1){$f(U)$}
- \tlabel[tl](9,-1){$U'$}
- \tlabel[tl](0.1,0){ $x_0$ }
- \tlabel[tl](12.1,0){ $f(x_0)$ }
- \tlabel[tc](6.1,3.8){$f$}
- \end{mfpic}
- \end{center}
- \noindent
- \parbox[c]{7.51cm}
- {The picture on the right shows the intersection of two
- sets $A$ and $B$. Notice that this intersection consists of
- all points which belong to both sets.}
- \hfill
- \begin{minipage}{40mm}
- \begin{mfpic}[15]{-2.2}{5}{-2.2}{2.2}
- \store{a}{\circle{(0,0),2}}
- \store{b}{\circle{(2 *sqrt 2,0),2}}
- \store{c}{\arc[p]{(0,0),-45,45,2}}
- \store{de}{ \arc[p]{(2 *sqrt 2,0),135,225,2}}
- \store{dd}{\lclosed\connect\mfobj{de}\mfobj{c}\endconnect}
- \gfill[0.7white]\mfobj{dd}
- \draw\mfobj{a}\draw\mfobj{b}
- \tlabel(-1,-0.3){ $A$ }
- \tlabel(3,-0.3){ $B$ }
- \end{mfpic}
- \end{minipage}
- \bigskip
- \begin{definition}[Complex logarithm\index{complex logarithm}]
- The \tit{complex logarithm}, $\log: \Cc^* \ra S_l$, is defined by
- \begin{equation}\notag
- \log z=\log\abs z+i\arg_lz.
- \end{equation}
- It is the inverse of $\fv\exp{S_l}$, the so-called \tit{ main branch}
- of the exponential function.
- \end{definition}
- The region of discontinuity
- is now the axis
- $\set{z\in\Cc^*}{\arg z=\pi}$. Thus, the exponential function
- is not only bijective in the
- open strip
- $\inn S_l$,
- but also a differentiable homeomorphism onto
- $\Si=\set{z\in\Cc^*}{\arg z\neq \pi}$ with
- $\pri\exp z=\exp z\neq 0$, and therefore, in view of the previous theorem, we may conclude
- \begin{theorem}
- The complex logarithm is infinitely often differentiable in $\Si$
- and
- $\pri\log z=\frac{1}{z}$.
- \end{theorem}
- \begin{mfpic}[15]{0}{20}{-2.5}{3}
- \gfill[0.6white]\rect{(12,-2),(20,2)}
- \gfill[0.6white]\circle{(4,0),2}
- \arrow[l 5pt]\lines{(4,0),(8,0)}
- \arrow[l 5pt]\lines{(4,-2.5),(4,3)}
- \arrow[l 5pt]\lines{(12,0),(20,0)}
- \gfill[white]\circle{(4,0),0.05}
- \arrow\curve[1]{(7,2.5),(10,3.5),(13,2.5)}
- \penwd{1pt}
- \draw[white]\lines{(0,0),(4,0)}
- \penwd{0.5pt}
- \arrow[l 5pt]\lines{(16,-2.5),(16,3)}
- \tlabel[cr](17.2,2.3){$\pi$}
- \tlabel[cr](17.2,-2.3){$-\pi$}
- \tlabel[cc](10,4){ log}
- \tlabel[cc](2,2.5){ $\Si$}
- \end{mfpic}%
- \closegraphsfile
- \end{document}