algorithm2e error on \SetDataSty

Using the algorithm2e package I am trying to write an algorithm on a document. I wish to change the default font used on the \SetKwData variables and I am trying to do that by using the \SetDataSty function as shown below:

\SetAlFnt{\footnotesize}
\SetDataSty{\small\fontfamily{qcr}} % this line causes Extra \endcsname. errors

\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\begin{algorithm}[h]
\LinesNumbered

\SetKwData{AVG}{average\_val}

\Input{A tuple $(a,b)$}
\Output{A hashmap $m$}

\BlankLine

\AVG

\end{algorithm}



But I am getting Extra \endcsname. errors on the compilation log. What am I doing wrong here?

• Please write a minimal working example. See link for more details what it means. Jun 14 at 11:15
• I'm pretty sure you need to put a single control sequence name in the \SetDataSty{...} Jun 14 at 11:20

You need to define a command with an argument giving the font specification and then use the name of this command in the argument for \SetDataSty:

%! TEX program = lualatex
\documentclass[12pt]{article}
\usepackage{algorithm2e}
\begin{document}

\SetAlFnt{\footnotesize}
\newcommand\mydatastyle{\small\fontfamily{qcr}}
\SetDataSty{mydatastyle} % this line does not cause Extra \endcsname. errors

\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\begin{algorithm}[h]
\LinesNumbered

\SetKwData{AVG}{averageval}

\Input{A tuple $(a,b)$}
\Output{A hashmap $m$}

\AVG

\end{algorithm}

\end{document}


first sentence quote nearly-verbatim from https://tex.stackexchange.com/a/162208/250119

• Actually I'm not quite sure if the lack of grouping cause problem or not...? Jun 14 at 11:29
• Well, i still get the same error Jun 14 at 14:22
• @ex1led Give MWE. The document I include in my answer does not get any error Jun 14 at 14:55