# Export org file to html and latex

I want to use only one org file to export both .tex and .html.

I use begin_latex in my org files to embed maths and I can use C-c ' to use the org-edit-src-code feature which help fast typing latex(Thus I can use Auctex and more). But it seems that the contents in begin_latex will not be formatted into equations when exporting to html.

After I read the org manual, I know that latex code can be embedded without begin_latex, and can be export to both html and tex. In this situation, I have to use cdlatex to type latex in a org file and can not use the org-edit-src-code feature, which means that I lost the latex code highlighting when typing. That really annoys me.

• What I do in this case: #+begin_src latex ... #+end_src and then use the by-backend macro to export the LaTeX code depending on what back-end is currently active. For example see my question here: emacs.stackexchange.com/questions/19419/… (also note the related problems). Jan 23 '16 at 14:33

You can write the code in a begin_src latex block with :results drawer :export results in the header. Here is an example:

#+begin_src latex :results drawer :exports results
$\frac{1}{2}$
#+end_src


This way you can edit the latex with full editor support and end up with raw latex. Best of both worlds!

• Thanks for your answer! Looks great! It seems that I should add an org template for writing this :result thing quickly. Now I find a new question like org-html-export-does-not-recognize-custom-latex-macros. Is there an elegant way to share the custom latex commands in both latex and html export ? Jan 24 '16 at 0:50
• I guess you need to read docs.mathjax.org/en/latest/tex.html
– Ista
Jan 24 '16 at 4:35
• Seems that adjusting org-html-mathjax-template is needed, thanks for your hints! Jan 24 '16 at 5:43