# Unwanted space after figure environment

When the figure environment directly follows a $...$ environment an unwanted space occurs in the output. It obviously seems to be an endlinechar which is changed into a space.

\documentclass{article}
\begin{document}
$a = b.$
\begin{figure}
figure
\end{figure}
Text\\
Text

$a = b.$
\begin{figure}
figure
\end{figure}%
Text\\
Text

\end{document}


I know I can get rid of this adding a % after \end{figure} or generally by adding \ignorespaces to the figure environment with etoolbox's \AfterEndEnvironment.

My question is: is this a bug or expected behaviour? And if it is a bug who do I send a report?

EDIT: It seems my example was not really a minimal one. As it turns out the display environment is not necessary to get the space:

\documentclass{article}
\begin{document}
a%
\begin{figure}
\caption{A}
\end{figure}
b

and

c\\
d%
\begin{figure}
\caption{B}
\end{figure}
e

vs.

f%
\begin{figure}
\caption{C}
\end{figure}%
g

\end{document}


In case I didn't make it clear enough: I am not interested in a way to avoid the space -- I know already how to do that. I admit that such information might be useful for other readers, though.

I rather want to know if this behaviour is to be expected of the figure environment or a bug?

-
In your example both figures are located at the top of the page. – Marco Daniel Jan 14 '12 at 17:53
I know but that seems not to be the point, or am I wrong? – clemens Jan 14 '12 at 17:59
As I explained, \begin{figure} eats a space before it (if there is), but \end{figure} doesn't eat a space after it. In cases (ab) and (de) there's a space after \end{figure}; in case (fg) there isn't. – egreg Jan 15 '12 at 22:23
@egreg so you're saying this is expected (and wanted?) benahviour? Is that for a purpose? – clemens Jan 15 '12 at 23:04
It's expected; you just insert a figure environment and don't worry about spaces. Just don't put them after displayed equations and, as I said, it's usually better to put them between paragraphs. – egreg Jan 16 '12 at 0:37

Inserting the figure environment there is not the best idea. For example, even if you say \begin{figure}[htp] and the h option can be honored, the figure will not be printed just after the display.
A figure environment inserted in the mid of a paragraph cancels the space before it, rather than ignoring spaces after it. But in that case it has nothing to cancel out.
I always put my figure and table environment between paragraphs.
If you want to show a picture representing what's in the displayed formula, it's better to put the figure (not in a figure environment) inside the display: the environments available with amsmath allow for multiline displays.