algorithmicx 软件包因行号问题而堵塞

algorithmicx 软件包因行号问题而堵塞

我正在尝试根据这个答案编译代码:https://tex.stackexchange.com/a/1376/35161

我不断收到以下错误:

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

当我删除行号(更改\begin{algorithmic}[1]\begin{algorithmic})时,它会编译。有什么线索可以解决这个问题吗?

以下是 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}

如果有人发现相关内容,我在 Windows 7 上使用 MikTeX。

答案1

您错过了\usepackage{fontspec} \setmainfont{Hoefler Text}该链接的前言部分。虽然我的系统上没有该字体,但如果我用已有的字体替换,则在 Windows 7 上使用 TL2014 时不会出现任何错误。这需要 XeLaTeX 或 LuaLaTeX 进行编译。

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

相关内容