texlive[49559] Master/texmf-dist: mpostinl (31dec18)

commits+karl at tug.org commits+karl at tug.org
Mon Dec 31 23:11:07 CET 2018


Revision: 49559
          http://tug.org/svn/texlive?view=revision&revision=49559
Author:   karl
Date:     2018-12-31 23:11:07 +0100 (Mon, 31 Dec 2018)
Log Message:
-----------
mpostinl (31dec18)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/mpostinl/README.txt
    trunk/Master/texmf-dist/doc/latex/mpostinl/mpinlsmp.tex
    trunk/Master/texmf-dist/doc/latex/mpostinl/mpostinl.pdf
    trunk/Master/texmf-dist/source/latex/mpostinl/mpostinl.dtx
    trunk/Master/texmf-dist/tex/latex/mpostinl/mpostinl.sty

Modified: trunk/Master/texmf-dist/doc/latex/mpostinl/README.txt
===================================================================
--- trunk/Master/texmf-dist/doc/latex/mpostinl/README.txt	2018-12-31 22:10:54 UTC (rev 49558)
+++ trunk/Master/texmf-dist/doc/latex/mpostinl/README.txt	2018-12-31 22:11:07 UTC (rev 49559)
@@ -1,4 +1,4 @@
-mpostinl v1.4
+mpostinl v1.5
 Copyright 2010-2018 Niklas Beisert
 
 mpostinl is a LaTeX2e package

Modified: trunk/Master/texmf-dist/doc/latex/mpostinl/mpinlsmp.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/mpostinl/mpinlsmp.tex	2018-12-31 22:10:54 UTC (rev 49558)
+++ trunk/Master/texmf-dist/doc/latex/mpostinl/mpinlsmp.tex	2018-12-31 22:11:07 UTC (rev 49559)
@@ -17,7 +17,7 @@
 %% version 2005/12/01 or later.
 %% 
 \NeedsTeXFormat{LaTeX2e}[1996/12/01]
-\ProvidesFile{mpinlsmp.tex}[2018/03/01 v1.4 sample for mpostinl]
+\ProvidesFile{mpinlsmp.tex}[2018/12/30 v1.5 sample for mpostinl]
 \documentclass[12pt,a4paper]{article}
 
 \parindent0pt
@@ -44,9 +44,9 @@
 %% \mpostsetup{classopt={12pt}}
 
 %% declare packages to be used for processing labels:
-\begin{mpostdef}[tex,global]
+\begin{mposttex}[global]
 \usepackage[utf8]{inputenc}
-\end{mpostdef}
+\end{mposttex}
 
 %% specify global definitions:
 \begin{mpostdef}[global]
@@ -114,7 +114,7 @@
 \IfFileExists{\jobname-name.mps}{\includegraphics{\jobname-name.mps}}{}
 
 label does not exist:\\
-\mpostuse{notexist}
+\mpostuse{not_exist}
 
 utf-8 test:\\
 \begin{mpostfig}
@@ -123,6 +123,24 @@
 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}
 

Modified: trunk/Master/texmf-dist/doc/latex/mpostinl/mpostinl.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/latex/mpostinl/mpostinl.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/mpostinl/mpostinl.dtx	2018-12-31 22:10:54 UTC (rev 49558)
+++ trunk/Master/texmf-dist/source/latex/mpostinl/mpostinl.dtx	2018-12-31 22:11:07 UTC (rev 49559)
@@ -18,10 +18,10 @@
 % and the derived files mpostinl.sty and mpinlsmp.tex
 %
 %<package|sample>\NeedsTeXFormat{LaTeX2e}[1996/12/01]
-%<package>\ProvidesPackage{mpostinl}[2018/03/01 v1.4 metapost inline figures]
-%<sample>\ProvidesFile{mpinlsmp.tex}[2018/03/01 v1.4 sample for mpostinl]
+%<package>\ProvidesPackage{mpostinl}[2018/12/30 v1.5 metapost inline figures]
+%<sample>\ProvidesFile{mpinlsmp.tex}[2018/12/30 v1.5 sample for mpostinl]
 %<*driver>
-%\ProvidesFile{mpostinl.drv}[2018/03/01 v1.4 mpostinl reference manual file]
+%\ProvidesFile{mpostinl.drv}[2018/12/30 v1.5 mpostinl reference manual file]
 \PassOptionsToClass{10pt,a4paper}{article}
 \documentclass{ltxdoc}
 
@@ -43,7 +43,8 @@
   conditions of the LaTeX Project Public License, either version 1.3
   of this license or (at your option) any later version.}}
 \hypersetup{pdflicenseurl={http://www.latex-project.org/lppl.txt}}
-\hypersetup{pdfcontactaddress={ETH Zurich, ITP, HIT K, Wolfgang-Pauli-Strasse 27}}
+\hypersetup{pdfcontactaddress={ETH Zurich, ITP, HIT K,
+  Wolfgang-Pauli-Strasse 27}}
 \hypersetup{pdfcontactpostcode={8093}}
 \hypersetup{pdfcontactcity={Zurich}}
 \hypersetup{pdfcontactcountry={Switzerland}}
@@ -50,6 +51,13 @@
 \hypersetup{pdfcontactemail={nbeisert at itp.phys.ethz.ch}}
 \hypersetup{pdfcontacturl={http://people.phys.ethz.ch/\xmptilde nbeisert/}}
 
+\newcommand{\secref}[1]{\hyperref[#1]{section \ref*{#1}}}
+
+\parskip1ex
+\parindent0pt
+\let\olditemize\itemize
+\def\itemize{\olditemize\parskip0pt}
+
 \begin{document}
 
 \title{The \textsf{mpostinl} Package}
@@ -62,7 +70,7 @@
   {\texttt{nbeisert at itp.phys.ethz.ch}}}
 \hypersetup{pdfauthor={Niklas Beisert}}
 \hypersetup{pdfsubject={Manual for the LaTeX2e Package mpostinl}}
-\date{1 March 2018, \textsf{v1.4}}
+\date{30 December 2018, \textsf{v1.5}}
 \maketitle
 
 \begin{abstract}\noindent
@@ -77,7 +85,10 @@
 to manage the generation of files and compilation.
 \end{abstract}
 
+\begingroup
+\parskip0ex
 \tableofcontents
+\endgroup
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -206,7 +217,7 @@
 customise the management in the desired way.
 The package offers most of the functionality of the above packages,
 but (presently) misses out on some more advanced features,
-see section \ref{sec:suggestions}.
+see \secref{sec:suggestions}.
 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -227,7 +238,7 @@
 the package \textsf{graphicx} will be loaded automatically.
 Metapost figures and definitions are to be specified using
 the environments |mpostfig| and |mpostdef|, respectively,
-as described in section \ref{sec:figuresdefinitions}.
+as described in \secref{sec:figuresdefinitions}.
 
 The package collects the figure files
 contained in the \LaTeX{} source,
@@ -237,7 +248,7 @@
 will normally \emph{not} be available
 in the first \LaTeX{} run and a secondary run is required
 for the correct output,
-see section \ref{sec:immediate} for strategies
+see \secref{sec:immediate} for strategies
 to avoid a second pass.
 
 You should make sure that \LaTeX{} allows
@@ -264,13 +275,13 @@
 
 Some extended configuration options and situations are described in
 the following sections:
-package options are listed in section \ref{sec:packageoptions};
+package options are listed in \secref{sec:packageoptions};
 some options for writing and compiling are discussed
-in section \ref{sec:compiling};
+in \secref{sec:compiling};
 the generation of multiple metapost files
-is described in \ref{sec:multiplefiles};
+is described in \secref{sec:multiplefiles};
 finally, some issues regarding other \LaTeX{} packages
-are discussed in section \ref{sec:interactions}.
+are discussed in \secref{sec:interactions}.
 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -282,9 +293,9 @@
 by the package is the |mpostfig| environment:
 \begin{center}
 \begin{tabular}{l}
-|\begin{mpostfig}[|\textit{opts}|]|\\
+|\||begin{mpostfig}[|\textit{opts}|]|\\
 |  |\textit{metapost code}\\
-|\end{mpostfig}|
+|\||end{mpostfig}|
 \end{tabular}
 \end{center}
 %
@@ -334,22 +345,25 @@
 %
 \begin{itemize}
 \item
-The closing statement |\end{mpostfig}| must be on a line on its own.
+The closing statement |\||end{mpostfig}| must be on a line on its own.
 Any amount of leading whitespace is allowed,
 and trailing characters are ignored.
 
 \item
-The opening statement |\begin{mpostfig}| \emph{without} optional arguments
-must not be followed immediately by empty lines
-or by the closing statement |\end{mpostfig}|.
-Note that commented lines do not help.
-Either avoid leading empty lines and empty bodies
-or use empty optional arguments: |\begin{mpostfig}[]|.
+The opening statement |\||begin{mpostfig}| has to find out
+whether an optional argument is provided
+by scanning into the block of metapost content.
+If none is given, all the code already scanned needs to be
+(re)interpreted as metapost content.
+In special circumstances this may cause problems.
+It should then help to use an empty optional argument:
+|\||begin{mpostfig}[]|.
 
 \item
-Lines starting with a single `|%|' are ignored and
-do not appear in the metapost file.
-Double `|%%|' or leading spaces preserve comments in the metapost file.
+Lines starting with a single `|%|'
+are ignored and do not appear in the metapost file.
+Double `|%%|'
+or leading spaces preserve comments in the metapost file.
 
 \item
 The environment |mpostfig|
@@ -362,8 +376,6 @@
 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\medskip
-\noindent
 \DescribeMacro{\mpostuse}
 Figures which have been previously declared
 with a label \textit{label}
@@ -381,8 +393,6 @@
 and passes it on to |\includegraphics|.
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\medskip
-\noindent
 \DescribeMacro{\mpostgetname}
 Furthermore, the filename of a figure can be obtained by
 calling |\mpostgetname{|\textit{label}|}|.
@@ -389,16 +399,16 @@
 The filename is returned in the macro |\mpostfigurename|.
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\medskip\noindent
 \DescribeEnv{mpostdef}
 Plain metapost code which is not part of a figure
 (definitions, assignments)
 can be specified by the |mpostdef| environment:
+%
 \begin{center}
 \begin{tabular}{l}
-|\begin{mpostdef}[|\textit{opts}|]|\\
+|\||begin{mpostdef}[|\textit{opts}|]|\\
 |  |\textit{code}\\
-|\end{mpostdef}|
+|\||end{mpostdef}|
 \end{tabular}
 \end{center}
 %
@@ -408,17 +418,51 @@
 is a comma-separated list of options:
 %
 \begin{itemize}
+\item |global|[|=true|$\vert$|false|]
+(no value implies |true|, overrides global setting |globaldef|) --
+In a setup with multiple metapost files, the block \textit{code}
+is applied to all files, not just the current file.
+
 \item |tex|[|=true|$\vert$|false|]
 (no value implies |true|, initially set to |false|) --
 The block \textit{code} represents \TeX{} or \LaTeX{} definitions
 rather than \MP{} code,
 which will be enclosed in the metapost file by |verbatimtex| and |etex|.
+This feature is superseded by the environment |mposttex| described below.
+The |tex| option is deprecated, and provided for backward compatibility only.
 
+\end{itemize}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\DescribeEnv{mposttex}
+\TeX{} or \LaTeX{} definitions for use in metapost labels
+can be specified by the |mposttex| environment:
+%
+\begin{center}
+\begin{tabular}{l}
+|\||begin{mposttex}[|\textit{opts}|]|\\
+|  |\textit{code}\\
+|\||end{mposttex}|
+\end{tabular}
+\end{center}
+%
+The code will be enclosed in the metapost file by |verbatimtex| and |etex|.
+Note that the same restrictions as for |mpostfig| (see above)
+apply to |mposttex|.
+The optional argument \textit{opts}
+is a comma-separated list of options:
+%
+\begin{itemize}
 \item |global|[|=true|$\vert$|false|]
 (no value implies |true|, overrides global setting |globaldef|) --
 In a setup with multiple metapost files, the block \textit{code}
 is applied to all files, not just the current file.
 
+\item |dual|[|=true|$\vert$|false|]
+(no value implies |true|, initially set to |false|) --
+The definitions within the block \textit{code}
+will be available to both metapost figures and subsequent \LaTeX{} code.
+
 \end{itemize}
 
 
@@ -585,7 +629,7 @@
 \item |globaldef|[|=true|$\vert$|false|]
 (no value implies |true|, initially set to |false|) --
 Enable/disable the |global| option
-for the |mpostdef| environments by default.
+for the |mpostdef| and |mposttex| environments by default.
 This option can be used to specify a global block of definitions
 by enclosing it with appropriate |\mpostsetup| statements.
 
@@ -634,6 +678,7 @@
 how things should be managed.
 
 \DescribeMacro{\mpostplaceholder}
+\DescribeMacro{\mpostdisplaylabel}
 Finally, the package allows to customise the placeholder
 which is displayed when a figure file is not (yet) present
 after the first \LaTeX{} pass (or in case of some compile error)
@@ -647,6 +692,9 @@
 By default this command displays a 1''$\times$0.6'' box
 containing the missing filename or label.
 This behaviour can be customised by overwriting the macro.
+It makes sense to display the filename or label through
+|\mpostdisplaylabel| which can handle some special characters
+such as an underscore.
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \subsection{Writing and Compiling Options}
@@ -686,7 +734,7 @@
 An alternative class and options can be specified
 by the package options |class| and |classopt|.
 Further packages or macros should be declared as usual
-by specifying them in a |mpostdef| enviroment in |tex| mode.
+by specifying them in a |mposttex| enviroment.
 If no \LaTeX{} structure is desired,
 set the package option |latex| to |false|.
 If the typesetting requires an advanced compiler
@@ -805,14 +853,10 @@
 in which case only the relevant metapost file
 is generated and compiled.
 
-\medskip
-
 The contents of each metapost file should be enclosed
 by |\mpostfile| and |\mpostdone|.
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\medskip
-\noindent
 \DescribeMacro{\mpostfile}
 A new metapost file is started by the command:
 \begin{center}
@@ -826,8 +870,6 @@
 which declares whether the file is an include file.
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\medskip
-\noindent
 \DescribeMacro{\mpostdone}
 The present metapost file is completed by the command
 |\mpostdone| which also compiles the contained figures.
@@ -837,12 +879,12 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \paragraph{Global Definitions.}
 
-Definitions in |mpostdef| environments apply to the
+Definitions in |mpostdef| and |mposttex| environments apply to the
 present metapost file only. However, definitions can also be
 specified for all metapost files
 by means of the option |global|:
 \begin{center}
-|\begin{mpostdef}[global]|%\end{mpostdef}
+|\||begin{mpostdef}[global]|
 \end{center}
 These definitions are stored internally and will be written
 to all subsequent metapost files.
@@ -1009,9 +1051,9 @@
 in the metapost figures by means of:
 \begin{center}
 \begin{tabular}{l}
-|\begin{mpostdef}[tex]|\\
+|\||begin{mposttex}|\\
 |\usepackage[|\textit{enc}|]{inputenc}|\\
-|\end{mpostdef}|
+|\||end{mposttex}|
 \end{tabular}
 \end{center}
 
@@ -1024,7 +1066,7 @@
 by means on an overlay mechanism.
 To that end the |frame| environment
 saves the enclosed block and processes it in several passes.
-Therefore, the environments |mpostfig| and |mpostdef|
+Therefore, the environments |mpostfig|, |mpostdef| and |mposttex|
 must not be used within the |frame| environment.
 Instead, figures should be declared outside the |frame| environment
 and can be displayed by |\mpostuse| within the |frame| environment.
@@ -1041,7 +1083,7 @@
 Since graphics arguments are passed on directly to |\includegraphics|
 the \textsf{graphbox} package can be used without restrictions.
 For instance, to align a figure vertically with the centre of the line,
-you may use |\begin{mpostfig}[opt={align}]|
+you may use |\||begin{mpostfig}[opt={align}]|
 or |\mpostuse[align]{|\textit{label}|}|.
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -1089,10 +1131,6 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \subsection{Copyright}
 
-\begingroup
-\parskip1ex
-\parindent0pt
-
 Copyright \copyright{} 2010--2018 Niklas Beisert
 
 This work may be distributed and/or modified under the
@@ -1110,8 +1148,6 @@
 This work consists of the files |README.txt|, |mpostinl.ins| and |mpostinl.dtx|
 as well as the derived files |mpostinl.sty|, |mpinlsmp.tex| and |mpostinl.pdf|.
 
-\endgroup
-
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \subsection{Files and Installation}
 
@@ -1212,10 +1248,6 @@
 However, both appear to be somewhat in contrast
 to the usual \TeX{} philosophy.
 %\item
-%an environment to pass tex commands to mpost and also compile them locally
-%probably have to write to file and subsequently input the file
-%perhaps could use \scantokens!
-%\item
 %improve detection of changed figure files?
 %allow to declare extra include files for update detection
 \end{itemize}
@@ -1224,6 +1256,21 @@
 \subsection{Revision History}
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\paragraph{v1.5:} 2018/12/30
+
+\begin{itemize}
+\item
+new environment |mposttex| for \TeX{} or \LaTeX{} definitions
+to replace option |tex| of |mpostdef|;
+can be used in |dual| mode
+\item
+allow underscore, caret and ampersand in figure labels and filenames
+\item
+improve handling of optional arguments and special situations
+when scanning metapost blocks
+\end{itemize}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \paragraph{v1.4:} 2018/03/01
 
 \begin{itemize}
@@ -1350,8 +1397,6 @@
 \appendix
 
 \settowidth\MacroIndent{\rmfamily\scriptsize 000\ }
-\parskip1ex
-\parindent0pt
 
  \DocInput{mpostinl.dtx}
 
@@ -1425,9 +1470,9 @@
 % make sure this statement in included in all of them:
 %    \begin{macrocode}
 %% declare packages to be used for processing labels:
-\begin{mpostdef}[tex,global]
+\begin{mposttex}[global]
 \usepackage[utf8]{inputenc}
-\end{mpostdef}
+\end{mposttex}
 %    \end{macrocode}
 
 % Define an internal variable |unit| and initialise to 1cm;
@@ -1551,7 +1596,7 @@
 % triggers a warning and displays a box:
 %    \begin{macrocode}
 label does not exist:\\
-\mpostuse{notexist}
+\mpostuse{not_exist}
 %    \end{macrocode}
 
 % Display a figure with a label containing special characters in UTF-8.
@@ -1566,6 +1611,36 @@
 \end{mpostfig}
 %    \end{macrocode}
 
+% Write a totally empty figure
+%    \begin{macrocode}
+empty figure:\\
+\begin{mpostfig}
+\end{mpostfig}
+%    \end{macrocode}
+
+% Write a figure with an empty line
+%    \begin{macrocode}
+empty figure:\\
+\begin{mpostfig}
+
+\end{mpostfig}
+%    \end{macrocode}
+
+% Make a dual definition
+%    \begin{macrocode}
+\begin{mposttex}[dual]
+\def\mymacro{hello!}
+\end{mposttex}
+%    \end{macrocode}
+% and test it
+%    \begin{macrocode}
+dual definition `\mymacro':\\
+\begin{mpostfig}
+draw unitsquare shifted (-0.5,-0.5) xscaled 3 scaled unit;
+label(btex \mymacro etex, (0,0));
+\end{mpostfig}
+%    \end{macrocode}
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \subsection{Immediate Processing}
 %
@@ -1871,10 +1946,10 @@
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \paragraph{Package Options.}
 %
-% \begin{macro}{\mpostfilename}
-% \begin{macro}{\mpi at nowname}
-% \begin{macro}{\mpi at extension}
-% \begin{macro}{\mpi at template}
+% \macro{\mpostfilename}
+% \macro{\mpi at nowname}
+% \macro{\mpi at extension}
+% \macro{\mpi at template}
 % |\mpostfilename| stores the metapost filename,
 % |\mpi at nowname| stores the filename for immediate processing,
 % and |\mpi at template| is the template to generate the figure filenames:
@@ -1885,18 +1960,13 @@
 \def\mpi at template#1{\mpostfilename-#1%
   \ifx\mpi at extension\mpi at empty\else.\fi\mpi at extension}
 %    \end{macrocode}
-% \end{macro}
-% \end{macro}
-% \end{macro}
-% \end{macro}
 
-% \begin{macro}{mpi at count}
+% \macro{mpi at count}
 % Declare a counter for figure filenames:
 %    \begin{macrocode}
 \newcounter{mpi at count}
 \def\thempi at count{\arabic{mpi at count}}
 %    \end{macrocode}
-% \end{macro}
 
 % The package has some boolean \textsf{keyval} options
 % which can be set to |true| or |false|.
@@ -1916,15 +1986,16 @@
 \newif\ifmpi at nowkeep\mpi at nowkeepfalse
 \newif\ifmpi at include\mpi at includefalse
 \newif\ifmpi at defglobal\mpi at defglobalfalse
+\newif\ifmpi at texdual\mpi at texdualfalse
 \newif\ifmpi at warnunused\mpi at warnunusedtrue
 \newif\ifmpi at beamer\mpi at beamertrue
 %    \end{macrocode}
 
-% \begin{macro}{\mpi at mpostmem}
-% \begin{macro}{\mpi at mpostcompiler}
-% \begin{macro}{\mpi at latexclass}
-% \begin{macro}{\mpi at latexoptions}
-% \begin{macro}{\mpi at documentclass}
+% \macro{\mpi at mpostmem}
+% \macro{\mpi at mpostcompiler}
+% \macro{\mpi at latexclass}
+% \macro{\mpi at latexoptions}
+% \macro{\mpi at documentclass}
 % These definitions store the options for processing labels via
 % \TeX{} or \LaTeX{}:
 %    \begin{macrocode}
@@ -1935,13 +2006,8 @@
 \def\mpi at documentclass{\@backslashchar documentclass%
   \mpi at latexoptions{\mpi at latexclass}}
 %    \end{macrocode}
-% \end{macro}
-% \end{macro}
-% \end{macro}
-% \end{macro}
-% \end{macro}
 
-% \begin{macro}{\mpi at warncompile}
+% \macro{\mpi at warncompile}
 % Warn and disable compiling if |\write18| is unavailable:
 %    \begin{macrocode}
 \def\mpi at warncompile{\ifmpi at compile\ifeof18%
@@ -1949,7 +2015,6 @@
     manual metapost compiling required}{}%
   \global\mpi at compilefalse\fi\fi}
 %    \end{macrocode}
-% \end{macro}
 
 % Process package options:
 %    \begin{macrocode}
@@ -2004,30 +2069,27 @@
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \paragraph{Internal Commands and Definitions.}
 %
-% \begin{macro}{\mpi at empty}
+% \macro{\mpi at empty}
 % Define an empty macro for comparison via |\ifx|:
 %    \begin{macrocode}
 \def\mpi at empty{}
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at unusedlist}
+% \macro{\mpi at unusedlist}
 % Initialise a list of unused figure labels:
 %    \begin{macrocode}
 \def\mpi at unusedlist{}
 %    \end{macrocode}
-% \end{macro}
 
 
-% \begin{macro}{\mpi at dblquotchar}
+% \macro{\mpi at dblquotchar}
 % Define a bare double quotation character for writing to the file:
 %    \begin{macrocode}
 \begingroup\catcode`\"=12\relax\gdef\mpi at dblquotchar{"}\endgroup
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\ifmpi at infile}
-% \begin{macro}{\ifmpi at inbody}
+% \macro{\ifmpi at infile}
+% \macro{\ifmpi at inbody}
 % |\ifmpi at infile| indicates whether a file is open,
 % |\ifmpi at inbody| indicates whether the content section has started:
 %    \begin{macrocode}
@@ -2034,11 +2096,9 @@
 \newif\ifmpi at infile\mpi at infilefalse
 \newif\ifmpi at inbody\mpi at inbodyfalse
 %    \end{macrocode}
-% \end{macro}
-% \end{macro}
 
-% \begin{macro}{\ifmpi at inclmod}
-% \begin{macro}{\ifmpi at filemod}
+% \macro{\ifmpi at inclmod}
+% \macro{\ifmpi at filemod}
 % |\ifmpi at inclmod| indicates whether an include file has been modified,
 % |\ifmpi at filemod| indicates whether the current file is modified:
 %    \begin{macrocode}
@@ -2045,11 +2105,9 @@
 \newif\ifmpi at inclmod\mpi at inclmodfalse
 \newif\ifmpi at filemod
 %    \end{macrocode}
-% \end{macro}
-% \end{macro}
 
-% \begin{macro}{\ifmpi at warnmod}
-% \begin{macro}{\ifmpi at showinfile}
+% \macro{\ifmpi at warnmod}
+% \macro{\ifmpi at showinfile}
 % |\ifmpi at warnmod| indicates whether a rerun warning is to be issued,
 % |\ifmpi at showinfile| indicates whether a figure has been displayed
 %   while a file is being composed:
@@ -2057,11 +2115,9 @@
 \newif\ifmpi at warnmod\mpi at warnmodfalse
 \newif\ifmpi at showinfile
 %    \end{macrocode}
-% \end{macro}
-% \end{macro}
 
-% \begin{macro}{\mpi at out}
-% \begin{macro}{\mpi at outnow}
+% \macro{\mpi at out}
+% \macro{\mpi at outnow}
 % File handles for the metapost file (|\mpi at out|)
 % and for immediate output (|\mpi at outnow|):
 %    \begin{macrocode}
@@ -2068,26 +2124,22 @@
 \newwrite\mpi at out
 \newwrite\mpi at outnow
 %    \end{macrocode}
-% \end{macro}
-% \end{macro}
 
-% \begin{macro}{\mpi at writebuf}
+% \macro{\mpi at writebuf}
 % Write to the file:
 %    \begin{macrocode}
 \def\mpi at writebuf{\ifmpi at write\immediate\write\mpi at out{\the\mpi at buf}\fi}
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at writenow}
+% \macro{\mpi at writenow}
 % Write to the immediate buffer:
 %    \begin{macrocode}
 \def\mpi at writenow{\ifmpi at nowactive\mpi at addtoexp\mpi at nowbuf{\the\mpi at buf^^J}\fi}
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at buf}
-% \begin{macro}{\mpi at defbuf}
-% \begin{macro}{\mpi at nowbuf}
+% \macro{\mpi at buf}
+% \macro{\mpi at defbuf}
+% \macro{\mpi at nowbuf}
 % Declare three token buffers to store the current block (|\mpi at buf|),
 % global definitions (|\mpi at defbuf|)
 % and the definitions for immediate processing (|\mpi at nowbuf|):
@@ -2095,14 +2147,12 @@
 \newtoks\mpi at buf
 \newtoks\mpi at defbuf
 \newtoks\mpi at nowbuf
+\newtoks\mpi at verbbuf
 \mpi at defbuf={}
 %    \end{macrocode}
-% \end{macro}
-% \end{macro}
-% \end{macro}
 
-% \begin{macro}{\mpi at addto}
-% \begin{macro}{\mpi at addtoexp}
+% \macro{\mpi at addto}
+% \macro{\mpi at addtoexp}
 % |\mpi at addto| adds the second argument to a global token buffer
 % without expansion.
 % |\mpi at addtoexp| first expands the second argument (once)
@@ -2111,25 +2161,24 @@
 \def\mpi at addto#1#2{\global#1=\expandafter{\the#1#2}}
 \def\mpi at addtoexp#1#2{\expandafter\mpi at addto\expandafter#1\expandafter{#2}}
 %    \end{macrocode}
-% \end{macro}
-% \end{macro}
 
-% \begin{macro}{\mpi at clearbuf}
-% \begin{macro}{\mpi at addbufexp}
-% \begin{macro}{\mpi at addbuf}
+% \macro{\mpi at clearbuf}
+% \macro{\mpi at addbufexp}
+% \macro{\mpi at addbufbuf}
+% \macro{\mpi at addbuf}
 % |\mpi at clearbuf| clears the current block buffer.
-% |\mpi at addbufexp| expands (once) and adds to the current block buffer.
+% |\mpi at addbufexp| expands the first token
+% and adds to the current block buffer.
+% |\mpi at addbufbuf| adds a buffer to the current block buffer.
 % |\mpi at addbuf| adds to the current block buffer via |\protected at edef|:
 %    \begin{macrocode}
 \def\mpi at clearbuf{\global\mpi at buf={}}
 \def\mpi at addbufexp#1{\mpi at addtoexp\mpi at buf{#1^^J}}
+\def\mpi at addbufbuf#1{\mpi at addtoexp\mpi at buf{\the#1}}
 \def\mpi at addbuf#1{{\protected at edef\mpi at tmp{#1}\mpi at addbufexp\mpi at tmp}}
 %    \end{macrocode}
-% \end{macro}
-% \end{macro}
-% \end{macro}
 
-% \begin{macro}{\mpi at stripext}
+% \macro{\mpi at stripext}
 % Strip |.mps| or |.eps| ending of a figure filename,
 % return result in |\mpi at stripped|:
 %    \begin{macrocode}
@@ -2154,9 +2203,8 @@
   \expandafter\endgroup\mpi at tmp%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at warnmod}
+% \macro{\mpi at warnmod}
 % Warn if some figure has been displayed while a file has been written
 % (potentially the displayed figure is old):
 %    \begin{macrocode}
@@ -2167,9 +2215,8 @@
   \fi\fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at warnunused}
+% \macro{\mpi at warnunused}
 % This macro processes the list of all figure labels
 % and issues a warning for every unused ones:
 %    \begin{macrocode}
@@ -2186,9 +2233,17 @@
 %    \begin{macrocode}
 \AtEndDocument{\expandafter\mpi at warnunused\mpi at unusedlist{}}
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpostplaceholder}
+% \macro{\mpostdisplaylabel}
+% Rescan a string potentially containing the special characters
+% underscore (`|_|'), caret (`|^|') and ampersand (`|&|'):
+%    \begin{macrocode}
+\newcommand{\mpostdisplaylabel}[1]{{%
+  \catcode`\_=11\catcode`\^=11\catcode`\&=11%
+  \edef\mpi at tmp{#1}\expandafter\scantokens\expandafter{\mpi at tmp}}}
+%    \end{macrocode}
+
+% \macro{\mpostplaceholder}
 % Display a placeholder for non-existing files or labels;
 % this function may be overwritten by the user for customisation purposes
 % (optional argument contains either `|file|' or `|label|'):
@@ -2195,12 +2250,12 @@
 %    \begin{macrocode}
 \newcommand{\mpostplaceholder}[2][]{\parbox[c]{1in}{%
   \hrule\vrule\hfill%
-  \parbox[c]{0pt}{\rule{0cm}{0.6in}}\makebox[0pt][c]{\scriptsize\tt #2}%
+  \parbox[c]{0pt}{\rule{0cm}{0.6in}}%
+    \makebox[0pt][c]{\scriptsize\tt\mpostdisplaylabel{#2}}%
   \hfill\vrule\hrule}}
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at graphics}
+% \macro{\mpi at graphics}
 % Display a figure;
 % if the file does not exist (yet) issue a warning and display a placeholder,
 % otherwise expand filename properly and pass on to |\includegraphics|:
@@ -2211,9 +2266,8 @@
     {\typeout{graphics file `#2' missing}\mpostplaceholder[file]{#2}}%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at verbatim}
+% \macro{\mpi at verbatim}
 % Start reading the block from the source file
 % using the \textsf{verbatim} package;
 % add each line to the buffer:
@@ -2223,13 +2277,13 @@
   \@bsphack%
   \let\do\@makeother\dospecials%
   \catcode`\^^M\active%
-  \def\verbatim at processline{\mpi at addbufexp{\the\verbatim at line}}%
+  \global\mpi at verbbuf={}%
+  \def\verbatim at processline{\mpi at addtoexp\mpi at verbbuf{\the\verbatim at line^^J}}%
   \verbatim at start%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at endverbatim}
+% \macro{\mpi at endverbatim}
 % End reading the block from the source file:
 %    \begin{macrocode}
 \newcommand{\mpi at endverbatim}{%
@@ -2237,9 +2291,29 @@
   \endgroup%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at putlineno}
+% \macro{\mpi at scanblock}
+% Read one optional argument and pass on
+% to an environment which reads a block from the source file.
+% Handle special cases of an initial empty line
+% or a completely empty block.
+% Pass prefetched tokens as second argument:
+%    \begin{macrocode}
+\def\mpi at scanblock#1{%
+  \@ifnextchar\par{\mpi at scanblock@par{#1}}{\mpi at scanblock@sel{#1}}}
+\long\def\mpi at scanblock@par#1\par{\mpi at scanblock@sel{#1}[]}
+\def\mpi at scanblock@sel#1{\@ifnextchar[{\mpi at scanblock@opt{#1}}%
+  {\@ifnextchar\end{\mpi at scanblock@end{#1}}{\mpi at scanblock@noopt{#1}}}}
+\def\mpi at scanblock@end#1\end#2{%
+  \def\mpi at tmp{#2}\ifx\mpi at tmp\@currenvir%
+    \def\mpi at verbatim{\global\mpi at verbbuf={}}\def\mpi at endverbatim{}%
+  \fi%
+  #1{}{\scantokens{\end{#2}}}}
+\def\mpi at scanblock@noopt#1#2{#1{}{\scantokens#2}}
+\def\mpi at scanblock@opt#1[#2]{#1{#2}{}}
+%    \end{macrocode}
+
+% \macro{\mpi at putlineno}
 % Write current position in source file to buffer;
 % write line number and source file name
 % (if available via package \textsf{currfile}):
@@ -2253,9 +2327,8 @@
   \fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at beginfig}
+% \macro{\mpi at beginfig}
 % Write beginning of figure block to buffer;
 % write filename and |beginfig| statement:
 %    \begin{macrocode}
@@ -2264,9 +2337,8 @@
   \mpi at addbuf{beginfig(\arabic{mpi at count})}%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at endfig}
+% \macro{\mpi at endfig}
 % Write end of figure block to buffer;
 % write |endfig| statement:
 %    \begin{macrocode}
@@ -2274,9 +2346,8 @@
   \mpi at addbuf{endfig;}%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at declaredoc}
+% \macro{\mpi at declaredoc}
 % Write |\documentclass| statement in \LaTeX{} mode to buffer:
 %    \begin{macrocode}
 \newcommand{\mpi at declaredoc}{%
@@ -2288,11 +2359,10 @@
   \fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at begindoc}
+% \macro{\mpi at begindoc}
 % Write beginning of content section to buffer;
-% write |\begin{document}| statement in \LaTeX{} mode:
+% write |\||begin{document}| statement in \LaTeX{} mode:
 %    \begin{macrocode}
 \newcommand{\mpi at begindoc}{%
   \ifmpi at latex%
@@ -2303,11 +2373,10 @@
   \fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at enddoc}
+% \macro{\mpi at enddoc}
 % Write end of content section to buffer;
-% write |\end{document}| statement in \LaTeX{} mode:
+% write |\||end{document}| statement in \LaTeX{} mode:
 %    \begin{macrocode}
 \newcommand{\mpi at enddoc}{%
   \ifmpi at latex%
@@ -2318,9 +2387,8 @@
   \fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at declareformat}
+% \macro{\mpi at declareformat}
 % Write \TeX{} format specifier to buffer:
 %    \begin{macrocode}
 \newcommand{\mpi at declareformat}{%
@@ -2334,9 +2402,8 @@
   \fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at composehead}
+% \macro{\mpi at composehead}
 % Write file header to buffer;
 % declare font inclusion and draft mode,
 % write \TeX{} format specifier and \LaTeX{} header:
@@ -2354,9 +2421,8 @@
   \mpi at declaredoc%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at beginfile}
+% \macro{\mpi at beginfile}
 % Write beginning of file to buffer;
 % write generated file comment and header:
 %    \begin{macrocode}
@@ -2367,13 +2433,12 @@
   \mpi at addbuf{\@percentchar generated from file `\jobname' by mpostinl.sty}%
   \ifmpi at include\else%
     \mpi at composehead%
-    \mpi at addbufexp{\the\mpi at defbuf}%
+    \mpi at addbufbuf{\mpi at defbuf}%
   \fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at endfile}
+% \macro{\mpi at endfile}
 % Write end of file to buffer;
 % write |end| statement:
 %    \begin{macrocode}
@@ -2384,9 +2449,8 @@
   \fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at getchecksum}
+% \macro{\mpi at getchecksum}
 % Compute the MD5 checksum for a metapost file and store in macro:
 %    \begin{macrocode}
 \newcommand{\mpi at getchecksum}[3]{%
@@ -2393,9 +2457,8 @@
   \IfFileExists{#3}{#1\edef#2{\pdfmdfivesum file{#3}}}{#1\let#2=\@undefined}%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at startfile}
+% \macro{\mpi at startfile}
 % Start a new file if not already open:
 %    \begin{macrocode}
 \newcommand{\mpi at startfile}{%
@@ -2443,9 +2506,8 @@
   \fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at startcontent}
+% \macro{\mpi at startcontent}
 % Start content section of file;
 % make sure the file is open,
 % prepare start of content section and write to file,
@@ -2462,9 +2524,8 @@
   \fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at compile}
+% \macro{\mpi at compile}
 % Compile the metapost file (if writing and compiling is enabled):
 %    \begin{macrocode}
 \newcommand{\mpi at compile}[1]{%
@@ -2506,9 +2567,8 @@
   \fi\fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at cleanfile}
+% \macro{\mpi at cleanfile}
 % Write a mps file containing a plain cross:
 %    \begin{macrocode}
 \newcommand{\mpi at cleanfile}[1]{%
@@ -2528,9 +2588,8 @@
   \immediate\closeout\mpi at outnow%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at cleanfiles}
+% \macro{\mpi at cleanfiles}
 % Clean all figure files prior to compilation:
 %    \begin{macrocode}
 \newcommand{\mpi at cleanfiles}[1]{%
@@ -2540,9 +2599,8 @@
   \expandafter\endgroup\mpi at tmp%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at closefile}
+% \macro{\mpi at closefile}
 % Close the file, compile and reset:
 %    \begin{macrocode}
 \newcommand{\mpi at closefile}{%
@@ -2575,7 +2633,8 @@
 % during composition:
 %    \begin{macrocode}
     \ifmpi at filemod\ifmpi at inbody%
-      \ifmpi at clean\expandafter\mpi at cleanfiles\mpi at filelist{}\fi%
+      \ifmpi at clean\ifmpi at write\ifmpi at compile%
+        \expandafter\mpi at cleanfiles\mpi at filelist{}\fi\fi\fi%
       \mpi at compile{\mpostfilename.mp}%
     \fi\fi%
     \ifmpi at filemod\ifmpi at showinfile\global\mpi at warnmodtrue\fi\fi%
@@ -2589,9 +2648,8 @@
   \fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpi at processnow}
+% \macro{\mpi at processnow}
 % Write present figure to an individual file and process immediately:
 %    \begin{macrocode}
 \newcommand{\mpi at processnow}{%
@@ -2623,7 +2681,6 @@
   \fi\fi\fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
 % Make sure to close and process the file at the end.
 % Warn if figures may need another compiler pass:
@@ -2637,7 +2694,7 @@
 %
 % The following commands are the interface of the package.
 %
-% \begin{macro}{\mpostsetup}
+% \macro{\mpostsetup}
 % |\mpostsetup| processes package options
 % when the package has already been loaded:
 %    \begin{macrocode}
@@ -2647,9 +2704,8 @@
   \ifdefined\pdfmdfivesum\else\mpi at checksumfalse\fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{mpostdef}
+% \macro{mpostdef}
 % Declare options for the |mpostdef| environment:
 %    \begin{macrocode}
 \newif\ifmpi at deftex
@@ -2658,9 +2714,11 @@
 %    \end{macrocode}
 
 % The environment |mpostdef| adds a block
-% of definitions to the metapost file:
+% of definitions to the metapost file.
+% Pass on to |\mpi at scanblock| mechanism:
 %    \begin{macrocode}
-\newenvironment{mpostdef}[1][]{%
+\def\mpostdef{\mpi at scanblock{\mpi at mpostdef}}
+\def\mpi at mpostdef#1#2{%
 %    \end{macrocode}
 % Process optional arguments:
 %    \begin{macrocode}
@@ -2687,14 +2745,16 @@
   \ifmpi at deftex%
     \mpi at addbuf{verbatimtex}%
   \fi%
-  \mpi at verbatim%
+  \mpi at verbatim#2%
 }
 %    \end{macrocode}
 % Postprocessing; add `|etex|' if in \TeX{} mode,
 % add to appropriate buffer(s).
 %    \begin{macrocode}
+\def\endmpostdef
 {%
   \mpi at endverbatim%
+  \mpi at addbufbuf{\mpi at verbbuf}%
   \ifmpi at deftex%
     \mpi at addbuf{etex}%
   \fi%
@@ -2710,9 +2770,79 @@
   \fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{mpostfig}
+% \macro{mposttex}
+% Declare options for the |mposttex| environment:
+%    \begin{macrocode}
+\newif\ifmpi at deftex
+\define at key{mpi at tex}{dual}[true]{\csname mpi at texdual#1\endcsname}
+\define at key{mpi at tex}{global}[true]{\csname mpi at defglobal#1\endcsname}
+%    \end{macrocode}
+
+% The environment |mposttex| adds a block
+% of tex definitions to the metapost file.
+% Pass on to |\mpi at scanblock| mechanism:
+%    \begin{macrocode}
+\def\mposttex{\mpi at scanblock{\mpi at mposttex}}
+\def\mpi at mposttex#1#2{%
+%    \end{macrocode}
+% Process optional arguments:
+%    \begin{macrocode}
+  \mpi at texdualfalse%
+  \setkeys{mpi at tex}{#1}%
+%    \end{macrocode}
+% \TeX{} definitions cannot be in an include file:
+%    \begin{macrocode}
+  \ifmpi at defglobal\else\ifmpi at include%
+    \PackageWarning{mpostinl}{tex definitions within an include file %
+      will be ignored by mpost; switching to global definition}{}%
+    \mpi at defglobaltrue%
+  \fi\fi%
+%    \end{macrocode}
+% Prepare for recording; start the file if not open and not global,
+% clear buffer, write current position, and add `|verbatimtex|':
+%    \begin{macrocode}
+  \ifmpi at defglobal\else%
+    \mpi at startfile%
+  \fi%
+  \mpi at clearbuf%
+  \mpi at putlineno%
+  \mpi at addbuf{verbatimtex}%
+  \mpi at verbatim#2%
+}
+%    \end{macrocode}
+% Postprocessing; add `|etex|',
+% add to appropriate buffer(s).
+%    \begin{macrocode}
+\def\endmposttex
+{%
+  \mpi at endverbatim%
+  \mpi at addbufbuf{\mpi at verbbuf}%
+  \mpi at addbuf{etex}%
+  \ifmpi at defglobal%
+    \mpi at addtoexp\mpi at defbuf{\the\mpi at buf^^J}%
+    \ifmpi at include\else\ifmpi at infile%
+      \mpi at writebuf%
+      \mpi at writenow%
+    \fi\fi%
+  \else%
+    \mpi at writebuf%
+    \ifmpi at include\else\mpi at writenow\fi%
+  \fi%
+%    \end{macrocode}
+% Hack |\ignorespacesafterend| mechanism to
+% ship out block contents after environment group:
+%    \begin{macrocode}
+  \ifmpi at texdual%
+    \ignorespacesafterend%
+    \global\let\mpi at ignorespaces\ignorespaces%
+    \gdef\ignorespaces{\expandafter\scantokens\expandafter{\the\mpi at verbbuf}%
+      \global\let\ignorespaces\mpi at ignorespaces}%
+  \fi%
+}
+%    \end{macrocode}
+
+% \macro{mpostfig}
 % Declare options for the |mpostfig| environment:
 %    \begin{macrocode}
 \newif\ifmpi at figshow
@@ -2724,9 +2854,11 @@
 \define at key{mpi at fig}{now}[true]{\csname mpi at now#1\endcsname}
 %    \end{macrocode}
 
-% The environment |mpostfig| adds a figure to the metapost file:
+% The environment |mpostfig| adds a figure to the metapost file.
+% Pass on to |\mpi at scanblock| mechanism:
 %    \begin{macrocode}
-\newenvironment{mpostfig}[1][]{%
+\def\mpostfig{\mpi at scanblock{\mpi at mpostfig}}
+\def\mpi at mpostfig#1#2{%
 %    \end{macrocode}
 % Make sure that include files do not contain figures:
 %    \begin{macrocode}
@@ -2780,14 +2912,16 @@
   \mpi at clearbuf%
   \mpi at putlineno%
   \mpi at beginfig{\mpi at figfile}%
-  \mpi at verbatim%
+  \mpi at verbatim#2%
 }
 %    \end{macrocode}
 % Postprocessing; end figure block, add to buffer, add file to list,
 % process immediately if desired:
 %    \begin{macrocode}
+\def\endmpostfig
 {%
   \mpi at endverbatim%
+  \mpi at addbufbuf{\mpi at verbbuf}%
   \mpi at endfig%
   \mpi at writebuf%
   \xdef\mpi at filelist{\mpi at filelist{\mpi at figfile}}%
@@ -2821,9 +2955,8 @@
   \fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpostuse}
+% \macro{\mpostuse}
 % |\mpostuse| includes a metapost figure which was declared earlier
 % via its label. The optional argument is passed as the optional
 % argument for |\includegraphics|.
@@ -2841,9 +2974,8 @@
   \fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpostgetname}
+% \macro{\mpostgetname}
 % |\mpostgetname| gets the filename of a figure declared earlier
 % via its label and returns it in the macro |\mpostfigurename|.
 % Remember that the label has been used:
@@ -2858,9 +2990,8 @@
   \fi%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpostfile}
+% \macro{\mpostfile}
 % Declare options for |\mpostfile|:
 %    \begin{macrocode}
 \define at key{mpi at file}{include}[true]{\csname mpi at include#1\endcsname}
@@ -2877,17 +3008,15 @@
   \xdef\mpostfilename{#2}%
 }
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpostdone}
+% \macro{\mpostdone}
 % |\mpostdone| closes the present metapost file
 % and processes it if applicable:
 %    \begin{macrocode}
 \newcommand{\mpostdone}{\mpi at closefile}
 %    \end{macrocode}
-% \end{macro}
 
-% \begin{macro}{\mpostuse<>}
+% \macro{\mpostuse<>}
 % This overwrites the definition of |\mpostfile|
 % to accept the overlay option |<|\ldots|>|
 % of the \textsf{beamer} package:
@@ -2900,7 +3029,6 @@
     \mpi at plain@mpostuse[#1]{#2}\endgroup}%
 }{}\fi
 %    \end{macrocode}
-% \end{macro}
 
 %\iffalse
 %</package>

Modified: trunk/Master/texmf-dist/tex/latex/mpostinl/mpostinl.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/mpostinl/mpostinl.sty	2018-12-31 22:10:54 UTC (rev 49558)
+++ trunk/Master/texmf-dist/tex/latex/mpostinl/mpostinl.sty	2018-12-31 22:11:07 UTC (rev 49559)
@@ -17,7 +17,7 @@
 %% version 2005/12/01 or later.
 %% 
 \NeedsTeXFormat{LaTeX2e}[1996/12/01]
-\ProvidesPackage{mpostinl}[2018/03/01 v1.4 metapost inline figures]
+\ProvidesPackage{mpostinl}[2018/12/30 v1.5 metapost inline figures]
 
 \RequirePackage{verbatim}
 \RequirePackage{graphicx}
@@ -47,6 +47,7 @@
 \newif\ifmpi at nowkeep\mpi at nowkeepfalse
 \newif\ifmpi at include\mpi at includefalse
 \newif\ifmpi at defglobal\mpi at defglobalfalse
+\newif\ifmpi at texdual\mpi at texdualfalse
 \newif\ifmpi at warnunused\mpi at warnunusedtrue
 \newif\ifmpi at beamer\mpi at beamertrue
 
@@ -126,6 +127,7 @@
 \newtoks\mpi at buf
 \newtoks\mpi at defbuf
 \newtoks\mpi at nowbuf
+\newtoks\mpi at verbbuf
 \mpi at defbuf={}
 
 \def\mpi at addto#1#2{\global#1=\expandafter{\the#1#2}}
@@ -133,6 +135,7 @@
 
 \def\mpi at clearbuf{\global\mpi at buf={}}
 \def\mpi at addbufexp#1{\mpi at addtoexp\mpi at buf{#1^^J}}
+\def\mpi at addbufbuf#1{\mpi at addtoexp\mpi at buf{\the#1}}
 \def\mpi at addbuf#1{{\protected at edef\mpi at tmp{#1}\mpi at addbufexp\mpi at tmp}}
 
 \def\mpi at stripext#1{\edef\mpi at tmp{#1}\expandafter%
@@ -173,9 +176,14 @@
 }
 \AtEndDocument{\expandafter\mpi at warnunused\mpi at unusedlist{}}
 
+\newcommand{\mpostdisplaylabel}[1]{{%
+  \catcode`\_=11\catcode`\^=11\catcode`\&=11%
+  \edef\mpi at tmp{#1}\expandafter\scantokens\expandafter{\mpi at tmp}}}
+
 \newcommand{\mpostplaceholder}[2][]{\parbox[c]{1in}{%
   \hrule\vrule\hfill%
-  \parbox[c]{0pt}{\rule{0cm}{0.6in}}\makebox[0pt][c]{\scriptsize\tt #2}%
+  \parbox[c]{0pt}{\rule{0cm}{0.6in}}%
+    \makebox[0pt][c]{\scriptsize\tt\mpostdisplaylabel{#2}}%
   \hfill\vrule\hrule}}
 
 \newcommand{\mpi at graphics}[2][]{%
@@ -189,7 +197,8 @@
   \@bsphack%
   \let\do\@makeother\dospecials%
   \catcode`\^^M\active%
-  \def\verbatim at processline{\mpi at addbufexp{\the\verbatim at line}}%
+  \global\mpi at verbbuf={}%
+  \def\verbatim at processline{\mpi at addtoexp\mpi at verbbuf{\the\verbatim at line^^J}}%
   \verbatim at start%
 }
 
@@ -198,6 +207,19 @@
   \endgroup%
 }
 
+\def\mpi at scanblock#1{%
+  \@ifnextchar\par{\mpi at scanblock@par{#1}}{\mpi at scanblock@sel{#1}}}
+\long\def\mpi at scanblock@par#1\par{\mpi at scanblock@sel{#1}[]}
+\def\mpi at scanblock@sel#1{\@ifnextchar[{\mpi at scanblock@opt{#1}}%
+  {\@ifnextchar\end{\mpi at scanblock@end{#1}}{\mpi at scanblock@noopt{#1}}}}
+\def\mpi at scanblock@end#1\end#2{%
+  \def\mpi at tmp{#2}\ifx\mpi at tmp\@currenvir%
+    \def\mpi at verbatim{\global\mpi at verbbuf={}}\def\mpi at endverbatim{}%
+  \fi%
+  #1{}{\scantokens{\end{#2}}}}
+\def\mpi at scanblock@noopt#1#2{#1{}{\scantokens#2}}
+\def\mpi at scanblock@opt#1[#2]{#1{#2}{}}
+
 \newcommand{\mpi at putlineno}{%
   \ifmpi at lineno%
     \mpi at addbuf{\@percentchar---------------------------------------}%
@@ -274,7 +296,7 @@
   \mpi at addbuf{\@percentchar generated from file `\jobname' by mpostinl.sty}%
   \ifmpi at include\else%
     \mpi at composehead%
-    \mpi at addbufexp{\the\mpi at defbuf}%
+    \mpi at addbufbuf{\mpi at defbuf}%
   \fi%
 }
 
@@ -397,7 +419,8 @@
     \fi%
     \ifmpi at include\ifmpi at filemod\global\mpi at inclmodtrue\fi\fi%
     \ifmpi at filemod\ifmpi at inbody%
-      \ifmpi at clean\expandafter\mpi at cleanfiles\mpi at filelist{}\fi%
+      \ifmpi at clean\ifmpi at write\ifmpi at compile%
+        \expandafter\mpi at cleanfiles\mpi at filelist{}\fi\fi\fi%
       \mpi at compile{\mpostfilename.mp}%
     \fi\fi%
     \ifmpi at filemod\ifmpi at showinfile\global\mpi at warnmodtrue\fi\fi%
@@ -441,7 +464,8 @@
 \define at key{mpi at def}{tex}[true]{\csname mpi at deftex#1\endcsname}
 \define at key{mpi at def}{global}[true]{\csname mpi at defglobal#1\endcsname}
 
-\newenvironment{mpostdef}[1][]{%
+\def\mpostdef{\mpi at scanblock{\mpi at mpostdef}}
+\def\mpi at mpostdef#1#2{%
   \mpi at deftexfalse%
   \setkeys{mpi at def}{#1}%
   \ifmpi at defglobal\else\ifmpi at deftex\ifmpi at include%
@@ -457,10 +481,12 @@
   \ifmpi at deftex%
     \mpi at addbuf{verbatimtex}%
   \fi%
-  \mpi at verbatim%
+  \mpi at verbatim#2%
 }
+\def\endmpostdef
 {%
   \mpi at endverbatim%
+  \mpi at addbufbuf{\mpi at verbbuf}%
   \ifmpi at deftex%
     \mpi at addbuf{etex}%
   \fi%
@@ -476,6 +502,50 @@
   \fi%
 }
 
+\newif\ifmpi at deftex
+\define at key{mpi at tex}{dual}[true]{\csname mpi at texdual#1\endcsname}
+\define at key{mpi at tex}{global}[true]{\csname mpi at defglobal#1\endcsname}
+
+\def\mposttex{\mpi at scanblock{\mpi at mposttex}}
+\def\mpi at mposttex#1#2{%
+  \mpi at texdualfalse%
+  \setkeys{mpi at tex}{#1}%
+  \ifmpi at defglobal\else\ifmpi at include%
+    \PackageWarning{mpostinl}{tex definitions within an include file %
+      will be ignored by mpost; switching to global definition}{}%
+    \mpi at defglobaltrue%
+  \fi\fi%
+  \ifmpi at defglobal\else%
+    \mpi at startfile%
+  \fi%
+  \mpi at clearbuf%
+  \mpi at putlineno%
+  \mpi at addbuf{verbatimtex}%
+  \mpi at verbatim#2%
+}
+\def\endmposttex
+{%
+  \mpi at endverbatim%
+  \mpi at addbufbuf{\mpi at verbbuf}%
+  \mpi at addbuf{etex}%
+  \ifmpi at defglobal%
+    \mpi at addtoexp\mpi at defbuf{\the\mpi at buf^^J}%
+    \ifmpi at include\else\ifmpi at infile%
+      \mpi at writebuf%
+      \mpi at writenow%
+    \fi\fi%
+  \else%
+    \mpi at writebuf%
+    \ifmpi at include\else\mpi at writenow\fi%
+  \fi%
+  \ifmpi at texdual%
+    \ignorespacesafterend%
+    \global\let\mpi at ignorespaces\ignorespaces%
+    \gdef\ignorespaces{\expandafter\scantokens\expandafter{\the\mpi at verbbuf}%
+      \global\let\ignorespaces\mpi at ignorespaces}%
+  \fi%
+}
+
 \newif\ifmpi at figshow
 \define at key{mpi at fig}{show}[true]{\csname mpi at figshow#1\endcsname}
 \define at key{mpi at fig}{twice}[true]{\csname mpi at twice#1\endcsname}
@@ -484,7 +554,8 @@
 \define at key{mpi at fig}{opt}{\def\mpi at figopt{[#1]}}
 \define at key{mpi at fig}{now}[true]{\csname mpi at now#1\endcsname}
 
-\newenvironment{mpostfig}[1][]{%
+\def\mpostfig{\mpi at scanblock{\mpi at mpostfig}}
+\def\mpi at mpostfig#1#2{%
   \ifmpi at include%
     \PackageError{mpostinl}{cannot write figure to include file}{}%
   \fi%
@@ -515,10 +586,12 @@
   \mpi at clearbuf%
   \mpi at putlineno%
   \mpi at beginfig{\mpi at figfile}%
-  \mpi at verbatim%
+  \mpi at verbatim#2%
 }
+\def\endmpostfig
 {%
   \mpi at endverbatim%
+  \mpi at addbufbuf{\mpi at verbbuf}%
   \mpi at endfig%
   \mpi at writebuf%
   \xdef\mpi at filelist{\mpi at filelist{\mpi at figfile}}%



More information about the tex-live-commits mailing list