Skip to main content

[Python] Notebook-11 如何從文檔漂亮輸出SymPy符號運算式? How to pretty print the symbolic arithmetic of SymPy with scripts?


這一篇不是典型的上課筆記,
是我在嘗試輸出符號運算結果屢屢遇到障礙時的解法紀錄。
This is not a typical class note. It is a lesson learned that I figured out (or found) as I was floundering in the pool of printing pretty outputs. 

在這一篇文章Python 符号计算的瑞士军刀——SymPy中,
有提到如何輸出漂亮的符號運算式。
但是有其限制—深色主題下會看不清輸出結果。

In this article, Python 符号计算的瑞士军刀——SymPy, it shows you the way to pretty print the arithmetic outputs. However, there is a limitation—low readability under dark themes.



而且原文的輸出結果其實是來自IConsole而不是Editor,
不加一些命令的話是跑不出原文的結果的。

Besides, the author worked with the IPython console rather than with Editor (or script). You shall not see the output that you expect without adding some more commands.



解決第二個問題容易一些,
只要加上display()就可以了。
(參考資料: spyder-sympy-won't-print-symbolic-math

The second problem is easier to resolve. You just put on display(). And we are done. (Reference: spyder-sympy-wont-print-symbolic-math)

第一個問題其實也是在Stackoverflow獲得解答。
只要先安裝Miktex
再於Editor裡增加下面這兩行代碼,
就可以順利在暗色系主題中輸出清晰可見的運算式了。
(參考資料: control-latex-expression-color-in-ipython-qtconsole

Luckily, we could also find the answer to the first problem on Stackoverflow. The only thing we need to do is insert the two line of codes.
from sympy import init_printing
init_printing(use_latex = True, forecolor = "Color you want", backcolor = "Color you want") 


Comments

Popular posts from this blog

[申辦綠卡] EB-2 NIW 國家利益豁免綠卡申請教學(一)找合作的律師事務所

Image by  David Peterson  from  Pixabay

[申辦綠卡] EB-2 NIW 國家利益豁免綠卡申請教學(零)名詞解釋 Petitioner vs Applicant

Image by  David Peterson  from  Pixabay

[申辦綠卡] EB-2 NIW 國家利益豁免綠卡申請教學(七)組裝 NIW I-140 申請文件包

Image by  David Peterson  from  Pixabay