[metapost] mpost: list of all output file names

Laurent Méhats laurent.mehats at gmail.com
Thu Sep 26 16:46:48 CEST 2013


Le 07/09/2013 12:22, Peter Zeman a écrit :
> Hello.
>
> I'm writing a program, which needs to know the name of each output
> file produced from compiling a MetaPost soucre file.
>
> Is there a way to force 'mpost' to print all output file names and not
> just the name of the first one and the last one?
>
> Another option would be to collect all outputtemplates, create regular
> expression and search the directory, but I would like to avoid this if
> possible.
>
> Is there a way the get the list of all output file names?
>
> Thank you for your answers!
>
>    Peter Zeman
> --
> http://tug.org/metapost/
>

Hello,

You may use the "outputfilename" internal string, which is available since 
MetaPost version 1.800. Here is its description in the announcement.

What is new in MetaPost version 1.800:
* A new string-valued internal "outputfilename", which is set by
   "shipout" to the value of the just created file name. Until the
   first shipout has occurred, it is the empty string.

"shipout" is usually called by "shipit" which itself is called by 
"endfig". So you may add a command using "outputfilename" after each 
"endfig". Example:

--%<-- test1.mp
outputtemplate:="%j-%c.mps";

for idx=0 upto 4:
   beginfig(idx)
   draw origin;
   endfig;
   message outputfilename;
endfor

end;
--%<-- test1.mp

Both "endfig" and "shipit" are defined in plain.mp:

def shipit = shipout currentpicture enddef;

def endfig =
   scantokens extra_endfig;
   shipit;
   endgroup
enddef;

So you may also redefine "shipit" or "endfig" to take "outputfilename" 
into account. Example:

--%<-- test2.mp
outputtemplate:="%j-%c.mps";

def shipit =
   shipout currentpicture;
   message outputfilename;
enddef;

for idx=0 upto 4:
   beginfig(idx)
   draw origin;
   endfig;
endfor

end;
--%<-- test2.mp

Then to get a list of all output file names, you may redefine "shipit" to 
build it or to write it to a file. Example:

--%<-- test3.mp
outputtemplate:="%j-%c.mps";

string list, listfile;
list:="";
listfile:="list.txt";

def shipit =
   shipout currentpicture;
   list:=list&outputfilename&" ";
   write outputfilename to listfile;
enddef;

for idx=0 upto 4:
   beginfig(idx)
   draw origin;
   endfig;
endfor

message list;

end;
--%<-- test3.mp

Regards,
Laurent Méhats



More information about the metapost mailing list