From the preamble of the document. The mathtools bundle hundreds the amsmath package and for this reason there's no ought to usepackage amsmath from the preamble if mathtools is applied. $$ is TeX primitive syntax, which, as Other individuals have commented is difficult to redefine (in classic TeX there is https://gab.com/LudieKling