[Tex/LaTex] break line in if condition using algpseudocode while having nice indentation

algorithmicxline-breaking

I am trying to split a long line in my algorithm, which is in my if condition into two lines, while maintaining indentation. AND I don't want the line break to be anywhere but after my -or- in the code.

SO here is my code

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}

\usepackage{algorithm}
\usepackage{algpseudocode}

\algnewcommand\algorithmicor{\textbf{or}}
\newcommand{\pushcode}[1][1]{\hskip\dimexpr#1\algorithmicindent\relax}

\begin{algorithm}[h]
\caption{Core genome identification}
\begin{algorithmic}[1]
%I tired using this push
\While{$list$ is not empty \algorithmicor \\ \pushcode[1] second condition} 
\EndWhile
\end{algorithmic}
\end{algorithm}

\end{document}

I have tried it with this push for example, but this gives me a new line number what I don't want!

And other suggestions like defining

 \newcommand{\myindent}[1]{
 \newline\makebox[#1]{}
 }

Also puts the indent on a spec. indentation, what is not what I am searching for. I want it to be at the same indentation as the condition before. So something like

if (this is my first condition OR
    this is the second)

Best Answer

Redefine the loop and if statements in the preamble (after \usepackage{algpseudocode}) as follows:

\newcommand\CONDITION[2]%
  {\begin{tabular}[t]{@{}l@{}l@{}}
     #1&#2
   \end{tabular}%
  }
\algdef{SE}[WHILE]{While}{EndWhile}[1]%
  {\algorithmicwhile\ \CONDITION{#1}{\ \algorithmicdo}}%
  {\algorithmicend\ \algorithmicwhile}
\algdef{SE}[FOR]{For}{EndFor}[1]%
  {\algorithmicfor\ \CONDITION{#1}{\ \algorithmicdo}}%
  {\algorithmicend\ \algorithmicfor}
\algdef{S}[FOR]{ForAll}[1]%
  {\algorithmicforall\ \CONDITION{#1}{\ \algorithmicdo}}
\algdef{SE}[REPEAT]{Repeat}{Until}{\algorithmicrepeat}[1]%
  {\algorithmicuntil\ \CONDITION{#1}{}}
\algdef{SE}[IF]{If}{EndIf}[1]%
  {\algorithmicif\ \CONDITION{#1}{\ \algorithmicthen}}%
  {\algorithmicend\ \algorithmicif}%
\algdef{C}[IF]{IF}{ElsIf}[1]%
  {\algorithmicelse\ \algorithmicif\ \CONDITION{#1}{\ \algorithmicthen}}

The definitions are taken from the style file algpseudocode.sty and modified to handle multiline conditions.

Here is a complete example:

\documentclass{article}
\usepackage{algpseudocode}

... Code from above ...

\begin{document}
\begin{algorithmic}[1]
  \While{short condition} 
  \EndWhile
  \While{very long condition\\broken into two lines} 
  \EndWhile
\end{algorithmic}
\end{document}

enter image description here