Don't call `gsub` on a `SafeBuffer`.
Don't call `gsub` on a `SafeBuffer`.

SafeBuffer#gsub doesn't set backreferences ($1, $2, etc...) correctly
due to https://github.com/rails/rails/issues/1555 .  Avoid that by
converting the SafeBuffer to a String using `to_str` (not `to_s`, which
returns another SafeBuffer).

baierjan/rails-latex,amagical-net/rails-latex