I trying to make a kind of a refactor of, and added feature to, newwatermark (and siblings). That feature is binding a label to the watermark, such that the page on which it is applied is automatically determined. Where the program stands, I hope it's only a case of using the right kind of argument expansion inside \MyMacro:
\documentclass{report}
\usepackage[english]{babel}
\usepackage{mwe}
\usepackage{pdfpages}
\usepackage{refcount}
\usepackage{xparse}
\usepackage{xwatermark}
\ExplSyntaxOn
\cs_new_protected:Nn\__bgetpagerefnumber:n
{
%https://tex.stackexchange.com/questions/450771/babel-conflicts-with-i-think-refcount
\getpagerefnumber{\detokenize{#1}}
}
\cs_new_protected:Nn \__opt_as_arg:nn
{
#1[#2]
}
\cs_new_protected:Nn \__merge_keyval:nn
{
\seq_clear:N \l_tmpa_seq
\seq_put_right:Nn \l_tmpa_seq {#1}
\seq_put_right:Nn \l_tmpa_seq {#2}
\seq_use:Nn \l_tmpa_seq { , }
}
\NewDocumentCommand{\MyMacro}
{
m % cmd e.g. \newwatermark,\newwatermark*
m % label
O{} % options for \newwatermark except page
}
{
\label{#2}
\exp_args:Nff
\__opt_as_arg:nn
{\exp_not:n{#1}}
{%
\__merge_keyval:nn
{page=1}%todo: replace by%{\__bgetpagerefnumber:n{#2}}
{#3}
}
{\color{black}Watermark}
}
\ExplSyntaxOff
\begin{document}
\ExplSyntaxOn
\__merge_keyval:nn{page=1}{ypos=33} % EXPECT: page=1,ypos=33 %OK
\clearpage
%----
\MyMacro{\newwatermark*}{foo}[ypos=95] % EXPECT: equivalent to:
%--
%\label{foo}
%\newwatermark*[page=\__bgetpagerefnumber:n{foo},ypos=95]{\color{black}Watermark}
%--
\includepdf{example-image-a}
\ExplSyntaxOff
\end{document}
out:
ERROR: Package xwatermark Error: No page specifier for watermark:
--- TeX said ---
||\color {black}Watermark||.
See the xwatermark package documentation for explanation.
Type H <return> for immediate help.
...
l.71 \MyMacro{\newwatermark*}{foo}[ypos=95]
% EXPECT: equivalent to
--- HELP ---
No help available

MyMacromerely merges two steps, those shown underequivalent to:. If the user wants to refer to the page where the watermark has been laid, he needs control over it. – Erwann Jan 10 '20 at 13:54