When is leading/opening whitespace of a line in a tex file important?

The check program is clearly being over cautious (ie wrong) to say page breaks can always happen at spaces before \label.

However the form you give is not optimal,. but for a different reason: If you put the \label after the caption (whether or not you leave a blank space or newline before it) the vertical space is adversely affected.

Consider

enter image description here

\documentclass{article}

\setlength\belowcaptionskip{10pt}
\begin{document}

\begin{figure}[h]
  \caption{ay\label{a}}%
  \begin{center}
    x
  \end{center}
\end{figure}
\begin{figure}[h]
  \caption{ay}\label{b}
  \begin{center}
    x
  \end{center}
\end{figure}

\end{document}

The first form has visibly less space between the caption and the centred text as the space from center is merged with the space already added by the caption. However in the second version the \write node from \label prevents the center environment from detecting the vertical space already added so it adds its full amount of space.

(Note the first example posted here was completely wrong as explained in the other answer. The example above has been added after the original posting.)


If no special setting to spaces is active (essentially, we're not in verbatim mode), spaces at the beginning of a line are ignored. If chktex complains, it's for nothing, in this case.

Actually, the program is generally wrong in warning about spaces before \label or \index, because their definition starts with \@bsphack, whose duty is to check whether horizontal glue precedes it and, in this case, remember it and suppress it; the next \@esphack command will insert the remembered the space (after the label or index entry) and ignore subsequent spaces.

Here's an example

\documentclass{article}

\begin{document}

Here is an example of a ``misplaced label'' \label{mispl} according
to \texttt{chktex}.

Here is an example of a ``misplaced label'' according
to \texttt{chktex}.

\end{document}

with the output by chktex

ChkTeX v1.7.4 - Copyright 1995-96 Jens T. Berger Thielemann.
Compiled with POSIX extended regex support.
Warning 24 in splab.tex line 5: Delete this space to maintain correct pagereferences.
Here is an example of a ``misplaced label'' \label{mispl} according  
                                           ^
No errors printed; One warning printed; No user suppressed warnings; No line suppressed warnings.
See the manual for how to suppress some or all of these warnings/errors.

However, it is apparent that the typesetting is correct:

enter image description here

Note that your example can be simplified: there's no need for %.

\begin{figure}
  \centering
  \includegraphics{file}
  \caption{Caption text}
  \label{whatever}
\end{figure}

This is because \caption starts and ends with a \par, so \label is processed in vertical mode. The end-of-line after the \includegraphics will be suppressed by \par and \label is processed in vertical mode, where spaces do nothing.

My personal preference goes to

\begin{figure}
\centering

\includegraphics{file}

\caption{Caption text}
\label{whatever}

\end{figure}

I generally prefer blank lines to indentation, that makes clearer the distinction between various parts of the input. However it's just my style.