Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emulate \DontPrintSemicolon in algorithm2e.sty #2296

Merged

Conversation

dginev
Copy link
Collaborator

@dginev dginev commented Jan 4, 2024

Fixes dginev/ar5iv#423

Since algorithm2e.sty is emulated in Perl, with some very special considerations for the ends of lines, I think this is the best way to also support the \DontPrintSemicolon without losing the line endings.

There is probably a possible refactor that relies on the native interpretation more, but that could be deferred...

Running example:

\documentclass{article}
\usepackage{algorithm2e}
\begin{document}
\begin{algorithm}
\DontPrintSemicolon
line 1

line 2\;
line 3\;
\For{$t = 1, 2, \ldots, T$} {
    line 1\;
    line 2\;
    line 3\;
}
\end{algorithm}
\end{document}

@dginev
Copy link
Collaborator Author

dginev commented Jan 4, 2024

I also made the printing switches global assignments and spotted a curious discrepancy - algorithm2e will also create a listing line if there is a regular \par in the flow, but our binding had deactivated \r (to a space), so the par breaks weren't getting seen.

I probably need to fetch some more tests before this is really solid, since the comments do a great job of warning there may be too many newlines created if one isn't careful.

@dginev
Copy link
Collaborator Author

dginev commented Jan 4, 2024

As Bruce pointed out on the call today, this fixes the exact report from #2049

@brucemiller
Copy link
Owner

This looks plausible, I think. Is it ready for review?

@dginev
Copy link
Collaborator Author

dginev commented Jan 5, 2024

Doing a quick run through the ctan examples... It looks like the PR introduces some extra trailing newlines at the ends of indented blocks. Except no, the same extra line-breaks exist in the master branch. So no visible regressions.

I think the minimal fix here is ready for review+merge, and there are certainly more details one can fine-tune to get the examples rendering perfectly. But maybe not for this release?

@dginev
Copy link
Collaborator Author

dginev commented Jan 6, 2024

A comment for future reference (since I don't have an issue to attach it to):

Besides the empty trailing line, another detail that could be polished is the vertical algorithm bars, which are currently emulated via what seems to be | ascii art. I remembered that Twitter of all places has a nice solution for those using flexbox. I extracted it into a codepen (try horizontally shrinking/growing the window to demo the effect):
https://codepen.io/dginev/pen/QWoNgON

Maybe something to try a little later on.

@brucemiller brucemiller merged commit a76e37c into brucemiller:master Jan 6, 2024
13 checks passed
@brucemiller brucemiller deleted the algorithm2e-dont-print-semicolon branch January 6, 2024 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve article 2303.02491v2
2 participants