A community-maintained Python framework for creating mathematical animations.
Added docstrings
Philipp Imhofe426662a7c21
diff --git a/manim/utils/tex_file_writing.py b/manim/utils/tex_file_writing.pyindex aa00c3c4c..3e1f03303 100644--- a/manim/utils/tex_file_writing.py+++ b/manim/utils/tex_file_writing.py@@ -22,7 +22,22 @@ def tex_hash(expression):def tex_to_svg_file(expression, environment=None, tex_template=None):- """Takes a tex expression and returns the svg version of the compiled tex"""+ """Takes a tex expression and returns the svg version of the compiled tex++ Parameters+ ----------+ expression : :class:`str`+ String containing the TeX expression to be rendered, e.g. ``\\sqrt{2}`` or ``foo``+ environment : :class:`str`+ The string containing the environment in which the expression should be typeset, e.g. ``align*``+ Optional. If not set, the expression will be rendered in text mode.+ tex_template : :class:`TexTemplate`+ Template class used to typesetting.+ Optional. If not set, the default template will be used.+ Returns+ -------+ Path to generated SVG file.+ """if tex_template is None:tex_template = config["tex_template"]tex_file = generate_tex_file(expression, environment, tex_template)@@ -34,7 +49,22 @@ def tex_to_svg_file(expression, environment=None, tex_template=None):def generate_tex_file(expression, environment, tex_template):"""Takes a tex expression (and an optional tex environment),- and returns a fully formed tex file ready for compilation."""+ and returns a fully formed tex file ready for compilation.++ Parameters+ ----------+ expression : :class:`str`+ String containing the TeX expression to be rendered, e.g. ``\\sqrt{2}`` or ``foo``+ environment : :class:`str`+ The string containing the environment in which the expression should be typeset, e.g. ``align*``+ Optional. If not set, the expression will be rendered in text mode.+ tex_template : :class:`TexTemplate`+ Template class used to typesetting.+ Optional. If not set, the default template will be used.+ Returns+ -------+ Generated TeX file ready for compilation+ """if environment is not None:output = tex_template.get_texcode_for_expression_in_env(expression, environment)else:@@ -49,7 +79,23 @@ def generate_tex_file(expression, environment, tex_template):def tex_compilation_command(tex_compiler, output_format, tex_file, tex_dir):- """Prepares the tex compilation command with all necessary cli flags"""+ """Prepares the tex compilation command with all necessary cli flags++ Parameters+ ----------+ tex_compiler : :class:`str`+ String containing the compiler to be used, e.g. ``pdflatex`` or ``lualatex``+ output_format : :class:`str`+ String containing the output format generated by the compiler, e.g. ``.dvi`` or ``.pdf``+ Optional. If not set, the expression will be rendered in text mode.+ tex_file : :class:`str`+ File name of TeX file to be typeset.+ tex_dir : :class:`str`+ Path to the directory where compiler output will be stored.+ Returns+ -------+ Path to generated output file.+ """if tex_compiler in {"latex", "pdflatex", "luatex", "lualatex"}:commands = [tex_compiler,@@ -84,7 +130,21 @@ def tex_compilation_command(tex_compiler, output_format, tex_file, tex_dir):def tex_to_dvi(tex_file, tex_compiler, output_format):- """Compiles a tex_file into a .dvi or a .xdv or a .pdf"""+ """Compiles a tex_file into a .dvi or a .xdv or a .pdf++ Parameters+ ----------+ tex_file : :class:`str`+ File name of TeX file to be typeset.+ tex_compiler : :class:`str`+ String containing the compiler to be used, e.g. ``pdflatex`` or ``lualatex``+ output_format : :class:`str`+ String containing the output format generated by the compiler, e.g. ``.dvi`` or ``.pdf``+ Optional. If not set, the expression will be rendered in text mode.+ Returns+ -------+ Path to generated output file.+ """result = tex_file.replace(".tex", output_format)result = Path(result).as_posix()tex_file = Path(tex_file).as_posix()@@ -105,7 +165,21 @@ def tex_to_dvi(tex_file, tex_compiler, output_format):def dvi_to_svg(dvi_file, extension, regen_if_exists=False, page=1):- """Converts a .dvi, .xdv, or .pdf file into an svg using dvisvgm."""+ """Converts a .dvi, .xdv, or .pdf file into an svg using dvisvgm.++ Parameters+ ----------+ dvi_file : :class:`str`+ File name of the input file to be converted.+ extension : :class:`str`+ String containing the file extension and thus indicating the file type, e.g. ``.dvi`` or ``.pdf``+ regen_if_exists : `bool`+ Setting if SVG has to be regenerated even if it already exists. Optional, defaulting to False.+ page : `int`+ Page to be converted if input file is multi-page. Optional, defaulting to 1.+ Returns+ -------+ Path to generated SVG file."""result = dvi_file.replace(extension, ".svg")result = Path(result).as_posix()dvi_file = Path(dvi_file).as_posix()