Stephan Hennig wrote:
> Hi,
> 
> I didn't have the opportunity to touch luaTeX yet, but let me ask one
> question in advance:  Since luaTeX has a built-in MetaPost interpreter,
> is it possible to refer to a certain figure in a MetaPost source file
> for inclusion, instead of a compiled figure?
> 
> As an example, I would like to say in a TeX document (syntax may differ)
> 
>   \includeMetaPost{foo.2}
> 
> and this should not refer to the pre-compiled file
> 
>   foo.2
> 
> but to section
> 
>   figure(2);
>     ...
>   endfig;
> 
> in file
> 
>   foo.mp
> 
> and compile it on-the-fly.  Would that be possible?

mplib is still just mp so it ptocessed what is passed to it; no 
intelligence is added to the mp kernel

however, when using the lib ons is in control over what is passed to it

in the past i did what you describe in metafun by using just a macro 
(loadfigure) which filters the image from a file;

in luatex we can be more clever (i admit that i hadn;t yet thought of 
replacing the macro -)

using lua we get something ...

function filterfromMPblob(data,number)
     return 
(data:match(string.format("beginfig%%(%s%%).-endfig",number)) or "") .. " ;"
end

test this with:

str = [[
beginfig(1)
     draw fullcircle ;
endfig ;
beginfig(2)
     draw fullcircle ;
endfig ;
]]

print(filterfromMPblob(str,2))

glue to tex:

\def\includeMetaPost#1#2% io.loaddata is part of l-io.lua
   {\directlua0{tex.print(filterfromMPblob(io.loaddata("#1",#2)))}}

of course this need to be embeded in some general mp support

(i'll add it to my todolist; actually a bit more is involved since one 
probably wants to include the data between the figures too since it may 
be called upon)




-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : [email protected] / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to