adityam / filter

ConTeXt module to process contents of a start-stop environment through an external program
45 stars 10 forks source link

Using filter twice gives same replaced output #60

Closed MichaelEwe closed 2 years ago

MichaelEwe commented 2 years ago

Versions:

ConTeXt ver: 2022.01.21 20:13 LMTX fmt: 2022.2.16 int: english/english t-filter (ver: 2022.02.17)

Use case

Using the same filter twice with different content.

Expected Result

In the produced output both filters are "replaced" with their corresponding content.

Observed Result

Both filters are indeed "replaced". But the replaced content is coming from the first filter invocation.

How To Reproduce

Use "dot.tex" from the test-cases in this repository as a starting point. Add a second invocation like in the code below. Both figures will appear, but the second one contains the dot-graph from the first filter invocation again.

\usemodule[filter]

\defineexternalfilter
  [graphviz]
  [
    filter=\externalfilterparameter{layout} -Tpdf -o\externalfilteroutputfile,
    layout=dot, % neato or twopi
    cache=yes,
    output=\externalfilterbasefile.pdf,
    readcommand=\ReadPDF,
  ]

\def\ReadPDF#1%
    {\externalfigure[#1][frame=on]}

\starttext

\startplacefigure[location=right]
  \startgraphviz
    digraph G {
        a_1-> a_2 -> a_3 -> a_1;
        }
  \stopgraphviz
\stopplacefigure
\input ward

% this is the second figure with (almost) the same graph

\startplacefigure[location=left]
  \startgraphviz
    digraph G {
        1_a-> 2_a ->3_a ->1_a;
        }
  \stopgraphviz
\stopplacefigure
\input ward

\stoptext
adityam commented 2 years ago

Works here and gives the attached output (Side remark: It has been a while since I used graphviz; but I think that 1_a is not being recognized as a variable. you may have to use "1_a" (with quotes) to get the right variable name.).

12-two-outputs.pdf

Not sure why it is failing at your end. Can you add \traceexternalfilters before \starttext and paste the complete terminal output.

MichaelEwe commented 2 years ago

I found a hint. It works on my side too, as long as I have "cache=yes" in the definition. Change it to "cache=no" and you get the error. (Remark: looks like I pasted the wrong file in the first place, sorry...)

The input below yields this output

dot.pdf

Thank you for your support. I can live with "cache=yes", but there seems to be an issue with caching...

Input with cache=no

\usemodule[filter]

\defineexternalfilter
  [graphviz]
  [
    filter=\externalfilterparameter{layout} -Tpdf -o\externalfilteroutputfile,
    layout=dot, % neato or twopi
    cache=no,
    output=\externalfilterbasefile.pdf,
    readcommand=\ReadPDF,
  ]

\def\ReadPDF#1%
    {\externalfigure[#1][frame=on]}

\starttext

\startplacefigure[location=right]
  \startgraphviz
    digraph G {
        Peter -> Paul;
        }
  \stopgraphviz
\stopplacefigure
\input ward

\startplacefigure[location=left]
  \startgraphviz
    digraph G {
        Paul -> Mary;
        }
  \stopgraphviz
\stopplacefigure
\input ward

\stoptext
adityam commented 2 years ago

I added some explanation in the README to explain why cache=yes is necessary.

MichaelEwe commented 2 years ago

Splendid. Again thank you for your support!