*latex equations and $ sign@ 2014-06-06 10:47 Federico Beffa2014-06-06 14:10 ` Jorge A. Alfaro-Murillo 2014-06-06 15:00 ` Rasmus 0 siblings, 2 replies; 5+ messages in thread From: Federico Beffa @ 2014-06-06 10:47 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 830 bytes --] 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 [-- Attachment #2: Type: text/html, Size: 1090 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread

*Re: latex equations and $ sign2014-06-06 10:47 latex equations and $ sign Federico Beffa@ 2014-06-06 14:10 ` Jorge A. Alfaro-Murillo2014-07-09 13:32 ` Federico Beffa 2014-06-06 15:00 ` Rasmus 1 sibling, 1 reply; 5+ messages in thread From: Jorge A. Alfaro-Murillo @ 2014-06-06 14:10 UTC (permalink / raw) To: emacs-orgmode 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. ^ permalink raw reply [flat|nested] 5+ messages in thread

*Re: latex equations and $ sign2014-06-06 10:47 latex equations and $ sign Federico Beffa 2014-06-06 14:10 ` Jorge A. Alfaro-Murillo@ 2014-06-06 15:00 ` Rasmus2014-07-09 13:31 ` Federico Beffa 1 sibling, 1 reply; 5+ messages in thread From: Rasmus @ 2014-06-06 15:00 UTC (permalink / raw) To: emacs-orgmode 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? Is there a reason you are not using a mode argument like this: #+NAME: mass-energy #+BEGIN_SRC python :results raw :exports results :post import sympy as sp E, m, c = sp.symbols('E, m, c', real=True, positive=True) E = m*c**2 return sp.latex(E, mode="inline") #+END_SRC #+RESULTS: mass-energy $c^{2} m$ Alternatively, if you need to combine stuff you could use the post argument #+name: wrapper #+BEGIN_SRC emacs-lisp :var x="" (format "\\(%s\\)" x) #+END_SRC #+NAME: mass-energy #+BEGIN_SRC python :results raw :exports results :post wrapper(x=*this*) 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 #+RESULTS: mass-energy \(c^{2} m\) —Rasmus -- El Rey ha muerto. ¡Larga vida al Rey! ^ permalink raw reply [flat|nested] 5+ messages in thread

*2014-06-06 15:00 ` RasmusRe: latex equations and $ sign@ 2014-07-09 13:31 ` Federico Beffa0 siblings, 0 replies; 5+ messages in thread From: Federico Beffa @ 2014-07-09 13:31 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 2383 bytes --] Hi Ramus, yes, the reason is that, differently from $...$ and \(...\), an equation environment produces a *numbered* equation to which you can add a label and reference the equation by (label) name in other parts of the text. This is not possibly with unnumbered math environments ($$, ...). Regards, Fede On Fri, Jun 6, 2014 at 5:00 PM, Rasmus <rasmus@gmx.us> 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 = 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? > > Is there a reason you are not using a mode argument like this: > > #+NAME: mass-energy > #+BEGIN_SRC python :results raw :exports results :post > import sympy as sp > E, m, c = sp.symbols('E, m, c', real=True, positive=True) > E = m*c**2 > return sp.latex(E, mode="inline") > #+END_SRC > > #+RESULTS: mass-energy > $c^{2} m$ > > > Alternatively, if you need to combine stuff you could use the post > argument > > #+name: wrapper > #+BEGIN_SRC emacs-lisp :var x="" > (format "\\(%s\\)" x) > #+END_SRC > > #+NAME: mass-energy > #+BEGIN_SRC python :results raw :exports results :post > wrapper(x=*this*) > 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 > > #+RESULTS: mass-energy > \(c^{2} m\) > > —Rasmus > > -- > El Rey ha muerto. ¡Larga vida al Rey! > > > [-- Attachment #2: Type: text/html, Size: 3426 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread

*Re: latex equations and $ sign2014-06-06 14:10 ` Jorge A. Alfaro-Murillo@ 2014-07-09 13:32 ` Federico Beffa0 siblings, 0 replies; 5+ messages in thread From: Federico Beffa @ 2014-07-09 13:32 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 2995 bytes --] 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 <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. > > > [-- Attachment #2: Type: text/html, Size: 4236 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-07-09 13:33 UTC | newest]Thread overview:5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-06-06 10:47 latex equations and $ sign Federico Beffa 2014-06-06 14:10 ` Jorge A. Alfaro-Murillo 2014-07-09 13:32 ` Federico Beffa 2014-06-06 15:00 ` Rasmus 2014-07-09 13:31 ` Federico Beffa

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).