# Apply formatting to selected page numbers of index

I would like to apply a formatting to some of the page numbers in an index. In the MWE below, when I use \index{} the page number should be in black and when I use \MyIndex{} the page number should be formatted with \FormatPageNumber{}:

The MWE below produces the results on the left. What changes do I need to make to the \MyIndex{} macro to achieve the results on the right:

## Code:

\documentclass{article}

\usepackage{xcolor}

\usepackage{imakeidx}
\makeindex

\newcommand*{\FormatPageNumber}[1]{\textcolor{red}{\bfseries#1}}
\newcommand*{\MyIndex}[1]{%
\begingroup
% Want to apply \FormatPageNumber{} to this page number ONLY in the index.
\index{#1}%
\endgroup
}%

\begin{document}

stuff\index{test}
\clearpage
more stuff\MyIndex{test}

\printindex

\end{document}


Formatting commands for the page number can be added using the syntax term|formatting, see page 5 of the manual.

MWE:

\documentclass{article}
\usepackage{xcolor}\pagecolor{white}

\usepackage{imakeidx}
\makeindex
\newcommand*{\FormatPageNumber}[1]{\textcolor{red}{\bfseries#1}}
\newcommand*{\MyIndex}[1]{%
\begingroup
\index{#1|FormatPageNumber}%
\endgroup
}%

\begin{document}
stuff\index{test}
\clearpage
more stuff\MyIndex{test}

\printindex

\end{document}