GeneralHow to continue displaying an algorithm if it is too long?

LaTeX specific issues not fitting into one of the other forums of this category.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

How to continue displaying an algorithm if it is too long?

Post by Stefan Kottwitz »

daiyue wrote:The thing is when I was using algorithmic, there seems to be no end if and such appears. So I was wondering how to turn such thing off.
You could create your own macro which saves that work:

Code: Select all

\newcommand\myIf[2]{\If{#1}#2\EndIf}
\newcommand\myWhile[2]{\While{#1}#2\EndWhile}
Using requires braces so the end can be detected, like here:

Code: Select all

      \myWhile{$\Sigma \leq \Sigma_{\max}$
             and $i < i_{\max}$}{
        \Let{x^\prime}{x^2 - y^2 + c_x}
        \Let{y^\prime}{2xy + c_y}
        \Let{m}{x^\prime}
        \Let{y}{y^\prime}
        \Let{\Sigma}{x^2 + y^2}}
      \myIf{$i < i_{\max}$}{
        \State \Return{$i$}}
      \State\Return{0}

Stefan
LaTeX.org admin

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

daiyue
Posts: 17
Joined: Mon May 21, 2012 5:58 pm

How to continue displaying an algorithm if it is too long?

Post by daiyue »

Stefan_K wrote:
daiyue wrote:The thing is when I was using algorithmic, there seems to be no end if and such appears. So I was wondering how to turn such thing off.
You could create your own macro which saves that work:

Code: Select all

\newcommand\myIf[2]{\If{#1}#2\EndIf}
\newcommand\myWhile[2]{\While{#1}#2\EndWhile}
Using requires braces so the end can be detected, like here:

Code: Select all

      \myWhile{$\Sigma \leq \Sigma_{\max}$
             and $i < i_{\max}$}{
        \Let{x^\prime}{x^2 - y^2 + c_x}
        \Let{y^\prime}{2xy + c_y}
        \Let{m}{x^\prime}
        \Let{y}{y^\prime}
        \Let{\Sigma}{x^2 + y^2}}
      \myIf{$i < i_{\max}$}{
        \State \Return{$i$}}
      \State\Return{0}

Stefan
\usepackage[noend]{algpseudocode} seems to be another viable solution.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Re: How to continue displaying an algorithm if it is too lon

Post by Stefan Kottwitz »

Ah, I see, it's not about saving source code lines but about omitting them in the output. Well, I think, a clear block end statement makes the algorithm often a bit clearer than omitting the end, having it implicit, so the reader should be aware.

Stefan
LaTeX.org admin
Post Reply