## LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

 Options: Use Forum View Use Monospaced Font Show HTML Part by Default Show All Mail Headers Message: [<< First] [< Prev] [Next >] [Last >>] Topic: [<< First] [< Prev] [Next >] [Last >>] Author: [<< First] [< Prev] [Next >] [Last >>]

I just had a look into the following question on TeX.sx:

http://tex.stackexchange.com/questions/40330/centered-captions-containing-vref-may-not-always-appear-as-expected

The issue here is the following code:

\long\def\@makecaption#1#2{%
\vskip\abovecaptionskip
\sbox\@tempboxa{#1: #2}%
\ifdim \wd\@tempboxa >\hsize
#1: #2\par
\else
\global \@minipagefalse
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
\fi
\vskip\belowcaptionskip}

The problem is that this code trial typesets the caption as
\sbox\@tempboxa{#1: #2} but then is not using it if the line is getting
to long but instead uses  #1: #2\par. If however the line is short
enough it reuses the box.

There are some reason for doing this (I mean not reusing the box in the
multi-line version) as this has other deficiencies, but together with
varioref this produces a problem. The problem being that varioref
internally increments some counters to add label names and those are
then never written to the aux file with bad results (basically a \vref
may pick up the wrong information)

I wonder if this isn't a more general issue which needs addressing by
providing some  "trial area" where you can go

\trial_start:
... do the trial
\trial_end:

where changes to counters dimensions etc are being stored away and
returned back to their previous values afterwards.

what you would need then is a way to flag certain variables for this
trial usage so that they can be properly saved and restored.

I think I remember that Michael Downes at one time wrote code for this
for amsmath to manage labels and the like appearing in places like
\mathchoice or in environments that do several trial typesettings to
determine placement.

A brute force solution (but most certainly wrong with more complication
structures in the caption) would be

\long\def\@makecaption#1#2{%
\vskip\abovecaptionskip
\sbox\@tempboxa{\globaldefs=-1\relax #1: #2}%
\ifdim \wd\@tempboxa >\hsize
#1: #2\par
\else
\global \@minipagefalse
\hb@xt@\hsize{\hfil #1: #2\hfil}%
\fi
\vskip\belowcaptionskip}

ie make all mods local in the trial and then retypeset the whole thing
in both cases. But it is not difficult to see who this dies a different
death depending on input.

Anybody some good ideas how to address topic this in a general fashion?

frank