Issue
I am trying to create a list in Python wherein the elements are Latex entries. I have the following code snippet. I have called "from IPython.display import display, Math, Latex".
lst = [r'$a_1$', r'$a_2$', r'$a_3$', r'$a_4$']
print(lst)
I get ['$a_1$', '$a_2$', '$a_3$', '$a_4$'], but the elements are not "Latexed". Is there something I am missing?
Solution
I believe this can help: How to write LaTeX in IPython Notebook?
Specifically to your problem: you are trying to display a list of latex-formatted strings, which its not a latex formatted string itself; a possible workaround could be something like:
from IPython.display import display, Math, Latex
class LatexList:
def __init__(self, lst) :
self.lst = lst
def __str__(self) :
fl = "["
for exp in self.lst :
fl += exp+","
fl += "]"
return fl
latex_list = LatexList([r'$a_1$', r'$a_2$', r'$a_3$', r'$a_4$'])
display(Math(str(latex_list)))
Now it displays a <IPython.core.display.Math object>
, instead of a list. Of course, how to format the list (i.e. what __str__
does) is up to you to decide!
Answered By - Michele Pellegrino
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.