Last active
August 2, 2023 09:07
-
-
Save abul4fia/475577ef58e4cd3babc2028be7f960fa to your computer and use it in GitHub Desktop.
Latex items environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This module implements class LatexItems which is useful as an alternative | |
to manim's BulletedList. | |
Unless BulletedList, LatexItems uses standard latex itemize environment to | |
typeset the text and the bullets. The width of the paragraphs can be customized | |
as well as the kind of environment (itemize, enumerate, or description) | |
""" | |
from manim import Tex, TexTemplate | |
class LatexItems(Tex): | |
def __init__(self, *args, page_width="15em", itemize="itemize", ragged="", **kwargs): | |
""" | |
*args is a sequence of strings to be typeset by latex. The expected usage is that | |
each of these strings starts by r"\item " | |
page_width is the width of the minipage in which the environment will be typeset | |
it is recommended to use "em" as unit (being 1em the width of letter m) | |
itemize is the environment to use. It can be "itemize", "enumerate" or "description" | |
The last one requires each item to be followed by the term to be defined in | |
square brackets, eg: r"\item[Foo] this is a foo" | |
ragged is an optional command that will be inserted at the beginning of the minipage | |
environment. Its intended usage is to provide r"\raggedright" to avoid the hyphenation | |
and full-justification of the paragraphs | |
EXAMPLE: | |
items = LatexItems(r"\item Foo", r"\item Bar", r"\item Foobar") | |
for item in items: | |
self.play(Write(item)) | |
""" | |
template = TexTemplate() | |
template.body = (r"\documentclass[preview]{standalone}\usepackage[english]{babel}" | |
r"\usepackage{amsmath}\usepackage{amssymb}\begin{document}" | |
rf"\begin{{minipage}}{{{page_width}}}{ragged}" | |
rf"\begin{{{itemize}}}YourTextHere\end{{{itemize}}}" | |
r"\end{minipage}\end{document}" | |
) | |
super().__init__(*args, tex_template=template, tex_environment=None, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment