On Thu, Jun 04, 2015 at 07:25:25PM +0200, Enrico Forestieri wrote:

> On Thu, Jun 04, 2015 at 06:56:46PM +0200, Jürgen Spitzmüller wrote:
> > 2015-06-04 18:39 GMT+02:00 Enrico Forestieri <[email protected]>:
> > 
> > > Yes, I can reproduce in master. It does not occur in stable, where a
> > > different strategy is used, only involving the instant preview scripts.
> > > If I am not mistaken, it goes like this. When you enter and then leave
> > > a math inset, the generated preview snippet is compared with the cached
> > > ones. If it matches one of them, no further action is taken and the
> > > corresponding image is used. It is the way duplicated macros are avoided
> > > in master that causes this glitch, because the macro definitions are also
> > > cached. When the document is loaded, that snippet contains the macro
> > > definition because it was not appearing before. However, when you
> > > enter and then leave the math inset, the code thinks that the macro
> > > was already defined previously and does not include it anymore. Now the
> > > snippet does not match any of the cached ones because the macro is not
> > > there anymore. Hence, a new preview is attempted but it fails because of
> > > the missing macro definition.
> > >
> > > Fixing this requires a bit more work in master. First of all, the cached
> > > macros should be cleared after a preview cycle completed, such that next
> > > previews involving the same macro can succeed. However, given that the
> > > produced snippet would now be different from when it was generated the
> > > first time (no macro present at that time), the already cached image would
> > > not be used and a new one will be generated. This risks to be highly
> > > inefficient, of course, so something should be thought for avoiding it.
> > >
> > 
> > 
> > Yes, I had a closer look at this as well. I am not sure about a good and
> > efficient strategy. Maybe we should store for which insets definitions were
> > cached and remove them from the general cache if this inset is modified. I
> > do not yet have a brilliant idea, though.
> 
> What about the following strategy?
> 
> Always include the macro definition if it appears in the math inset and
> don't include it if its name is not there. To decide this, don't cache
> the whole macro but only its name. I mean, if the macro is defined by
> \global\long\def, include it as is. If not, check the cache for the
> name and accordingly use \newcommandx or \renewcommandx. When comparing
> cached snippets, treat \newcommandx and \renewcommandx as the same
> (maybe replacing \renew with \new before the comparison, or the way around).
> Or something like that...
> 
> Of course, the cache should be cleared, but that's should be easy.
> See attached.

Jürgen, this is going to become complicated and fragile. What about
following the same strategy used in stable?
This implies reverting bc47054b.

-- 
Enrico

Reply via email to