1

I want to write the algorithm in latex. I don't want to use for example a code given below:

\begin{algorithm}

  \caption{Counting mismatches between two packed \DNA{} strings
    \label{alg:packed-dna-hamming}}
  \begin{algorithmic}[1]
    \Require{$x$ and $y$ are packed \DNA{} strings of equal length $n$}
    \Statex
    \Function{Distance}{$x, y$}
      \Let{$z$}{$x \oplus y$} \Comment{$\oplus$: bitwise exclusive-or}
      \Let{$\delta$}{$0$}
      \For{$i \gets 1 \textrm{ to } n$}
        \If{$z_i \neq 0$}
          \Let{$\delta$}{$\delta + 1$}
        \EndIf
      \EndFor
      \State \Return{$\delta$}
    \EndFunction
  \end{algorithmic}
\end{algorithm}

The problem with above code is that it is pseudocode. But my algorithm consists of English sentences only. Is there an better way to write such kind of algorithms?

1 Answer 1

7

If you just have a list of items showing a sequence of events/steps, it would suffice to use a regular list (like enumerate or itemize):

enter image description here

\documentclass{article}

\usepackage{lipsum}% Just for this example

\begin{document}

Consider the following structured approach:
\begin{enumerate}
  \item This is the first sentence that contains a description of
    what is important to do.
  \item There is more in this sentence.
  \item \lipsum[1]
  \item A final sentence describing a warp-up of what should be
    performed to complete the process you're want to discuss.
\end{enumerate}

\end{document}

algorithmicx can also be used in the way you suggest - sentences:

enter image description here

\documentclass{article}

\usepackage{algorithm,algpseudocode}
\usepackage{lipsum}% Just for this example

\begin{document}

\begin{algorithm}
  \caption{This is an algorithm}
  \begin{algorithmic}[1]
    \State This is the first sentence that contains a description of
      what is important to do.
    \State There is more in this sentence.
    \State \lipsum[1]
    \State A final sentence describing a warp-up of what should be
      performed to complete the process you're want to discuss.
  \end{algorithmic}
\end{algorithm}

\end{document}

algorithm2e is also an option:

enter image description here

\documentclass{article}

\usepackage{algorithm2e}
\DontPrintSemicolon
\LinesNumbered

\usepackage{lipsum}% Just for this example

\begin{document}

\begin{algorithm}
  \caption{This is an algorithm}
  This is the first sentence that contains a description of
    what is important to do.\;
  There is more in this sentence.\;
  \lipsum*[1]\;
  A final sentence describing a warp-up of what should be
    performed to complete the process you're want to discuss.\;
\end{algorithm}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .