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: 10348
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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

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: 10348
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