connorferster / handcalcs

Python library for converting Python calculations into rendered latex.
Apache License 2.0
5.68k stars 434 forks source link

NameError: name 'theta_A' is not defined #219

Open k4sh4n1 opened 2 months ago

k4sh4n1 commented 2 months ago

I have these cells on a notebook:

import handcalcs.render
import forallpeople
forallpeople.environment('structural', top_level=True)
from sympy import *
%%render sympy
theta_A # Parameter
L # Parameter
Delta_B # Parameter

But I'm receiving this error:

NameError: name 'theta_A' is not defined

2024-09-05 07_36_53-lab (2) - JupyterLab - Opera

Question

Symbolic equations

I have studied this post: https://github.com/connorferster/handcalcs/issues/22#issuecomment-703406581 But it's too complex.

I just simply want to display symbolic equations. How can I do that? I'm confused 😕

Klummel69 commented 2 months ago

You should familiarize yourself with how sympy works. You must first assign sympy objects to the variables, e.g.

import sympy as sp
theta_A = sp.symbols("theta_A")
L = sp.symbols("L")
Delta_B = sp.symbols("Delta_B")

As described in the README of handcalcs, Sympy does not need handcalcs to render the equations. Only if the equations are to be calculated in handcalcs style at the end, handcalc makes sense. See example in the README.