
% We use mfpic to make figures showing patch relationships
\usepackage[metapost,mplabels,truebbox]{mfpic}
\setlength\pointsize{5pt}

\newcommand{\mkpointname}[1]{%
% We put a string before the point name, so we don't have problems with
% point names like 'or'
igPoint#1%
}
\newcommand{\mkpointnamecmd}[1]{%
\csname \mkpointname{#1}\endcsname
}

\def\pointcolour{blue}

\newcommand{\existential}[1]{%
    \tlabelcolor{red}%
    \drawcolor{red}%
    \headcolor{red}%
    \def\pointcolour{red}%
    #1%
    \tlabelcolor{black}%
    \drawcolor{black}%
    \headcolor{black}%
    \def\pointcolour{blue}%
}

\newcommand{\definepoint}[2]{%
\pointdef{\mkpointname{#1}}#2%
}

\newcommand{\drawpoint}[2]{%
\definepoint{#1}{#2}%
\point{\mkpointnamecmd{#1}}%
}

\newcommand{\drawlabpoint}[3]{%
\drawpoint{#1}{#2}%
\tlabelsep{5pt}%
\tlabelcolor{\pointcolour}%
\tlabel[#3]{\mkpointnamecmd{#1}}{#1}%
\tlabelcolor{black}%
\tlabelsep{1pt}%
}

% Grids aren't used in the final thing, but are handy when placing
% things in igpics.
\newcommand{\iggrid}[4]{%
\newcounter{ctX}%
\newcounter{ctY}%
\drawcolor{white}%
% XXX Should probably be using a line command rather than a curve % command?
\forloop{ctX}{#1}{\value{ctX} < #2}{%
\curve{(\arabic{ctX},#3),(\arabic{ctX},#4)}%
}%
\forloop{ctY}{#3}{\value{ctY} < #4}{%
\curve{(#1,\arabic{ctY}),(#2,\arabic{ctY})}%
}%
\drawcolor{black}%
}
% XXX lin(e) should probably use a straightline command rather than curve
\newcommand{\lin}[2]{%
    \trimpath{\pointsize,\pointsize}%
    \curve{\mkpointnamecmd{#1},\mkpointnamecmd{#2}}%
}
\newcommand{\arr}[3]{%
    \arrow%
    \trimpath{\pointsize,\pointsize}%
    \curve{\mkpointnamecmd{#1},\mkpointnamecmd{#2},\mkpointnamecmd{#3}}%
}
\newcommand{\arrlab}[5]{%
    \arr{#1}{#2}{#3}%
    \tlabel[#4]{\mkpointnamecmd{#2}}{#5}%
}
\newcommand{\earrlab}[5]{\existential{\arrlab{#1}{#2}{#3}{#4}{#5}}}
% Is there a global setting we can set for the default tlabelsep instead?
\everymfpic{\tlabelsep{1pt}}
\mfpverbtex{%&latex
\documentclass[a4paper]{article}
\usepackage{import}
\import{}{preamble}
\begin{document}
\import{}{definitions}
}
\opengraphsfile{figures}
% Each unit in mfpic pitures corresponds to 18pt
\mfpicunit=18pt
% Default is 1(ratio) 1(tension) false(don't fill the arrowhead)
\headshape{1}{100}{true}
% Default is 3pt, but that makes weedy-looking arrows
\headlen=5pt
