%%
%% This is file `mpinlsmp.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% mpostinl.dtx  (with options: `sample')
%% 
%% Copyright (C) 2010-2018 Niklas Beisert
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\ProvidesFile{mpinlsmp.tex}[2018/12/30 v1.5 sample for mpostinl]
\documentclass[12pt,a4paper]{article}

\parindent0pt
\parskip6pt

\usepackage[fonts=true]{mpostinl}

\usepackage[utf8]{inputenc}

%% optional: add filename to position labels in metapost code
\IfFileExists{currfile.sty}{\usepackage{currfile}}{}
%% optional: tools to align graphics
\makeatletter\define@key{Gin}{align}[]{}\makeatother
\IfFileExists{graphbox.sty}{\usepackage{graphbox}}{}

%% some sample package options:
%% \mpostsetup{write=false}
%% \mpostsetup{compile=false}
\mpostsetup{checksum}
\mpostsetup{now}
%% \mpostsetup{nowall}
\mpostsetup{lineno}
%% \mpostsetup{latex=false}
%% \mpostsetup{classopt={12pt}}

%% declare packages to be used for processing labels:
\begin{mposttex}[global]
\usepackage[utf8]{inputenc}
\end{mposttex}

%% specify global definitions:
\begin{mpostdef}[global]
newinternal unit;
unit:=1cm;
\end{mpostdef}

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Basic Functionality}

a plain circle:\\
\begin{mpostfig}
draw fullcircle scaled unit;
label(btex 1 etex, (0,0));
\end{mpostfig}

scaled (and aligned to centre if available):\\
X
\begin{mpostfig}[opt={scale=1.5,align}]
draw fullcircle scaled unit;
label(btex 2 etex, (0,0));
\end{mpostfig}
X

declare figure with label (no display).
\begin{mpostfig}[label={fig}]
draw fullcircle scaled unit;
label(btex 3 etex, (0,0));
\end{mpostfig}

display:\\
\mpostuse{fig}

display with options:\\
\mpostuse[scale=1.5,align]{fig}

display in a box:\\
\fbox{\mpostuse{fig}}

centred display:
\begin{center}
\mpostuse[scale=1.5]{fig}
\end{center}

display in equation (align if possible):
\begin{equation}
\mpostuse[scale=1.5,align]{fig}
\end{equation}

filename: \mpostgetname{fig}
\texttt{\mpostfigurename}

figure with filename:\\
\begin{mpostfig}[file={\jobname-name.mps},label={name},show]
draw fullcircle scaled unit;
label(btex 4 etex, (0,0));
\end{mpostfig}
\\
filename: \mpostgetname{name}
\texttt{\mpostfigurename}

display by \verb+\includegraphics+ (if file exists):\\
\IfFileExists{\jobname-name.mps}{\includegraphics{\jobname-name.mps}}{}

label does not exist:\\
\mpostuse{not_exist}

utf-8 test:\\
\begin{mpostfig}
interim unit:=1.5cm;
draw fullcircle scaled unit;
label(btex àáâãäåæ etex, (0,0));
\end{mpostfig}

empty figure:\\
\begin{mpostfig}
\end{mpostfig}

empty figure:\\
\begin{mpostfig}

\end{mpostfig}

\begin{mposttex}[dual]
\def\mymacro{hello!}
\end{mposttex}
dual definition `\mymacro':\\
\begin{mpostfig}
draw unitsquare shifted (-0.5,-0.5) xscaled 3 scaled unit;
label(btex \mymacro etex, (0,0));
\end{mpostfig}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Immediate Processing}

immediate processing per figure:\\
\begin{mpostfig}[now]
interim unit:=1.5cm;
draw fullcircle scaled unit;
label(btex 5 etex, (0,0));
\end{mpostfig}

turn on immediate processing for all figures and keep sources.
\mpostsetup{nowall,nowkeep}

generate file \texttt{\jobname-now.mps}:
\begin{mpostfig}[file={\jobname-now.mps}]
draw fullcircle scaled unit;
label(btex 6 etex, (0,0));
\end{mpostfig}
\\
display by \verb+\includegraphics+:\\
\includegraphics{\jobname-now.mps}
\\
source \texttt{\jobname-now.mp}
\IfFileExists{\jobname-now.mp}{exists}{does not exist}.

turn off immediate processing and discard sources.
\mpostsetup{nowall=false,nowkeep=false}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Filename Composition}

by label:\\
\mpostsetup{labelnames=true}
\begin{mpostfig}[label={circle},show]
draw fullcircle scaled unit;
label(btex 7 etex, (0,0));
\end{mpostfig}
\mpostsetup{labelnames=false}
\\
filename: \mpostgetname{circle}
\texttt{\mpostfigurename}

change extension:
\mpostsetup{extension=eps}
\begin{mpostfig}[label={ext}]
draw fullcircle scaled unit;
label(btex 8 etex, (0,0));
\end{mpostfig}
\mpostsetup{extension=mps}
\\
filename: \mpostgetname{ext}
\texttt{\mpostfigurename}

change template:\\
\mpostsetup{template=\mpostfilename-figure-#1.mps}
\begin{mpostfig}[label={template},show]
draw fullcircle scaled unit;
label(btex 9 etex, (0,0));
\end{mpostfig}
\mpostsetup{template=\mpostfilename-#1.mps}
\\
filename: \mpostgetname{template}
\texttt{\mpostfigurename}

\mpostsetup{numberwithin=subsection}

\subsection{Section 1}

\begin{mpostfig}[show,label={sec1}]
draw fullcircle scaled unit;
label(btex 10 etex, (0,0));
\end{mpostfig}
\\
filename: \mpostgetname{sec1}
\texttt{\mpostfigurename}

\subsection{Section 2}

\begin{mpostfig}[show,label={sec2}]
draw fullcircle scaled unit;
label(btex 11 etex, (0,0));
\end{mpostfig}
\\
filename: \mpostgetname{sec2}
\texttt{\mpostfigurename}

\begin{mpostfig}[show,label={sec3}]
draw fullcircle scaled unit;
label(btex 12 etex, (0,0));
\end{mpostfig}
\\
filename: \mpostgetname{sec3}
\texttt{\mpostfigurename}

\subsection{Section 3}

\begin{mpostfig}[show,label={sec4}]
draw fullcircle scaled unit;
label(btex 13 etex, (0,0));
\end{mpostfig}
\\
filename: \mpostgetname{sec4}
\texttt{\mpostfigurename}

\makeatletter
\def\thempi@count{\arabic{mpi@count}}
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Multiple Files}

\mpostdone

\mpostsetup{globaldef=true}

\begin{mpostdef}
unit:=0.8cm;
\end{mpostdef}

\mpostsetup{globaldef=false}

\mpostfile[include]{\jobname-inc}

\begin{mpostdef}
def drawcircle =
draw fullcircle scaled unit
enddef;
\end{mpostdef}

\mpostdone

\subsection*{Section 1}
\mpostfile{\jobname-sec1}

\begin{mpostfig}[show,label={sec5}]
drawcircle;
label(btex 14 etex, (0,0));
\end{mpostfig}
\\
filename: \mpostgetname{sec5}
\texttt{\mpostfigurename}

\mpostdone

\subsection*{Section 2}
\mpostfile{\jobname-sec2}

\begin{mpostfig}[show,label={sec6}]
drawcircle;
label(btex 15 etex, (0,0));
\end{mpostfig}
\\
filename: \mpostgetname{sec6}
\texttt{\mpostfigurename}

\begin{mpostdef}
unit:=1.5cm;
\end{mpostdef}

\begin{mpostfig}[show,label={sec7}]
drawcircle;
label(btex 16 etex, (0,0));
\end{mpostfig}
\\
filename: \mpostgetname{sec7}
\texttt{\mpostfigurename}

\mpostdone

\subsection*{Section 3}
\mpostfile{\jobname-sec3}

\begin{mpostfig}[show,label={sec8}]
drawcircle;
label(btex 17 etex, (0,0));
\end{mpostfig}
\\
filename: \mpostgetname{sec8}
\texttt{\mpostfigurename}

\mpostdone

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
\endinput
%%
%% End of file `mpinlsmp.tex'.
