emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* SymPy equations + displayed equation + label = difficult?
@ 2021-03-23 16:21 autofrettage
  0 siblings, 0 replies; only message in thread
From: autofrettage @ 2021-03-23 16:21 UTC (permalink / raw)
  To: emacs-orgmode

Hi all,

I have tried to use SymPy in Org Mode code blocks, export LaTeX
expressions to displayed equations, and refer to those with
labels. My current solution is ugly, which has left me with a
strong feeling that there must be a better way.

Sensitive Org Mode users are warned. Here comes a brief
description of my current solution.

* The equation is defined inside a SymPy block, e.g.:

   a, R, L = symbols('\\alpha R L')
   equ = Eq(R, L * sin(a))

* The LaTeX representation for equ, and the rest of the LaTeX
  code needed for producing a displayed equation, with a label,
  are generated with the Python function expequ:

  #+BEGIN_SRC python :session :results none :exports none
  def expequ(expr, label):
     # will write out code for export of SymPy equation
     expression = latex(expr, mode="plain")
     \\end{equation}""" % {'expr': expression, 'label': label})

* At the place where I want to display equ, I call expequ like

  #+HEADER:  :results output latex overwrite :exports results
  #+BEGIN_SRC python :session

* ...which yields:

  #+BEGIN_EXPORT latex
     R = L \sin{\left(\alpha \right)}

How many painfully obvious solutions have I missed?


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-23 16:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23 16:21 SymPy equations + displayed equation + label = difficult? autofrettage

Code repositories for project(s) associated with this public inbox


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