3

I'm using the small capital font \textsc{MyAlgorithm} several times inside my algorithm2e environment as follows:

\documentclass[a4paper, english]{article}
\usepackage{amsmath} 
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[ruled,linesnumbered,vlined]{algorithm2e}

\begin{document}

\begin{algorithm}
\DontPrintSemicolon
\FuncSty{${\textsc{FirstAlgorithm}}(a, b))$} \Begin{
  $ X \leftarrow \textsc{AnotherAlgorithm}(c, d)$\;
}
\end{algorithm}

\end{document}

I don't undestand why FirstAlgorithm has a completely and unexpected (looks like \textit) font and AnotherAlgorithm later looks as it should? Any ideas?

1 Answer 1

3

\FuncSty sets its argument using \texttt, which is inherited by \textsc (from algorithm2e.sty):

\newcommand{\FuncSty}[1]{\textnormal{\texttt{#1}}\unskip}%\SetFuncSty{texttt}

Technically you don't need \FuncSty in this instance, but I'd suggest defining a macro to perform your function name formatting consistently:

enter image description here

\documentclass{article}
\usepackage[ruled,linesnumbered,vlined]{algorithm2e}% http://ctan.org/pkg/algorithm2e
\newcommand{\FuncName}[1]{\mbox{\normalfont\textsc{#1}}}

\begin{document}

\begin{algorithm}
  \DontPrintSemicolon
  \FuncSty{${\textsc{FirstAlgorithm}}(a, b))$}
  \Begin{
    $ X \leftarrow \textsc{AnotherAlgorithm}(c, d)$\;
  }
\end{algorithm}

\begin{algorithm}
  \DontPrintSemicolon
  $\FuncName{FirstAlgorithm}(a, b)$
  \Begin{
    $X \leftarrow \FuncName{AnotherAlgorithm}(c, d)$\;
  }
\end{algorithm}

\end{document}

Your use of the ruled style provided by algorithm2e does not seem appropriate (the double-rule at the top is supposed to contain an algorithm \caption).

1
  • Pretty good explanation. I'll pay attention to this in the future.
    – Daniel F
    Commented Dec 15, 2013 at 18:35

You must log in to answer this question.

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