2

I am using overleaf. When using the algorithm2e package, it gives me bold line numbers prefixed with a "-" symbol for each line. I want to have a line number in small fonts without the "-" symbol. An output pdf snapshot is attached with minimal working code. Thank you in advance.

\documentclass{ieeeaccess}
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage[ruled,linesnumbered]{algorithm2e}
\usepackage{graphicx}
\begin{document}
     \begin{algorithm}
    \DontPrintSemicolon   
    % enter the algorithm environment
    \caption{algorithm}          
    % give the algorithm a caption
    \label{alg1}   
    %\begin{multicols}{2}                       % and a label for \ref{} commands 
    %\begin{algorithmic}[1] 
    \KwIn{
        $a=\sum_{i=0}^{n-1} a_i\cdot2^i$,
        $b=\sum_{i=0}^{n-1} b_i\cdot2^i$,
        $m=\sum_{i=0}^{n-1} m_i\cdot2^i$}
    \KwOut {$c = a \times b$ \text{mod} $m$}
    
    $c \leftarrow 0, \quad reg_1 \leftarrow a$\;
    $reg \leftarrow 2a$ mod $m \qquad \text {//     \scriptsize Pre-computed value //} $\;
    %$N \leftarrow n+2 \quad \quad \quad \text{ //  \scriptsize append two 0's to left of MSB of y //}$\;
    $N= 
    \begin{cases}
    n+3,& \text{ if $n \bmod 2 = 0,$ append two $0$ to the left of MSB of $b$} \\
    n+2,& \text{ if $n \bmod 2 = 1,$ append single $0$ to the left of MSB of $b$}
    \end{cases}
    $\;
    $N \leftarrow N+1 \qquad  \text{ // \scriptsize append 0 to right of LSB of b //}$\;
    
    \For {$(i=0; i \leq N-2; i \leftarrow i+2)$ }{
        \Switch{$(b_{(i+2:i)})$}{
            \textbf{when} $ 000 \mid 111 \Longrightarrow v\leftarrow 0$ \;
            \textbf{when} $ 001 \mid 010 \mid 101 \mid 110 \Longrightarrow v\leftarrow reg_1$  \;
            \textbf{else} $ \Longrightarrow  d\leftarrow reg_2$ \;
        }
        \tcp {following critical operations are executed concurrently //}
        $reg_1 \leftarrow 4\times reg_1 \text{ modulo } m$\; 
        $reg_2 \leftarrow 4\times reg_2 \text{ modulo } m$\; 
        $v \leftarrow v \pm d \text{ modulo } m$\;
    }
    \Return{$v$}\;
    %\end{multicols}
    \end{algorithm}
\end{document}

enter image description here

6
  • 2
    Please tell us which document class you employ, which font packages you load, and how or where \atcp is defined. – Mico Feb 24 at 8:00
  • 1
    Off-topic: I believe you should replace all instances of \sum_{i=o}^{n-1} with \sum_{i=0}^{n-1}. – Mico Feb 24 at 8:07
  • I am using IEEE Access document class with following packages \documentclass{ieeeaccess} \usepackage{cite} \usepackage{amsmath,amssymb,amsfonts} \usepackage{algorithmic} \usepackage[ruled,linesnumbered]{algorithm2e} \usepackage{graphicx} – Khalid Feb 24 at 8:15
  • 2
    This is not a MWE, please edit and complete with all preamble, in order to make it work for everyone just by copy/paste in our editor. – SebGlav Feb 24 at 9:41
  • now i have edited it in the form of MWE... – Khalid Feb 24 at 14:24
3

Use a different class.

If you can't, make a copy of the original \textbf before loading the class and restore it afterwards

\RequirePackage{letltxmacro}
\LetLtxMacro{\LaTeXtextbf}{\textbf}
\documentclass{ieeeaccess}
\LetLtxMacro{\textbf}{\LaTeXtextbf}
% [ the rest of your document ]

enter image description here


Explanation

The file (sorry but I can't really call it class) ieeeaccess.cls does a lot of wonderful things, among which we find the following jewels (new lines added for clarity):

\def\textbf#1{{\bf #1}}%
\long\def\bf#1{%
   \ifmmode
      \mathbf{#1}%
      \message{Please use mathbf in math mode instead of bf.}%
   \else
      \fontencoding{T1}%
      \fontseries{b}%
      \selectfont{#1}%
   \fi
}

The first redefinition is very questionable but the second one is really evil, and will break down every time the argument of \textbf starts with a macro taking arguments (or some primitive, or who knows what else).

Let us make a concrete example: assume we are in text mode and we write

\textbf{ABCDE...}

The first expansion turns this into

{\bf ABCDE...}

Now \bf has been defined to take an argument, which will be just the first token of the argument passed to \textbf, in this example A. The expansion of \bf turns then our example into

{\fontencoding{T1}\fontseries{b}\selectfont{A}BCDE...}

I suspect (though I'm not Mary Poppins and as such I might be incorrect) that the result isn't quite what the author(s) intended. The first token (here A) is put into a group, which will break kerning with the following letter.


The situation is even worse when the argument of \textbf involves other macros, like in the case of algorithm2e. The line numbers are printed using \NlSty{\theAlgoLine}, where \theAlgoLine expands to the line counter, and \NlSty is defined (simplifying a bit) as

\newcommand{\NlSty}[1]{\textbf{\relsize{-2}#1}}

This is similar to what I've written above, only that this time the first token of the argument of \textbf isn't a letter but is rather \relsize. After expansion of the gloriously redefined \textbf and \bf the code \NlSty{\theAlgoLine} results in

{\fontencoding{T1}\fontseries{b}\selectfont{\relsize}{-2}\theAlgoLine}

The macro \relsize is enclosed in a group and chaos ensues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.