emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: jorge.a.alfaro@gmail.com (Jorge A. Alfaro-Murillo)
To: emacs-orgmode@gnu.org
Subject: Re: latex equations and $ sign
Date: Fri, 06 Jun 2014 10:10:48 -0400	[thread overview]
Message-ID: <87oay6i0wn.fsf@gmail.com> (raw)
In-Reply-To: CAKrPhPOde-ABMYYB0Y7hfJvy7Qp32Y9p-HzDkqekq-=5W2Gm9g@mail.gmail.com


Federico Beffa <beffa@ieee.org> 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	other threads:[~2014-06-06 14:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-06 10:47 latex equations and $ sign Federico Beffa
2014-06-06 14:10 ` Jorge A. Alfaro-Murillo [this message]
2014-07-09 13:32   ` Federico Beffa
2014-06-06 15:00 ` Rasmus
2014-07-09 13:31   ` Federico Beffa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oay6i0wn.fsf@gmail.com \
    --to=jorge.a.alfaro@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).