1

I am using algorithm2e to write algorithms, and I use the answer to this question to prevent the text in the algorithm to be in italic (by adding \SetArgSty{textrm} at the start of the algorithm).

\documentclass{article}
\usepackage{algorithm2e}
\begin{document}

\begin{algorithm}
\SetArgSty{textrm}  % <-'Flag' will not be written in italic
\Begin{
    Flag $\leftarrow$ True\;
    \If{Flag}{
        DoSomething()\;
    }
}
\end{algorithm}
\end{document}

There are several algorithms in my document, and it is typically the kind of thing I like to have factored at the start of the document rather than to write it in each and every algorithm.

I am wondering, is there a way to have this working for all the algorithms in my document ?

m.raynal
  • 135

1 Answers1

3

with help of the package etoolbox and its macro \AtBeginEnvironment:

\documentclass{article}
\usepackage{algorithm2e}
\usepackage{etoolbox}
\AtBeginEnvironment{algorithm}{\SetArgSty{textrm}}  % <-'Flag' will not be written in italic

\begin{document}

\begin{algorithm}
\Begin{
    Flag $\leftarrow$ True\;
    \If{Flag}{
        DoSomething()\;
    }
}
\end{algorithm}
\end{document}

enter image description here

Zarko
  • 296,517