emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: autofrettage <autofrettage@protonmail.ch>
To: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: SymPy equations + displayed equation + label = difficult?
Date: Tue, 23 Mar 2021 16:21:03 +0000	[thread overview]
Message-ID: <d5r-KGZtzvxADwGx3rMPzvXicGSbcHl3CIw8pGd8dmZKH6oSl_3SpNyCfkZfzO5hmGYnCBHDOmyipjg2K3G7t1zY8Y9Pg4BAnpLusxArkTc=@protonmail.ch> (raw)

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	other threads:[~2021-03-23 16:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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='d5r-KGZtzvxADwGx3rMPzvXicGSbcHl3CIw8pGd8dmZKH6oSl_3SpNyCfkZfzO5hmGYnCBHDOmyipjg2K3G7t1zY8Y9Pg4BAnpLusxArkTc=@protonmail.ch' \
    --to=autofrettage@protonmail.ch \
    --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).