ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* luaTeX and on-the-fly MetaPost compilation
@ 2008-05-23 21:28 Stephan Hennig
  2008-05-24  7:28 ` Taco Hoekwater
  2008-05-24  7:30 ` Hans Hagen
  0 siblings, 2 replies; 7+ messages in thread
From: Stephan Hennig @ 2008-05-23 21:28 UTC (permalink / raw)
  To: ntg-context

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?

Rationale:  I do not want to mix TeX and MetaPost code.  Probably, I'll
stick with compiling .mp files prior to the TeX run anyway, but I'm
curious about this option.

Best regards,
Stephan Hennig

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: luaTeX and on-the-fly MetaPost compilation
  2008-05-23 21:28 luaTeX and on-the-fly MetaPost compilation Stephan Hennig
@ 2008-05-24  7:28 ` Taco Hoekwater
  2008-05-24  7:30 ` Hans Hagen
  1 sibling, 0 replies; 7+ messages in thread
From: Taco Hoekwater @ 2008-05-24  7:28 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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}

In principle something like that is possible, but it needs an extension
to the current system, because you have to filter out the specific
figure you really want, and I don't think Hans has code for that already
(but I could be wrong).

Best wishes,
Taco
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: luaTeX and on-the-fly MetaPost compilation
  2008-05-23 21:28 luaTeX and on-the-fly MetaPost compilation Stephan Hennig
  2008-05-24  7:28 ` Taco Hoekwater
@ 2008-05-24  7:30 ` Hans Hagen
  2008-05-24 10:49   ` Stephan Hennig
  1 sibling, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2008-05-24  7:30 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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 : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: luaTeX and on-the-fly MetaPost compilation
  2008-05-24  7:30 ` Hans Hagen
@ 2008-05-24 10:49   ` Stephan Hennig
  2008-05-24 13:21     ` Taco Hoekwater
  2008-05-24 16:54     ` Hans Hagen
  0 siblings, 2 replies; 7+ messages in thread
From: Stephan Hennig @ 2008-05-24 10:49 UTC (permalink / raw)
  To: ntg-context

Hans Hagen schrieb:

> 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)

Thank you for the outline.  For the exact mechanism of how to process an
.mp file I think there are three possible cases:

1. Strictly process what's between figure(n)..endfig only.

For this example

pair pnt;
pnt:=origin;
beginfig(1);
  pnt:=(100,100);
  drawdot pnt;
endfig;
beginfig(2);
  drawdot pnt;
endfig;
end

compilation of figure 2 should fail, since variable pnt is undeclared.

2. Process everything up-to the specified figure, omitting stuff inside
non-matching figure numbers.  In the example above, the output of figure
2 should be a dot at point (0,0).  This case is convenient if multiple
figures share common variables or macros that are defined outside the
scope of beginfig..endfig.  This should be the default case for .mp file
interpretation.

3. Process everything up-to the specified figure, including all
non-matching figures, but discard their output.  That is, in the
example, the output of figure 2 should be a dot at point (100,100),
since pnt was modified in figure 1.

Note, this is not a pressing feature for me.  The advantage is that
MetaPost and TeX code can be held in separate files (which has several
advantages) and users can easily compile the code in a single TeX run,
without knowing about Makefiles.  Well, there is the \write18 feature.
But that is as difficult to use as a Makefile or even more difficult for
the inexperienced user.

Best regards,
Stephan Hennig

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: luaTeX and on-the-fly MetaPost compilation
  2008-05-24 10:49   ` Stephan Hennig
@ 2008-05-24 13:21     ` Taco Hoekwater
  2008-05-24 13:25       ` Taco Hoekwater
  2008-05-24 16:54     ` Hans Hagen
  1 sibling, 1 reply; 7+ messages in thread
From: Taco Hoekwater @ 2008-05-24 13:21 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Stephan Hennig wrote:
> Thank you for the outline.  For the exact mechanism of how to process an
> .mp file I think there are three possible cases:
> 
> 1. Strictly process what's between figure(n)..endfig only.
> 
> 2. Process everything up-to the specified figure, omitting stuff inside
> non-matching figure numbers.  
> 
> 3. Process everything up-to the specified figure, including all
> non-matching figures, but discard their output.  

4. Start a new MP instance, process the whole file, save and remember
the outputs (store fig.1, fig.2, fig.3 etc), then immediately close
the MP instance again.

The advantage is that this makes the metapost input behave exactly the
same as a true external figure, something that is not possible when an
already running MP instance is re-used. This is important, because the
state of an already running instance can be altered in such a way that
a perfectly valid metapost source suddenly fails to run. That may happen
with embedded metapost code as well of course, but in that case it is
much easier to correct and diagnose the problem.

Best wishes,
Taco
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: luaTeX and on-the-fly MetaPost compilation
  2008-05-24 13:21     ` Taco Hoekwater
@ 2008-05-24 13:25       ` Taco Hoekwater
  0 siblings, 0 replies; 7+ messages in thread
From: Taco Hoekwater @ 2008-05-24 13:25 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Taco Hoekwater wrote:
>                                                    it is
> much easier to correct and diagnose the problem.

Although these actions are usually done in reverse order ;-)

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: luaTeX and on-the-fly MetaPost compilation
  2008-05-24 10:49   ` Stephan Hennig
  2008-05-24 13:21     ` Taco Hoekwater
@ 2008-05-24 16:54     ` Hans Hagen
  1 sibling, 0 replies; 7+ messages in thread
From: Hans Hagen @ 2008-05-24 16:54 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Stephan Hennig wrote:

> Note, this is not a pressing feature for me.  The advantage is that
> MetaPost and TeX code can be held in separate files (which has several
> advantages) and users can easily compile the code in a single TeX run,
> without knowing about Makefiles.  Well, there is the \write18 feature.
> But that is as difficult to use as a Makefile or even more difficult for
> the inexperienced user.

i'll put it on my todo list (let me know if it gets pressing -)



-----------------------------------------------------------------
                                           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 : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-05-24 16:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-23 21:28 luaTeX and on-the-fly MetaPost compilation Stephan Hennig
2008-05-24  7:28 ` Taco Hoekwater
2008-05-24  7:30 ` Hans Hagen
2008-05-24 10:49   ` Stephan Hennig
2008-05-24 13:21     ` Taco Hoekwater
2008-05-24 13:25       ` Taco Hoekwater
2008-05-24 16:54     ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).