# Algorithmic and hyperref packages: strange interaction

I am not sure the bug below has already been reported as I cannot find clear information online. See the MWE: if \usepackage{hyperref} is not commented, the space below the equation is fairly large, way more than when the package is commented. It looks like it is a bad interaction between hyperref and the STATE command of the algorithmic package:

\documentclass{book}
\usepackage{algorithmic}
\usepackage{hyperref}
\begin{document}
\setlength\abovedisplayshortskip{0pt}
\setlength\belowdisplayshortskip{0pt}
\setlength\abovedisplayskip{0pt}
\setlength\belowdisplayskip{0pt}
\begin{algorithmic}
\STATE text text text text text text text text text text text text text
$$\cos\pi=-1$$
\STATE text text text text text text text text text text text text text
\STATE text text text text text text text text text text text text text
$$\cos\pi=-1$$
text text text text text text text text text text text text text
\end{algorithmic}
text text text text text text text text text text text text text
$$\cos\pi=-1$$
text text text text text text text text text text text text text
\end{document}


• A solution by adding: \usepackage{etoolbox} \AfterEndEnvironment{equation}{\vskip-0.5\baselineskip} – M.Ahmadi Oct 6 '19 at 20:21
• @M.Ahmadi Not sure because it affects all equations in the document and only very few of them have an issue. – pluton Oct 7 '19 at 15:19
• usepackage algorithmicx greatly improved algorithmic – M.Ahmadi Oct 7 '19 at 20:48

Changing the

\usepackage{algorithmic}


to

\usepackage{algorithmicx}


OR

\usepackage{algpseudocode}


And \STATE to \State does not create an empty space

The Minimal example:

\documentclass{book}
\usepackage{algorithmicx}
%\usepackage{algpseudocode}
\usepackage{hyperref}

\begin{document}
\setlength\abovedisplayshortskip{0pt}
\setlength\belowdisplayshortskip{0pt}
\setlength\abovedisplayskip{0pt}
\setlength\belowdisplayskip{0pt}
\begin{algorithmic}
\State text text text text text text text text text text text text text
$$\cos\pi=-1$$
\State text text text text text text text text text text text text text
\State text text text text text text text text text text text text text
$$\cos\pi=-1$$
text text text text text text text text text text text text text
\end{algorithmic}
text text text text text text text text text text text text text
$$\cos\pi=-1$$
text text text text text text text text text text text text text
\end{document}


Output:

• Interesting. Then this is a bug to be reported to the algorithmic package maintainer. – pluton Oct 7 '19 at 22:25