Skip to content

Commit 51f54e1

Browse files
authored
Merge pull request #3 from PhilippImhof/pr-483
Pr 483
2 parents 35c8bf0 + 3516df5 commit 51f54e1

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

manim/utils/tex.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,37 +103,28 @@ def prepend_to_preamble(self, txt):
103103
----------
104104
txt : :class:`str`
105105
String containing the text to be added, e.g. ``\\usepackage{siunitx}``
106-
Returns
107-
-------
108-
None
109106
"""
110107
self.preamble = txt + "\n" + self.preamble
111108
self.rebuild()
112109

113110
def add_to_preamble(self, txt):
114-
"""Adds txt to the TeX template preamble just before \begin{document}
111+
"""Adds txt to the TeX template preamble just before \\begin{document}
115112
116113
Parameters
117114
----------
118115
txt : :class:`str`
119116
String containing the text to be added, e.g. ``\\usepackage{hyperref}``
120-
Returns
121-
-------
122-
None
123117
"""
124118
self.preamble += "\n" + txt
125119
self.rebuild()
126120

127121
def add_to_document(self, txt):
128-
"""Adds txt to the TeX template just after \begin{document}
122+
"""Adds txt to the TeX template just after \\begin{document}, e.g. ``\\boldmath``
129123
130124
Parameters
131125
----------
132126
txt : :class:`str`
133127
String containing the text to be added.
134-
Returns
135-
-------
136-
None
137128
"""
138129
self.post_doc_commands += "\n" + txt + "\n"
139130
self.rebuild()
@@ -145,6 +136,7 @@ def get_texcode_for_expression(self, expression):
145136
----------
146137
expression : :class:`str`
147138
The string containing the expression to be typeset, e.g. ``$\\sqrt{2}$``
139+
148140
Returns
149141
-------
150142
:class:`str`
@@ -161,6 +153,7 @@ def get_texcode_for_expression_in_env(self, expression, environment):
161153
The string containing the expression to be typeset, e.g. ``$\\sqrt{2}$``
162154
environment : :class:`str`
163155
The string containing the environment in which the expression should be typeset, e.g. ``align*``
156+
164157
Returns
165158
-------
166159
:class:`str`

manim/utils/tex_file_writing.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ def tex_to_svg_file(expression, environment=None, tex_template=None):
2828
----------
2929
expression : :class:`str`
3030
String containing the TeX expression to be rendered, e.g. ``\\sqrt{2}`` or ``foo``
31-
environment : :class:`str`
31+
environment : Optional[:class:`str`], optional
3232
The string containing the environment in which the expression should be typeset, e.g. ``align*``
33-
Optional. If not set, the expression will be rendered in text mode.
34-
tex_template : :class:`TexTemplate`
35-
Template class used to typesetting.
36-
Optional. If not set, the default template will be used.
33+
tex_template : Optional[:class:`TexTemplate`], optional
34+
Template class used to typesetting. If not set, use default template set via `config["tex_template"]`
35+
3736
Returns
3837
-------
39-
Path to generated SVG file.
38+
:class:`str`
39+
Path to generated SVG file.
4040
"""
4141
if tex_template is None:
4242
tex_template = config["tex_template"]
@@ -47,24 +47,26 @@ def tex_to_svg_file(expression, environment=None, tex_template=None):
4747
return convert_to_svg(dvi_file, tex_template.output_format)
4848

4949

50-
def generate_tex_file(expression, environment, tex_template):
50+
def generate_tex_file(expression, environment=None, tex_template=None):
5151
"""Takes a tex expression (and an optional tex environment),
5252
and returns a fully formed tex file ready for compilation.
5353
5454
Parameters
5555
----------
5656
expression : :class:`str`
5757
String containing the TeX expression to be rendered, e.g. ``\\sqrt{2}`` or ``foo``
58-
environment : :class:`str`
58+
environment : Optional[:class:`str`], optional
5959
The string containing the environment in which the expression should be typeset, e.g. ``align*``
60-
Optional. If not set, the expression will be rendered in text mode.
61-
tex_template : :class:`TexTemplate`
62-
Template class used to typesetting.
63-
Optional. If not set, the default template will be used.
60+
tex_template : Optional[:class:`TexTemplate`], optional
61+
Template class used to typesetting. If not set, use default template set via `config["tex_template"]`
62+
6463
Returns
6564
-------
66-
Generated TeX file ready for compilation
65+
:class:`string`
66+
Path to generated TeX file
6767
"""
68+
if tex_template is None:
69+
tex_template = config["tex_template"]
6870
if environment is not None:
6971
output = tex_template.get_texcode_for_expression_in_env(expression, environment)
7072
else:
@@ -87,14 +89,15 @@ def tex_compilation_command(tex_compiler, output_format, tex_file, tex_dir):
8789
String containing the compiler to be used, e.g. ``pdflatex`` or ``lualatex``
8890
output_format : :class:`str`
8991
String containing the output format generated by the compiler, e.g. ``.dvi`` or ``.pdf``
90-
Optional. If not set, the expression will be rendered in text mode.
9192
tex_file : :class:`str`
9293
File name of TeX file to be typeset.
9394
tex_dir : :class:`str`
9495
Path to the directory where compiler output will be stored.
96+
9597
Returns
9698
-------
97-
Path to generated output file.
99+
:class:`str`
100+
Compilation command according to given parameters
98101
"""
99102
if tex_compiler in {"latex", "pdflatex", "luatex", "lualatex"}:
100103
commands = [
@@ -140,10 +143,11 @@ def compile_tex(tex_file, tex_compiler, output_format):
140143
String containing the compiler to be used, e.g. ``pdflatex`` or ``lualatex``
141144
output_format : :class:`str`
142145
String containing the output format generated by the compiler, e.g. ``.dvi`` or ``.pdf``
143-
Optional. If not set, the expression will be rendered in text mode.
146+
144147
Returns
145148
-------
146-
Path to generated output file.
149+
:class:`str`
150+
Path to generated output file in desired format (DVI, XDV or PDF).
147151
"""
148152
result = tex_file.replace(".tex", output_format)
149153
result = Path(result).as_posix()
@@ -173,13 +177,15 @@ def convert_to_svg(dvi_file, extension, regen_if_exists=False, page=1):
173177
File name of the input file to be converted.
174178
extension : :class:`str`
175179
String containing the file extension and thus indicating the file type, e.g. ``.dvi`` or ``.pdf``
176-
regen_if_exists : `bool`
177-
Setting if SVG has to be regenerated even if it already exists. Optional, defaulting to False.
178-
page : `int`
179-
Page to be converted if input file is multi-page. Optional, defaulting to 1.
180+
regen_if_exists : Optional[:class:`bool`], optional
181+
Setting if SVG has to be regenerated even if it already exists.
182+
page : Optional[:class:`int`], optional
183+
Page to be converted if input file is multi-page.
184+
180185
Returns
181186
-------
182-
Path to generated SVG file."""
187+
:class:`str`
188+
Path to generated SVG file."""
183189
result = dvi_file.replace(extension, ".svg")
184190
result = Path(result).as_posix()
185191
dvi_file = Path(dvi_file).as_posix()

0 commit comments

Comments
 (0)