Mathjax renders badly

You are calling JavaScript in your card template to define custom MathJax macros. Calling getComponents() more than once causes MathJax to get confused, so as described in the link above, you must add a check to only call it once.