4

I use ipython notebook to type math and then convert to latex. To make mathjax understand \newcommand, I have to put it inside $...$. For example, $\newcommand{\cl}{\operatorname{cl}}$ works well with mathjax. The problem is that when I convert to tex file using pandoc, it is still $\newcommand{\cl}{\operatorname{cl}}$ there, but what I want is just \newcommand{\cl}{\operatorname{cl}} (no $...$). Is there anyone please show me how to solve this problem?

Thank you very much in advance!

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
Du Phan
  • 231
  • 2
  • 8
  • Hi have you tried to take a look at the "Verbatim code blocks" section of the [pandoc documentation](http://johnmacfarlane.net/pandoc/demo/example9/pandocs-markdown.html) ? – Stéphane Laurent Apr 17 '14 at 11:04
  • @StéphaneLaurent: I tried but it seems that code blocks not work with mathjax. If I want `\newcommand...` in the tex file, I just type exactly the same in markdown (so code block is not important in my opinion). `$\newcommand...$` when is converted to tex file using pandoc, then compile just cause error. – Du Phan Apr 17 '14 at 14:56
  • Minmal working example? – Thell Apr 17 '14 at 16:03
  • What do you mean by "code block don't work with mathjax" ? You want to convert your md file in html too ? – Stéphane Laurent Apr 17 '14 at 16:46
  • @StéphaneLaurent: I think that you have get my point. I didn't notice that. I type math in ipython notebook and it seems that ipython notebook converts markdown to html. Could you find any solution for this? Thanks! – Du Phan Apr 17 '14 at 17:10
  • Use the command line `pandoc -f markdown myfile.md -o myfile.tex`. I don't know ipython by the way. – Stéphane Laurent Apr 17 '14 at 18:11

1 Answers1

1

One easy option is to use latex magic to use latex environments within ipython.

For instance, here is an example

%%latex \begin{aligned} \nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\ \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\ \nabla \cdot \vec{\mathbf{B}} & = 0 \end{aligned}

Alternatively, the only solution to using full blown latex within markdown cells is to use a configuration file for creating tex Macros in MathJax instead of overloading $...$.

First

  1. Create a local MathJax installation (See ipython docs)

  2. Modify the local MathJax installation with a custom configuration file and tex macros. (References provided below)

  3. Tell ipython to use your local-modified MathJax installation using

     python -m IPython.external.mathjax -d /some/other/mathjax
    

Modifying MathJax Installation

Here is a relevant snippet from the MathJax Documentation

If you have many such definitions that you want to use on more than one page, you could put them into a configuration file that you can load along with the main configuration file. For example, you could create a file in MathJax/config/local called local.js that contains your macro definitions:

MathJax.Hub.Config({   
  TeX: {
    Macros: {
     RR: "{\\bf R}",
     bold: ["{\\bf #1}",1]
}   } });

MathJax.Ajax.loadComplete("[MathJax]/config/local/local.js"); and then load it along with your main configuration file on the script that loads MathJax.js:

<script src="/MathJax/MathJax.js?config=TeX-AMS_HTML,local/local.js"></script>

If you are using the CDN, you can make a local configuration file on your own server, and load MathJax itself from the CDN and your configuration file from your server. See Using a Local Configuration File with the CDN for details.

user1375
  • 159
  • 1
  • 7