Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In floating environments such as the captions of figures, LaTeX has a \global\@minipagefalse, why is this necessary and what does this switch do?

\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}
share|improve this question
add comment

2 Answers

up vote 10 down vote accepted

The @minipage switch is used by LaTeX to handle vertical spacing at the beginning of a minipage environment (or a similar construct). If it is true then \addvspace is not adding space. So if, for example, a minipage starts of with a list environment then the space normally added in front of the list (by \addvspace) is suppressed.

The switch will be set to true at the beginning of a minipage environment (or a similar construct) and is normally set to false by \everypar, i.e., the moment textual material appears in that "minipage".

Now in the case of the caption implementation, two different strategies are used: if the caption is wider than the current horizontal width, then it is re-set as a normal paragraph (so the switch would be set to false by \everypar). However is it is small then the box is used directly without triggering the paragraph builder. Therefore one has to set the switch manually in this case.

And the reason that it is done globally is just because the switch is always manipulated globally.

share|improve this answer
add comment

The sources say

The float mechanism, like minipage, sets the flag |@minipage| true
before executing the user-supplied text. Many \LaTeX\ constructs
test for this flag and do not add vertical space when it is true.
The intention is that this emulates \TeX's `top of page' behaviour.
The flag must be set false at the start of the first paragraph. This
is achieved by a redefinition of |\everypar|, but the call to
|\@parboxrestore| removes that redefinition, so it is re-inserted 
if needed. If the flag is already false then the |\caption| was not
the first entry in the float, and so some other paragraph has already
activated the special |\everypar|. In this case no further action is
needed.

The most important command that tests this switch is \addvspace which is the command that is mostly used to add the vertical space around display environments such as lists. It is a global flag and setting it in a float environment means the float acts in a consistent way even if it floats from somewhere where it is set to somewhere where it would not be set.

share|improve this answer
    
This much I could gather from the source2e, but shouldn't it then be outside the conditional? Why only at the hboxed caption? –  Yiannis Lazarides Apr 29 '12 at 19:52
    
@YiannisLazarides Frank just answered the point about caption in his answer –  David Carlisle Apr 29 '12 at 19:54
    
@Yiannis I think David's last part of the answer is a red herring. The switch takes care of itself and it only has to be set by \caption because of the caption implementation avoiding normal paragraphs. It is not doing a standardization which happens elsewhere. –  Frank Mittelbach Apr 29 '12 at 19:59
    
Hmm if in doubt I'd believe @FrankMittelbach, rather than me:-) But I wasn't so much thinking about caption there, as arbitrary addvspace at the top of the float. If the switch wasn't set by the float addvspace would pick up whatever value was current at the point of the float, wouldn't it? Ah we are agreeing. I think. the start of the float is the "elsewhere" that Frank meant:-) –  David Carlisle Apr 29 '12 at 20:04
    
indeed :-) the elsewhere is \@floatboxreset which sets the switch. And by the way if the caption is at the bottom of the float then it is correct if `\addvspace adds space. –  Frank Mittelbach Apr 29 '12 at 20:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.