andrewheiss / SublimeKnitr

Plugin that adds knitr Markdown and LaTeX support in Sublime Text 2 and 3
71 stars 11 forks source link

Can I use Latex and Markdown simultaneously? #14

Closed ernestyao closed 10 years ago

ernestyao commented 10 years ago

I love Rmarkdown. But sometimes I have to use latex in Rmd to write some formula. I tried like

$$latex f(x;\mu,\sigma^2) = \frac{1}{\sigma\sqrt{2\pi}} e^{ -\frac{1}{2}\left(\frac{x-\mu}{\sigma}\right)^2 } $$

It does not work. How can I get results like this? I don't use Rnw since I don't know latex a lot and formula are seldom in my paper. Thanks in advance.

andrewheiss commented 10 years ago

Yep. See the R Markdown documentation. The ST package won't do syntax highlighting for LaTeX like that, but it should compile just fine with knitr.

ernestyao commented 10 years ago

Thanks for your reply. But when I build the .Rmd file, got the same latex code block in .md file. Markdown Preview can't display it in equation form. What else should I do? I'm using LatexTools. And I find the modification to LatexTools deals with .Rnw file only.

Update:

I solved it myself. I misunderstood your meaning. It's the browser's job to render inline Latex instead of ST. I found a booklet here can do it: http://web.mit.edu/jcalz/Public/Reddit/mathbookmarklet.html. It works on my Mac with Safari 7.0.2.

andrewheiss commented 10 years ago

Yeah, HTML can't handle LaTeX natively. You can use Pandoc to convert from markdown to HTML and use a template that includes MathJax or something so that it renders the LaTeX automatically when you open the file in a browser. It works natively in RStudio because that's what they do—include MathJax in the preview.