[Tex/LaTex] Indentation in algorithmic package

algorithmicalgorithmicx

I have a renamed command in the algorithmic package:

\usepackage{algpseudocode,algorithm,algorithmicx}
\algrenewcommand\algorithmicrequire{\textbf{Launch:}}

I like the way it looks, not having a number and no indentation.

However, I came up with anew case on where I would like to have some indentation on the line (while still not having a line number).

I have tried adding \hspace, but that does only add spaces after the Launch:, not before. How can I indent that line?

MWE:

\documentclass[11pt]{report}
\usepackage{algpseudocode,algorithm,algorithmicx}
\algrenewcommand\algorithmicrequire{\textbf{Launch:}}
\algrenewcommand\algorithmicensure{\textbf{End Kernel}}

\begin{document}
\begin{algorithm}

\begin{algorithmic}[1]
\Require{stuff 1} % this is OK
\For{for}
\State{loremIpsum()}
\Require{Unindented stuff 2}  % This is what I want to indent to the same level as the previous line

\State{loremIpsum} % indent also, but I can \qquad
\Ensure{} %  This is what I want to indent also

\EndFor
\Ensure{} % this is OK also
\end{algorithmic}

\end{algorithm}
\end{document}

Best Answer

Here is a version that should give the wanted result (if I understood the requirements correctly).

\documentclass[11pt]{article}
\usepackage{algpseudocode,algorithm,algorithmicx}

\makeatletter
\def\ALG@special@indent{%
    \ifdim\ALG@thistlm=0pt\relax
        \hskip-\leftmargin
    \else
        \hskip\ALG@thistlm
    \fi
}
\newcommand{\Launch}[1]{\item[]\noindent\ALG@special@indent \textbf{Launch:}\ #1}
\newcommand{\EndKernel}{\item[]\noindent\ALG@special@indent \textbf{End Kernel}}
\makeatother

\begin{document}
\begin{algorithm}
\begin{algorithmic}[1]
\Launch{stuff 1}
\For{for}
  \State{loremIpsum()}
  \Launch{Unindented stuff 2}
  \State{loremIpsum}
  \EndKernel
\EndFor
\EndKernel
\end{algorithmic}

\end{algorithm}
\end{document}

example output

I added new commands \Launch and \EndKernel to make the code more readable, as I assume you just used the other names because the output looked somewhat similar to what you want.

Both commands just insert simple lines without line numbers (like \Statex), but take some special care about the indentation. If one of these commands occurs at the top-level, no indentation is added; if it occurs somewhere inside another block, the current block indentation is used.