[metapost] Question: [MPLib, MetaFun, ConTeXt, LuaTeX] metapost logging and message primitive?

Colin Fraizer metapost at cfraizer.com
Tue Feb 26 07:39:31 CET 2013

Aditya, thank you for your kind response. I fear I did not completely
understand it, being Lua-illiterate.

My problem (this is mostly contextual information):
1. I have a METAPOST program of modest complexity that runs fine with
   regular mpost version 1.504 (from TeXLive 2012).
2. I would like to use ConTeXt to generate both my figures and my
   document. (Two reasons: I'd prefer a single source file and I would
   like to be able to use OpenType fonts in my labels.)
3. When run within ConTeXt, my document fails to generate the correct
   figure.  I suspect this is because of the "extrapass" mechanism,
   but it is difficult to tell for sure without being able to see the
   METAPOST logging.
4. When running with TeXLive 2012's ConTeXt, "loggingall;" didn't
5. I installed stand-alone ConTeXt which improved some things, but
   generated only blank figures when "loggingall;" or "tracingall;
   tracingonline:=0;" was added to the METAPOST.  If
   "tracingonline:=1;" is added, then the figures contain the
   appropriate graphics. Most importantly, the log files and the
   screen show all the METAPOST info I need.

BOTTOM LINE (i.e., the problem I currently face):
When "tracingonline:=1;", the program runs unbearable slower! A run
that takes 20 seconds in stand-alone METAPOST takes more than AN HOUR
in ConTeXt. I believe much of this is related to I/O and occurs even
when the STDOUT is redirected to /dev/null (CygWin) or NUL: (Windows
CMD equivalent).

Does anyone know of a way to:
1. make ConTeXt/MPLIB *not* generate blank figures when "loggingall;"
   is used; AND/OR
2. make "tracingall;" not take *forever*?

-----Original Message-----
From: Aditya Mahajan [mailto:adityam at umich.edu] 
Sent: Wednesday, February 20, 2013 4:47 AM
To: Colin Fraizer
Cc: MetaPost List
Subject: Re: [metapost] Question: [MPLib, MetaFun, ConTeXt, LuaTeX] metapost
logging and message primitive?

On Mon, 18 Feb 2013, Colin Fraizer wrote:

> I have a METAPOST program that works fine with mpost, but fails when I 
> try to run it inline in ConTeXt. In order to debug it, I would like to 
> see the usual METAPOST logging and/or to use the METAPOST "message"
> However, whenever I add "loggingall;" or a message statement to my 
> ConTeXt file, I encounter errors like this
> %------
> metapost        > initializing instance 'metafun' using format 'metafun'
> metapost        > loading 'metafun':
> D:/texlive/2012/texmf-dist/metapost/context/base/metafun.mpiv
> ! terminal:
> %-------

You can get rid of the error message by setting


but that results in an equally useless:

metapost        > terminal:

metapost        > error: unknown, no error, terminal or log messages

The logic in metapost.reporterror(...) function in mlib-run.lua is a bit
weird. It assumes that metapost.texerrors is always set to false!

> What is the appropriate way to debug problems with inline METAPOST 
> code in ConTeXt?

I think that it is better to redefine metapost.reporterror as follows:


local report_metapost = logs.reporter("metapost") local texerrormessage =

-- metapost.showlog = true

function metapost.reporterror(result)
     if not result then
         report_metapost("error: no result object returned")
     elseif result.status > 0 then
         local t, e, l = result.term, result.error, result.log
         if t and t ~= "" and metapost.showlog then
             report_metapost("terminal: %s",t)
         if e then
             (metapost.texerrors and texerrormessage or
report_metapost)("error: %s",(e=="" and "?") or e)
         elseif l then
             if metapost.showlog then
                 metapost.lastlog = metapost.lastlog .. "\n" .. l
                 report_metapost("log: %s",l)
             report_metapost("error: unknown, no error, terminal or log
         return false
     return true

That way, when you enable metapost.showlog and set loggingall at the
metapost end, the logging messages will be shown on the terminal as well in
the log file.


More information about the metapost mailing list