From mboxrd@z Thu Jan 1 00:00:00 1970 From: Federico Beffa Subject: Re: latex equations and $ sign Date: Wed, 9 Jul 2014 15:32:52 +0200 Message-ID: References: <87oay6i0wn.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c1a3d8c1df2704fdc2bebb Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4rzU-0006uI-Vk for emacs-orgmode@gnu.org; Wed, 09 Jul 2014 09:33:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X4rzS-0005Ja-C9 for emacs-orgmode@gnu.org; Wed, 09 Jul 2014 09:32:56 -0400 Received: from mail-la0-x22d.google.com ([2a00:1450:4010:c03::22d]:53470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4rzR-0005JO-Pf for emacs-orgmode@gnu.org; Wed, 09 Jul 2014 09:32:54 -0400 Received: by mail-la0-f45.google.com with SMTP id hr17so5051625lab.18 for ; Wed, 09 Jul 2014 06:32:52 -0700 (PDT) In-Reply-To: <87oay6i0wn.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --001a11c1a3d8c1df2704fdc2bebb Content-Type: text/plain; charset=UTF-8 Hi Jorge, thanks for your suggestion. The reason that made me try :wrap EQUATION instead of :wrap LaTeX is that the former still produces an output even with other back-ends, while the latter only produces an output with LaTeX and nothing with other back-ends. If org-mode does not recognize math environments and always surrounds sub- and superscripts with $ signs with no way to stop this, then it essentially stops people from using numbered equations and still preserving the capability to export in multiple formats. Org-mode is great, but I find that this sounds as problematic for people writing texts including a lot of mathematical expressions. I guess I will have to dig into filters. Regards, Fede On Fri, Jun 6, 2014 at 4:10 PM, Jorge A. Alfaro-Murillo < jorge.a.alfaro@gmail.com> wrote: > > Federico Beffa 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. > > > --001a11c1a3d8c1df2704fdc2bebb Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Jorge,

thanks for your sugg= estion. The=20 reason that made me try :wrap EQUATION instead of :wrap LaTeX is that=20 the former still produces an output even with other back-ends, while the latter only produces an output with LaTeX and nothing with other=20 back-ends.

If org-mode=20 does not recognize math environments and always surrounds sub- and=20 superscripts with $ signs with no way to stop this, then it essentially=20 stops people from using numbered equations and still preserving the=20 capability to export in multiple formats.

Org-mode is great= , but I find that this sounds as problematic for people writing texts inclu= ding a lot of mathematical expressions.

I guess I w= ill have to dig into filters.

Regards,
Fede

On Fri, Jun 6, 2014 at 4:10 PM, Jorge A. Alfaro-Murillo &= lt;jorge.a.al= faro@gmail.com> wrote:

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 =3D sp.symbols('E, m, c', real=3DTrue, positive=3DTrue= )
> E =3D 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 insid= e
#+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
=C2=A0 import sympy as sp
=C2=A0 E, m, c =3D sp.symbols('E, m, c', real=3DTrue, positive=3DTr= ue)
=C2=A0 E =3D m*c**2
=C2=A0 return "\\begin{equation}\n" + str(sp.latex(E)) + &q= uot;\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
=C2=A0 import sympy as sp
=C2=A0 def org_equation(the_equation):
=C2=A0 =C2=A0 =C2=A0 return "\\begin{equation}\n" + str(sp.latex(= the_equation)) + "\n\\end{equation}\n"

=C2=A0 E, m, c =3D sp.symbols('E, m, c', real=3DTrue, positive=3DTr= ue)
=C2=A0 E =3D m*c**2
=C2=A0 return org_equation(E)
#+END_SRC

Best,

Jorge.



--001a11c1a3d8c1df2704fdc2bebb--