# Reset the default font and style for algoritm2e

I'm using a (required) template with a sans serif font, however I would like to maintain the default font for algorithms.

I'm using pseudocode with variables with more than one letter, so I defined a data type in algorithm2e with that variable name, because I was told that in math mode latex understands multiple variables without spaces as a multiplication of several single letter variables and not as the long name of a variable.

However, as I have to use sans serif font, my variables use that font also, and it doesn't look good, as it's different from single varibles.

I tried using italic an Computer Modern font...

My code:

\documentclass[10pt,a4paper,twoside]{report}

\usepackage[linesnumbered,ruled,vlined,algochapter]{algorithm2e}
\DontPrintSemicolon
\SetAlFnt{crm}
\SetDataSty{it}

\SetKwData{Result}{result}

% Use Arial font as default
\renewcommand{\rmdefault}{phv}
\renewcommand{\sfdefault}{phv}

\begin{document}

\begin{algorithm}
\KwIn{ $$x$$ and $$y$$  }
\KwOut{ \Result }

$$\Result \leftarrow x + y$$ \;

\Return{ \Result  }

\caption{ This is a caption }
\end{algorithm}

In here I talk about the \Result of $$x + y$$.
\end{document}


How it looks:

How I would like it to look:

("result" seem the same font as "x" and "y", but the caption also changed...)

• Before you go all out trying to do this, have you checked if you are allowed to? If they are demanding the entire document in sans (and this is not a presentation or a signpost), then they are typographically misguided and may well fail to appreciate any appeal to the aesthetic superiority of your approach. (And won't it look even odder to have serif just in the algorithms?) – cfr Oct 7 '15 at 23:08
• I see your point @cfr. But it is not just the algorithms, everything in math mode already appears with that font (inside and outside algorithms: it's probably noticeable in the "x +y", in the first image, in the text under the algorithm). I do agree sans is not the best choice. – Fernando César Oct 8 '15 at 8:20

Seems I nailed it, after finding this about typesetting in algorithm2e and this about the default math mode font.

\newcommand{\myargfont}{\itshape\fontfamily{lmr}\selectfont}
\SetDataSty{myargfont}


I'm not completely sure about the font (as the link talks about Latin Modern Math and not Latin Modern Roman, as I'm using here), so if some one wants to correct me, please do!

Complete code:

\documentclass[10pt,a4paper,twoside]{report}

\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\DontPrintSemicolon
\newcommand{\myargfont}{\itshape\fontfamily{lmr}\selectfont}
\SetDataSty{myargfont}
\SetKwData{Result}{result}
% Use Arial font as default
%
\renewcommand{\rmdefault}{phv}
\renewcommand{\sfdefault}{phv}

\begin{document}

\begin{algorithm}
\KwIn{$$x$$ and $$y$$}
\KwOut{\Result}
$$\Result\leftarrow x + y$$ \;
\Return{\Result}
\caption{ This is a caption }
\end{algorithm}

In here I talk about the \Result of $$x + y$$.
\end{document}