ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Disable reuse of figures
@ 2022-02-19  6:30 Aditya Mahajan via ntg-context
  2022-02-19 10:26 ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 3+ messages in thread
From: Aditya Mahajan via ntg-context @ 2022-02-19  6:30 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Aditya Mahajan

Hi,

This is related to a bug report for the filter module:
https://github.com/adityam/filter/issues/60

Normally, when the same figure is included twice, context only includes the figure once and refers to the included figure the second time. The option `object=no` to externalfigure is supposed to prevent that, but it doesn't work. For example, consider the following example the bug-report uses graphviz as the external program, but I have changed that to context to keep things self contained)

\usemodule[filter]

\defineexternalfilter
  [graphviz]
  [
    filter=context --purge,
    output=\externalfilterbasefile.pdf,
    readcommand=\ReadPDF,
  ]

\def\ReadPDF#1%
    {\externalfigure[#1][object=no]}

\starttext

  Circle:
  \startgraphviz
    \startMPpage
      draw fullcircle scaled 1cm;
    \stopMPpage
  \stopgraphviz

  Square:
  \startgraphviz
    \startMPpage
      draw fullsquare scaled 1cm;
    \stopMPpage
  \stopgraphviz

\stoptext

Behind the scenes, the first \startgraphviz ... \stopgraphviz environment writes the content to an external file (\jobname-temp-graphviz.tmp), runs `context --purge \jobname-temp-graphviz.tmp`, which creates `\jobname-temp-graphviz.pdf`. The `\ReadPDF` macro then includees the file (with object=no).

At the next \startgraphviz .. \stopgraphviz, the same process is repeated. The `\jobname-temp-graphviz.pdf` file is overwritten and the new file should have been included. But it is not. The output contains the first image twice. 

I thought that object=no should have prevented the reuse. In fact, if I compile the file with luatex, I get an error message:

! error:  (pdf inclusion): file has changed '12-two-outputs-temp-graphviz.pdf'
mtx-context     | fatal error: return code: 256

Any idea why object=no is not working?

Thanks,
Aditya





___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Disable reuse of figures
  2022-02-19  6:30 Disable reuse of figures Aditya Mahajan via ntg-context
@ 2022-02-19 10:26 ` Hans Hagen via ntg-context
  2022-02-21  9:47   ` Aditya Mahajan via ntg-context
  0 siblings, 1 reply; 3+ messages in thread
From: Hans Hagen via ntg-context @ 2022-02-19 10:26 UTC (permalink / raw)
  To: Aditya Mahajan via ntg-context; +Cc: Hans Hagen

On 2/19/2022 7:30 AM, Aditya Mahajan via ntg-context wrote:
> Hi,
> 
> This is related to a bug report for the filter module:
> https://github.com/adityam/filter/issues/60
> 
> Normally, when the same figure is included twice, context only includes the figure once and refers to the included figure the second time. The option `object=no` to externalfigure is supposed to prevent that, but it doesn't work. For example, consider the following example the bug-report uses graphviz as the external program, but I have changed that to context to keep things self contained)
> 
> \usemodule[filter]
> 
> \defineexternalfilter
>    [graphviz]
>    [
>      filter=context --purge,
>      output=\externalfilterbasefile.pdf,
>      readcommand=\ReadPDF,
>    ]
> 
> \def\ReadPDF#1%
>      {\externalfigure[#1][object=no]}
> 
> \starttext
> 
>    Circle:
>    \startgraphviz
>      \startMPpage
>        draw fullcircle scaled 1cm;
>      \stopMPpage
>    \stopgraphviz
> 
>    Square:
>    \startgraphviz
>      \startMPpage
>        draw fullsquare scaled 1cm;
>      \stopMPpage
>    \stopgraphviz
> 
> \stoptext
> 
> Behind the scenes, the first \startgraphviz ... \stopgraphviz environment writes the content to an external file (\jobname-temp-graphviz.tmp), runs `context --purge \jobname-temp-graphviz.tmp`, which creates `\jobname-temp-graphviz.pdf`. The `\ReadPDF` macro then includees the file (with object=no).
> 
> At the next \startgraphviz .. \stopgraphviz, the same process is repeated. The `\jobname-temp-graphviz.pdf` file is overwritten and the new file should have been included. But it is not. The output contains the first image twice.
> 
> I thought that object=no should have prevented the reuse. In fact, if I compile the file with luatex, I get an error message:
> 
> ! error:  (pdf inclusion): file has changed '12-two-outputs-temp-graphviz.pdf'
> mtx-context     | fatal error: return code: 256
> 
> Any idea why object=no is not working?
the pdf file is kept open, for various reasons:

- performance
- the might be different pages to fetch
- analysis happens when the image is placed, inclusion happens later

so you try to reopen an already open file (which has not been completely 
processed)

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Disable reuse of figures
  2022-02-19 10:26 ` Hans Hagen via ntg-context
@ 2022-02-21  9:47   ` Aditya Mahajan via ntg-context
  0 siblings, 0 replies; 3+ messages in thread
From: Aditya Mahajan via ntg-context @ 2022-02-21  9:47 UTC (permalink / raw)
  To: Hans Hagen via ntg-context; +Cc: Aditya Mahajan

On Sat, 19 Feb 2022, Hans Hagen via ntg-context wrote:

> On 2/19/2022 7:30 AM, Aditya Mahajan via ntg-context wrote:
> > Hi,
> > 
> > This is related to a bug report for the filter module:
> > https://github.com/adityam/filter/issues/60
> > 
> > Normally, when the same figure is included twice, context only includes the
> figure once and refers to the included figure the second time. The option
> `object=no` to externalfigure is supposed to prevent that, but it doesn't
> work. For example, consider the following example the bug-report uses graphviz
> as the external program, but I have changed that to context to keep things
> self contained)
> > 
> > \usemodule[filter]
> > 
> > \defineexternalfilter
> >    [graphviz]
> >    [
> >      filter=context --purge,
> >      output=\externalfilterbasefile.pdf,
> >      readcommand=\ReadPDF,
> >    ]
> > 
> > \def\ReadPDF#1%
> >      {\externalfigure[#1][object=no]}
> > 
> > \starttext
> > 
> >    Circle:
> >    \startgraphviz
> >      \startMPpage
> >        draw fullcircle scaled 1cm;
> >      \stopMPpage
> >    \stopgraphviz
> > 
> >    Square:
> >    \startgraphviz
> >      \startMPpage
> >        draw fullsquare scaled 1cm;
> >      \stopMPpage
> >    \stopgraphviz
> > 
> > \stoptext
> > 
> > Behind the scenes, the first \startgraphviz ... \stopgraphviz environment
> writes the content to an external file (\jobname-temp-graphviz.tmp), runs
> `context --purge \jobname-temp-graphviz.tmp`, which creates
> `\jobname-temp-graphviz.pdf`. The `\ReadPDF` macro then includees the file
> (with object=no).
> > 
> > At the next \startgraphviz .. \stopgraphviz, the same process is repeated.
> The `\jobname-temp-graphviz.pdf` file is overwritten and the new file should
> have been included. But it is not. The output contains the first image twice.
> > 
> > I thought that object=no should have prevented the reuse. In fact, if I
> compile the file with luatex, I get an error message:
> > 
> > ! error:  (pdf inclusion): file has changed
> '12-two-outputs-temp-graphviz.pdf'
> > mtx-context     | fatal error: return code: 256
> > 
> > Any idea why object=no is not working?
> the pdf file is kept open, for various reasons:
> 
> - performance
> - the might be different pages to fetch
> - analysis happens when the image is placed, inclusion happens later
> 
> so you try to reopen an already open file (which has not been completely 
> processed)

I see. So, for the filter module this means that one always has to use `cache=yes` (so that each PDF file has a different name). I'll add that to the documentation. 

Thanks,
Aditya
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2022-02-21  9:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-19  6:30 Disable reuse of figures Aditya Mahajan via ntg-context
2022-02-19 10:26 ` Hans Hagen via ntg-context
2022-02-21  9:47   ` Aditya Mahajan via ntg-context

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