Algorithm2e – write IfThenElse in one line

algorithm2eifthenelse

I have the following example

\documentclass{report}
\usepackage{algorithm2e}

\begin{document}
    
    \begin{algorithm}
        \lIf{$\max_{\mathcal{AV}} > \theta_5$}
        {
            \Return the tracklet with $\max_{\mathcal{AV}}$.
        }
        \lElse
        {
            \Return no speaker.
        }  
    \end{algorithm}
    
\end{document}

however I do not want if and else be in two separate lines, but only in one.

Could anyone help me, please?
Thanks in advance

Best Answer

Define \lIfElse{<condition>}{<true>}{<false>} to insert the <false> clause as part of <true>:

enter image description here

\documentclass{article}

\usepackage{algorithm2e}

\newcommand{\lIfElse}[3]{\lIf{#1}{#2 \textbf{else}~#3}}

\begin{document}
    
\begin{algorithm}
  \lIfElse{$a$}{True}{False}
  \lIfElse{$b$}{\Return True}{\Return False}
\end{algorithm}
    
\end{document}