emacs-orgmode
[Top][All Lists]
Advanced

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

SymPy equations + displayed equation + label = difficult?


From: autofrettage
Subject: SymPy equations + displayed equation + label = difficult?
Date: Tue, 23 Mar 2021 16:21:03 +0000

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")
     print("""
     \\begin{equation}
        \\label{%(label)s}
        %(expr)s
     \\end{equation}""" % {'expr': expression, 'label': label})
  #+END_SRC

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

  #+HEADER:  :results output latex overwrite :exports results
  #+BEGIN_SRC python :session
     expequ(equ2,"equ:labeltest")
  #+END_SRC

* ...which yields:

  #+RESULTS:
  #+BEGIN_EXPORT latex
  \begin{equation}
     \label{equ:labeltest}
     R = L \sin{\left(\alpha \right)}
  \end{equation}
  #+END_EXPORT

How many painfully obvious solutions have I missed?

Yours
Rasmus




reply via email to

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