[Tex/LaTex] How to wrap lines correctly inside algorithmic + more indentation for children lines

algorithmicxindentation

Please refer to this answer. I used its parState command to create this MWE:

\documentclass{article}
\usepackage{algorithm,algpseudocode}
\makeatletter
\newcommand{\algmargin}{\the\ALG@thistlm}   
\makeatother
\algnewcommand{\parState}[1]{\State%
    \parbox[t]{\dimexpr\linewidth-\algmargin}{\strut #1\strut}}

\begin{document}
\begin{algorithm}
\caption{My pseudo code.}
\begin{algorithmic}[1]
    \If{$true$}
    \parState{%
    Look at this state again, this state is just too long for algorithmic to handle, I'm just going to switch to Word. Look at this state again, this state is just too long for algorithmic to handle, I'm just going to switch to Word. Look at this state again, this state is just too long for algorithmic to handle, I'm just going to switch to Word.}
    \EndIf
\end{algorithmic}
\end{algorithm}
\end{document}

which yields this:

enter image description here

How can the last 4 lines of line 2 be even more intended than the first line of line 2? I'd like them to be intended by the amount of space which is used to intend line 2 with respect to the line 1.

Best Answer

If there is only one paragraph involved you can use \hangindent/\hangafter:

\documentclass{article}
\usepackage{algorithm,algpseudocode}
\makeatletter
\newcommand{\algmargin}{\the\ALG@thistlm}
\makeatother
\algnewcommand{\parState}[1]{\State%
    \parbox[t]{\dimexpr\linewidth-\algmargin}{\strut\hangindent=\algorithmicindent \hangafter=1 #1\strut}}

\begin{document}
\begin{algorithm}
\caption{My pseudo code.}
\begin{algorithmic}[1]
    \If{$true$}
    \parState{%
    Look at this state again, this state is just too long for algorithmic to handle, I'm just going to switch to Word. Look at this state again, this state is just too long for algorithmic to handle, I'm just going to switch to Word. Look at this state again, this state is just too long for algorithmic to handle, I'm just going to switch to Word.}
    \EndIf
\end{algorithmic}
\end{algorithm}
\end{document}

enter image description here