# Extra vertical spaces when $and$ are redefined as \begin{equation*} and \end{equation*} (ntheorem involved)

In this answer, it is advised to proceed to the following redefinition:

\DeclareRobustCommand{$}{\begin{equation*}} \DeclareRobustCommand{$}{\end{equation*}}


But, as pointed out by the following MCE, this leads to extra vertical spaces.

Do you see how to get rid of these extra spaces?

\documentclass[fleqn]{article}
\usepackage[step=1cm]{pagegrid}
\usepackage[margin=0pt,papersize=2.5cm]{geometry}
%
\usepackage{amsmath}
\usepackage[amsmath,fleqn,thmmarks]{ntheorem}
%
\newcommand{\test}{%
\noindent%
Foo
$a=a$
Bar
}
%
\begin{document}
\test
%
\DeclareRobustCommand{$}{\begin{equation*}}% \DeclareRobustCommand{$}{\end{equation*}}%
\newpage
\test
\end{document}


• I will remove my comments because I see only now your question is direct continuation of thread at tex.stackexchange.com/questions/402187/… which already mentions thmmarks features... – user4686 Nov 21 '17 at 16:15
• – John Kormylo Nov 22 '17 at 4:19
• No, the answer doesn't recommend to do that redefinition. It actually recommends not using thmmarks. – egreg Jun 18 '18 at 12:38
• @egreg Okay, this answer gave that redefinition as a workaround, sorry :) – Denis Bitouzé Jun 18 '18 at 13:34

In the first instance the spacing before and after is provided by \topsep (from a trivlist), whereas in the amsmath case it is \abovedisplayskip and \belowdisplayskip. Setting the last two to \topsep gives the same spacing:

\documentclass[fleqn]{article}
\usepackage[step=1cm]{pagegrid}
\usepackage[margin=0pt,papersize=2.5cm]{geometry}
%
\usepackage{amsmath}
\usepackage[amsmath,fleqn,thmmarks]{ntheorem}
%
\newcommand{\test}{%
\noindent%
Foo
$a=a$
Bar
}
%
\begin{document}
\test
%
\DeclareRobustCommand{$}{\begin{equation*}}% \DeclareRobustCommand{$}{\end{equation*}}%
\setlength{\abovedisplayskip}{\topsep}%
\setlength{\belowdisplayskip}{\topsep}%
\newpage
\test
\end{document}