0

What is the correct usage of algomathdisplay from the algorithm2e package? I appear to have misunderstood its usage, see example below. There are two different attempts one with just

\begin{algomathdisplay}
   ...
\end{algomathdisplay}
%
next line

which causes weird indentations on the next line, and a second attempt:

\begin{algomathdisplay}
   ...
\end{algomathdisplay}\;
%
next line

which results in an empty semicolon-line

enter image description here

lastly here is the full code

\begin{algorithm}
    \While{test}{
        Some words introducing the following equation
        \begin{algomathdisplay}
            1+1
        \end{algomathdisplay}
        Another line\;
        Words introducing the second equation
        \begin{algomathdisplay}
            2+2
        \end{algomathdisplay}\;
        Last Line;
    }
\end{algorithm}

Wrong Solutions

Suggested Macro fix by https://tex.stackexchange.com/a/543384/82917

\makeatletter
\renewenvironment{algomathdisplay}
 {\[}
 {\@endalgocfline\vspace{-\baselineskip}\]\;}
\makeatother

\begin{algorithm}
    \While{test}{
        Another line\;
        Words introducing the second equation
        \begin{algomathdisplay}
            2+2
        \end{algomathdisplay}
        Last Line\;
    }
\end{algorithm}

results in

enter image description here

2
  • @campa thanks for the comment - so I guess this should work in normal circumstances? Because I just assumed I made an immediately obvious user error.
    – Felix B.
    Aug 20, 2021 at 12:05
  • @campa yeah sorry - fixed it
    – Felix B.
    Aug 20, 2021 at 12:11

1 Answer 1

2

The issue was the global \DontPrintSemicolon in https://tex.stackexchange.com/a/543384/82917

something less invasive can be achieved with

\makeatletter
\renewenvironment{algomathdisplay}
 {\[}
 {\@endalgocfline\vspace{-\baselineskip}\]{\DontPrintSemicolon\;}}
\makeatother
1
  • That's amazing! Thank you, it is exactly what I was looking for!
    – milembar
    Dec 17, 2021 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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