[metapost] Question: [MPLib, MetaFun, ConTeXt, LuaTeX] metapost logging and message primitive?
Aditya Mahajan
adityam at umich.edu
Wed Feb 20 10:46:51 CET 2013
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" primitive.
>
> 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
\disabledirectives[mplib.texerrors]
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:
\startluacode
local report_metapost = logs.reporter("metapost")
local texerrormessage = logs.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)
end
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)
end
else
report_metapost("error: unknown, no error, terminal or log
messages")
end
else
return false
end
return true
end
\stopluacode
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.
Aditya
More information about the metapost
mailing list