0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【小ネタ】Django+sympy+MathJaxでシグマ記号の横ではなく、上下に数字を表示する【備忘録】

Last updated at Posted at 2023-10-26

前書き

例のごとく作成中の計算練習用のサイトで、少し詰まったところがあったので備忘録代わりに記録しておきます。

Σ記号の右側ではなく、上下に

sympyでは数列の和はsy.Sumを用いて以下のように表現できます。

series1.py
import sympy as sy

k = sy.Symbol("k")
n = sy.Symbol("n")
start = 1
end = n
function = -k ** 3 + 3 * k ** 2 + 3
series = sy.Sum(function, (k, start, end))
latex_series = sy.latex(series)

ですが、このままですと、以下の画像のように右側に文字と値が表示されてしまいます。

side.PNG

これを防止するには、以下のように\displaystyleを手前において、表示形式を指定すればよいです。

series2.py
latex_series = f"\\displaystyle {sy.latex(series)}"

up_and_bottom.PNG

後書き

地味なところですし、別に意味は同じですが、高校生を対象としているため、教科書と同じ形にそろえることを重視しました。実現できてよかったです。

参考サイト様

Texで総和(summation)を表すシグマの上付き下付き文字がちゃんと上と下にいかない時は

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?