I wanted to put mathjax inside a dialog box in an Anki addon, to show the fraction inside, but when I put it in an addon, unfortunately it doesn’t show.
I don’t know if you need to import a library, so if anyone knows, please let me know, thank you
I had to make the code putting these which are spaces in html, so that one number can be placed on top of another
def show_formula_arranjosimples(self):
n = random.randint(3, 10)
p = random.randint(1, n-1)
example_text = (
f"<span style='color: red;'>Combinatorial Analysis -> Simple Arrangement</span><br>"
f"How many arrangements are there of {n} elements taken from {p} into {p}?<br><br>"
f"An,k = n!<br>"
f" _____<br>"
f" (n-k)!<br><br>"
f"An,k = {n}!<br>"
f" _____<br>"
f" ({n}-{p})!<br><br>"
f"An,k = {n}!<br>"
f" _____<br>"
f" {n-p}!<br><br>"
f"An,k = {n} x {' x '.join(str(i) for i in range(n-1, n-p, -1))} = {self.calculate_arrangement(n, p)}"
)
QMessageBox.information(self, "Simple Arrangement Example", example_text)
def calculate_arrangement(self, n, p):
result = 1
for i in range(n, n-p, -1):
result *= i
return result
########################################
When I try to put mathjax inside a dialog box, it doesn’t work, I tried that and it didn’t work
f"How many arrangements are there of {n} elements taken from {p} into {p}?<br><br>"
f"An,k = \\(\\left(\\frac{{{n!}}}{{{({n}-{p})!}}}\\right)\\)<br> "
########################################
When I put mathjax to work within the front and back fields, it worked normally, as you can see in the code below
def insert_produto_potenciacao_fracao(editor):
# Generate random numbers for numerator, denominator and exponent
numerator = random.randint(1, 9)
denominator = random.randint(1, 9)
while numerator == denominator:
denominator = random.randint(1, 9)
exponent = random.randint(-3, 3)
while exponent == 0:
exponent = random.randint(-3, 3)
# Assembling the expression to the front of the letter
front_text = (f"<b>Power - Fraction</b><br>"
f"<font color='blue'>Solve the following potentiation:<br>\\(\\left(\\frac{{{numerator}}}{{{denominator}}}\\right)^{{{ exponent}}}\\)</font>")
# Calculating development
if exponent > 0:
num_exp = numerator ** exponent
denominator_exp = denominator ** exponent
back_text = (f"<b>Development:</b><br>"
f"\\(\\left(\\frac{{{numerator}}}{{{denominator}}}\\right)^{{{exponent}}} = \\frac{{{numerator}^{{ {exponent}}}}}{{{denominator}^{{{exponent}}}}} = \\frac{{{num_exp}}}{{{denom_exp}}}\\) ")
else:
inverse_numerator = denominator
inverse_denominator = numerator
positive_exponent = abs(exponent)
num_exp = inverse_numerator ** positive_exponent
denom_exp = inverse_denominator ** positive_exponent
back_text = (f"<b>Development:</b><br>"
f"\\(\\left(\\frac{{{numerator}}}{{{denominator}}}\\right)^{{{exponent}}} = \\left(\\frac{{{inverse_numerator }}}{{{inverse_denominator}}}\\right)^{{{positive_exponent}}} = "
f"\\frac{{{inverse_numerator}^{{{positive_exponent}}}}}{{{inverse_denominator}^{{{positive_exponent}}}}} = \\frac{{{num_exp}}}{{{denom_exp }}}\\)")