0

I'm trying to compile the code from this answer: https://tex.stackexchange.com/a/1376/35161

I keep getting the following error:

! Undefined control sequence.
\ALG@cmd@2@alglinenumber ...size \addfontfeatures 
                                                  {Colour=888888,Numbers=Mon...
l.22     \Function
                  {Distance}{$x, y$}
? 

When I remove the line numbers (changing \begin{algorithmic}[1] to \begin{algorithmic}), it compiles. Any clues on how to solve this?

Here is the MWE:

\documentclass[11pt]{article}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage[noend]{algpseudocode}

\newcommand*\DNA{\textsc{dna}~}

\newcommand*\Let[2]{\State #1 $\gets$ #2}
\algrenewcommand\alglinenumber[1]{
    {\sf\footnotesize\addfontfeatures{Colour=888888,Numbers=Monospaced}#1}}
\algrenewcommand\algorithmicrequire{\textbf{Precondition:}}
\algrenewcommand\algorithmicensure{\textbf{Postcondition:}}

\begin{document}

\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}

\end{document}

In case someone finds relevant, I'm using MikTeX on Windows 7.

1 Answer 1

1

You have missed the \usepackage{fontspec} \setmainfont{Hoefler Text} parts of the preamble at that link. Although I don't have that font on my system, if I substitute a font I do have, I get no errors with TL2014 on Windows 7. This requires either XeLaTeX or LuaLaTeX to compile.

\documentclass[11pt]{article}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage[noend]{algpseudocode}
\usepackage{fontspec} %<---- Here
\setmainfont{Calibri} %<---- Here

\newcommand*\DNA{\textsc{dna}~}

\newcommand*\Let[2]{\State #1 $\gets$ #2}
\algrenewcommand\alglinenumber[1]{
    {\sf\footnotesize\addfontfeatures{Colour=888888,Numbers=Monospaced}#1}}
\algrenewcommand\algorithmicrequire{\textbf{Precondition:}}
\algrenewcommand\algorithmicensure{\textbf{Postcondition:}}

\begin{document}

\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}
\end{document}
2
  • Ok, I don't want to use non-standard fonts, I don't think the journal I'm writing for would like it. I guess the exact offender is that \addfontfeature. I'm gonna remove it. Oct 6, 2014 at 23:28
  • Yup, it worked. Oct 6, 2014 at 23:34

You must log in to answer this question.

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