Skip to content

Automatic line wrap in the same indent level? #16

@taishi-n

Description

@taishi-n

First, thank you for the excellent package!

I tried to write pseudocode with your package in a float environment.
My question: how to wrap lines under the same indent level in float environment?
I looked over your documentation and implementation but could not find an appropriate solution.

Here is a brief example.

\documentclass[10pt]{article}

% math
\usepackage{amsfonts,amsmath,amssymb,amsthm}

% tcolorbox
\usepackage[xparse,breakable,hooks,listingsutf8,documentation]{tcolorbox}
\tcbuselibrary{skins,theorems}
\newtcbtheorem[number within = section]{algorithm}{Algorithm}{pseudo/booktabs, float}{alg}

% pseudo-code
\usepackage{tabularx}

\usepackage{pseudo}
\pseudodefinestyle{fullwidth}{
    begin-tabular =
    \tabularx{\linewidth}[t]{@{}
        r                                      % Labels
        >{\leavevmode\pseudosetup}             % Indent, font, ...
        X                                      % Code (flexible)
        >{\leavevmode\small\color{gray}}       % Comment styling
        p{0.5\linewidth}                       % Comments (fixed)
        @{}},
    end-tabular=\endtabularx,
}
\pseudoset{%
   fullwidth,
   kwfont=\sffamily\bfseries,
   prfont=\textsf,
   indent-mark,
   ref,
}

\begin{document}

Here is our novel strong proposed method summarized in Algorithm \ref{alg:main}.
However some problems occur in the \texttt{float} environment.
\begin{algorithm}{Proposed method}{prop}
  \label{alg:main}
  \begin{pseudo}
    \kw{for} $i = 1, \dots, 100$ \\+
    A short process, this is fine \\
    A really very long long process which was proposed \\
    in a paper published a lot lot years ago. \\
    Manual linebreaking is fine of cource. \\
    \kw{if} some condition is satisfied \\+
    A really very long long process which was proposed in a paper published a lot lot years ago... \\+
    Also I want this line to be wrapped under the same indent level... \\
    I want to get\\
    like this automatically
  \end{pseudo}
\end{algorithm}

\end{document}

Then I got a result like this:
example-output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions