The following code is continued from this post and this one. The following code compiles ok without babel
but not with it. See the console output below. Is there a way resolve this issue?
\documentclass{article}
\usepackage{afterpage}
\usepackage[french]{babel} % no error if uncommented
\usepackage{mwe}
\usepackage{refcount}
\usepackage{tocloft}
\usepackage{xparse}
\usepackage{xwatermark} % ruled out
\newlistof{encl}{encl}{List of enclosed items}
\NewDocumentCommand
{\addencl}
{ m }
{
\refstepcounter{encl}
\addcontentsline{encl}{encl}{\theencl. #1}
}
\NewDocumentCommand
{\getencl}
{ m }
{
E{\small NCL} \# \getrefnumber{#1}
}
\begin{document}
\newwatermark*[page=\getpagerefnumber{encl:bar}]{Bar}
\newwatermark*[page=\getpagerefnumber{encl:foo}]{Foo}
\listofencl
%\verb|\getrefnumber{encl:foo}|:\getrefnumber{encl:foo}
%\verb|\getpagerefnumber{encl:foo}|:\getpagerefnumber{encl:foo}
\getencl{encl:bar}~is~on~page~\getpagerefnumber{encl:bar}
\getencl{encl:foo}~is~on~page~\getpagerefnumber{encl:foo}
\newpage
%\refstepcounter{encl}
\addencl{Bar}\label{encl:bar}
\includegraphics[width=\linewidth]{example-image-a}
\newpage
\addencl{Foo}\label{encl:foo}
\includegraphics[width=\linewidth]{example-image-b}
%\newwatermark*{}
\end{document}
Console output:
ERROR: Missing \endcsname inserted.
--- TeX said --- \unskip l.36 \getencl{encl:bar} ~is~on~page~\getpagerefnumber{encl:bar} --- HELP --- From the .log file...
The control sequence marked should not appear between \csname and \endcsname.