chrmatt / algpseudocodex

LaTeX package for typesetting pseudocode.
38 stars 2 forks source link

How to adjust lineskip in algorithmic? #12

Closed note286 closed 1 year ago

note286 commented 1 year ago

I need to modify the lineskip value in a certain algorithmic environment so that it applies uniformly throughout the environment. It works in the algpseudocode package, but not in the algpseudocodex package. In the algpseudocodex package, I have to manually set it after each \State, which is very inconvenient. I have roughly read the source code, but I haven't found the reason. It seems like \State is resetting some values.

\documentclass{article}
% \usepackage{algpseudocodex}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithmic}[1]
\addtolength{\lineskip}{10pt}
\Require
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
$\sum\limits_i^1$
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
\Ensure
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
$\sum\limits_i^1$
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
\State
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
$\sum\limits_i^1$
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\State
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\State
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
$\sum\limits_i^1$
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{algorithmic}
\end{document}

image


But if with algpseudocodex.

image


With algpseudocodex, must add after to \State.

\State \addtolength{\lineskip}{10pt}
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
$\sum\limits_i^1$
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

image

note286 commented 1 year ago

After testing, I found that the \lineskip value set outside does not take effect within the minipage.

chrmatt commented 1 year ago

Your testing is correct: The reason it does not work with algpseudocodex is that it places everything in a varwidth environment, which resets certain values. You can place the following at the beginning of the algorithmic environment: \makeatletter\pretocmd{\algpx@endCodeCommand}{\addtolength{\lineskip}{10pt}}{}{}\makeatother This changes the lineskip for every command.

note286 commented 1 year ago

If noEnd=true, the position of the end will be added twice. If noEnd=false, It seems like there's no problem.

\documentclass[twocolumn]{article}
\usepackage[noEnd=true]{algpseudocodex}
\makeatletter
\pretocmd{\algpx@endCodeCommand}{\addtolength{\lineskip}{10pt}}{}{}
\makeatother
\newcommand{\xxx}{Lorem ipsum dolor sit amet $\sum\limits_i^1$}
\begin{document}
\begin{algorithmic}[1]
\Require \xxx
\Ensure \xxx
\For{\xxx}
\For{\xxx}
\State \xxx
\EndFor
\State \xxx
\EndFor
\State \xxx
\State \xxx
\State \xxx
\end{algorithmic}
\newpage
\begin{algorithmic}[1]
\Require \xxx
\Ensure \xxx
\State \xxx
\State \xxx
\State \xxx
\State \xxx
\State \xxx
\State \xxx
\State \xxx
\end{algorithmic}
\newpage
\begin{algorithmic}[1]
\Require \xxx
\Ensure \xxx
\For{\xxx}
\State \xxx
\State \xxx
\State \xxx
\EndFor
\State \xxx
\State \xxx
\State \xxx
\end{algorithmic}
\end{document}

image


noEnd=false

image

note286 commented 1 year ago

The following configuration results are good, I'm not sure if there are any omissions in principle? As the author, you are more familiar with the implementation details.

\usepackage[noEnd=true]{algpseudocodex}
\AtBeginEnvironment{algorithmic}{
\apptocmd{\State}{\addtolength{\lineskip}{10pt}}{}{}
\addtolength{\lineskip}{10pt}
}

image

chrmatt commented 1 year ago

If you just modify \State, it will not affect text inside, for, if, etc., that is spanning multiple lines.

I've pushed a quick update to the package such that the lineskip value is automatically restored. You can try the newest version from GitHub, it should behave the same as algpseudocode. It should be available via CTAN as version 1.1.1 soon.

note286 commented 1 year ago

Thank you very much. Considering the actual use, we still need to restore the value of \lineskiplimit. I have submitted the PR.

chrmatt commented 1 year ago

Great, thank you!