Solution (source code)

= Solution

Use the <Hecke-normalized rational slash operator> from the PDF, writing $f[\alpha]_k$ for its right action. Put $A_D=\operatorname{diag}(D,1)$. If $\gamma=\begin{pmatrix}a&b\\c&d\end{pmatrix}\in\Gamma_0(N)$, then
$$
A_D\gamma A_D^{-1}=\begin{pmatrix}a&Db\\c/D&d\end{pmatrix}\in\Gamma_0(M).
$$
Indeed $N/D$ is an integer divisible by $M$, so $c/D$ is an integer divisible by $M$. The ordinary weight transformation of the original <cusp form> therefore gives
$$
f(D\gamma\tau)=(c\tau+d)^k f(D\tau).
$$
Thus $g(\tau)=f(D\tau)$ has the correct transformation for the <Gamma 0 congruence subgroup> at level $N$, and it is holomorphic in the <complex upper half-plane>.

It remains to check every <modular cusp>, not just infinity. Let $\rho\in SL_2(\mathbb Z)$ carry infinity to that cusp, and choose $\sigma\in SL_2(\mathbb Z)$ with $\sigma\infty=A_D\rho\infty$. The matrix $B=\sigma^{-1}A_D\rho$ is upper triangular over the rationals, with positive ratio of diagonal entries. Therefore, up to a nonzero constant weight factor,
$$
g[\rho]_k=(f[\sigma]_k)[B]_k.
$$
The original cusp expansion of $f[\sigma]_k$ has only positive exponents. The change $\tau\mapsto r\tau+s$ induced by $B$, with $r>0$, preserves exponential decay as $\operatorname{Im}\tau\to\infty$. The transformed function also has a positive integral period because $g$ is modular for a finite-index subgroup. Its bounded periodic holomorphic expansion consequently has no negative exponents and its limiting constant term is zero. This proves <cusp holomorphy under rational slash operators> and establishes the <degeneracy map for cusp forms>:
$$
\boxed{f(D\tau)\in S_k(\Gamma_0(N)).}
$$