emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] latex equations and $ sign


From: Jorge A. Alfaro-Murillo
Subject: Re: [O] latex equations and $ sign
Date: Fri, 06 Jun 2014 10:10:48 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Federico Beffa <address@hidden> writes:

> Hi,
>
> I would like to have a mathematical equation typeset in latex and
> automatically generated by sympy, embedded in an equation environment:
>
> #+NAME: mass-energy
> #+BEGIN_SRC python :results raw :exports results :wrap EQUATION
> import sympy as sp
> E, m, c = sp.symbols('E, m, c', real=True, positive=True)
> E = m*c**2
> return sp.latex(E)
> #+END_SRC
>
> #+NAME: eq:1
> #+RESULTS: mass-energy
> #+BEGIN_EQUATION
> c^{2} m
> #+END_EQUATION
>
> The problem I'm facing is that despite the fact that the equation is
> already in a mathematical mode latex environment, it still gets sub-
> and superscripts surrounded by a $ sign. Here is the generated latex
> snippet:
>
> \begin{equation}
> \label{eq:1}
> c$^{\text{2}}$ m
> \end{equation}
>
> Is there a way to teach org-mode not to insert $ signs in equation
> environments?
>
> Thanks,
> Fede

Hi Federico,

I don't think that Org has a way to know that you want everything inside
#+BEGIN_EQUATION and #+END_EQUATION to be an equation in LaTeX, if
instead of EQUATION you write CENTER it does a \begin{center}
\end{center}. So by default it tries to produce text.

I would change your code to:

#+NAME: mass-energy
#+BEGIN_SRC python :results raw :exports results :wrap LaTeX
  import sympy as sp
  E, m, c = sp.symbols('E, m, c', real=True, positive=True)
  E = m*c**2
  return "\\begin{equation}\n" + str(sp.latex(E)) + "\n\\end{equation}\n"
#+END_SRC

which produces:

#+RESULTS: mass-energy
#+BEGIN_LaTeX
\begin{equation}
c^{2} m
\end{equation}
#+END_LaTeX

and gets exported to LaTeX as an equation. 

In fact if you use it often, you could make a function in python:

#+NAME: mass-energy
#+BEGIN_SRC python :results raw :exports results :wrap LaTeX
  import sympy as sp
  def org_equation(the_equation):
      return "\\begin{equation}\n" + str(sp.latex(the_equation)) + 
"\n\\end{equation}\n"

  E, m, c = sp.symbols('E, m, c', real=True, positive=True)
  E = m*c**2
  return org_equation(E)
#+END_SRC

Best,

Jorge.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]