Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
0 votes

I am attempting to use SympyBridge to simplify a somewhat involved algebraic expression and it appears to be throwing a python error. Here is the notebook

https://drive.google.com/file/d/16jcPyMk7OkSsiShWLiYIw_7ng7-MUdFG/view?usp=sharing

The error message  after the call to SympyBridge is

\begin{verbatim}TokenError: ('unexpected character after line continuation character', (1, 82))

At:   /usr/lib/python3.12/tokenize.py(582): _generate_tokens_from_c_tokenizer   /usr/lib/python3/dist-packages/sympy/parsing/sympy_parser.py(891): stringify_expr   /usr/lib/python3/dist-packages/sympy/parsing/sympy_parser.py(1072): parse_expr   Notebook Cell (Line 1): ex_sympy = sbb.to_sympy() \end{verbatim}

I have used SympyBridge on simpler expressions like those in the Cadabra Book and it works fine....

ago in General questions by (160 points)

1 Answer

0 votes

It chokes on the backslash in the \Dg, because Python does not like backslashes in variable names. All "normal" LaTeX symbols get (e.g. \alpha) get their backslash stripped and then re-instated afterwards, but if you use custom symbols that will not work.

Since you are already using a LaTeXForm to make the output look nice, I would just use Dg instead of \Dg everywhere. That will work.

ago by (86.7k points)

Thanks Kasper that works

...