问题
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!
回答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
Create a local MathJax installation (See ipython docs)
Modify the local MathJax installation with a custom configuration file and tex macros. (References provided below)
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.
来源:https://stackoverflow.com/questions/23129840/newcommand-environment-when-convert-from-markdown-to-pandoc