Here's a version that uses Markdown with included LaTeX rather than the other way around. Some weirdness with PDF rendering though, as these 2 pdf outputs show.