OK.
Did it work with the example given on the page (which modifies the manner of printing vectors)? I believe that is the original use case that John Jones wrote it for.
I can't troubleshoot the macro right this minute and as Alex points out this macro, written before MathJax mode existed, may no longer be the best way to handle this situation. I think I can answer your last two questions however.
$rh_envir (the rh is supposed to stand for reference-to-a-hash) is an anonymous hash passed into the PG environment. It is then unpacked into a regular hash (named) %envir in the file pg/macros/PG.pl so as to be more conveniently available.
Some of the macro files (and some PG problems) use $rh_envir directly, possibly because it is less likely that the contents have been modified from within a PG problem, or possibly for no particular reason -- just that it is available.
addTeXPreamble("TeXcommand_here") is a method which means that it requires an object in order to get its job done. For example it has to store this TeX command somewhere and the object gives it the information needed as to where to store it. The image generator object (which knows how to use this method) is $rh_envir->{imagegen} and one of these image generator objects is created for each PG problem.
Since perl shows you how things work "under the hood" it demystifies the concept of "object method" somewhat.
$rh_evir->{imagegen}>addTeXPreamble("TeXcommand_here") translates into a subroutine call of the
form WeBWorK::PG::ImageGenerator::addToTeXPreamble()($rh_envir->{imagegen}, "TeXcommand_here"). Methods are merely subroutines whose first step is to accept a "$self" object.
If a subroutine in a package starts with
my $self = shift; it's a method and called by $obj->subroutine_name() syntax. If it doesn't it's a function and called via subroutine_name() (with the package name prepended if necessary).