Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dvips to list of required LaTeX packages on Linux #2371

Merged

Conversation

kdkasad
Copy link
Contributor

@kdkasad kdkasad commented Dec 9, 2021

Overview: What does this pull request change?

This adds 'dvips' to the list of LaTeX packages on the Linux
installatioon documentation page:
docs/source/installation/linux.rst

Motivation and Explanation: Why and how do your changes improve the library?

The 'dvips' package is used by the 'dvisvgm' package to convert DVI
files to SVG graphics. Without it, manim fails to render files
containing LaTeX.

Links to added or changed documentation pages

https://manimce--2371.org.readthedocs.build/en/2371/installation/linux.html#optional-dependencies

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@behackl
Copy link
Member

behackl commented Dec 14, 2021

I am a bit confused about this: our Docker images work, but do not have the dvips package installed by default (see https://github.com/ManimCommunity/manim/blob/main/docker/Dockerfile). Could you provide an example of some code that throws an exception because of the missing dvips package?

@kdkasad
Copy link
Contributor Author

kdkasad commented Dec 15, 2021

Could you provide an example of some code that throws an exception because of the missing dvips package?

(TL;DR at bottom)

Steps to reproduce

I installed Manim using pip install manim and then installed the barebones TinyTex distribution for the LaTeX packages. Note: this is the one using the TinyTex-0 installer, not the default TinyTex-1. I then ran tlmgr install ... and pasted the list of packages specific in the documentation.

I tried to compile the following scene:

from manim import *

class TestScene(Scene):
    def construct(self):
        t = MathTex(r'\mathbb{M}').scale(7)
        self.add(t)

Observed error

It resulted in the following error:

$ manim -pqh scene.py TestScene
Manim Community v0.13.1

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│                                                                                                  │
│ /home/..../.local/lib/python3.10/site-packages/manim/cli/render/commands.py:139 in render        │
│                                                                                                  │
│   136 │   │   for SceneClass in scene_classes_from_file(file):                                   │
│   137 │   │   │   try:                                                                           │
│   138 │   │   │   │   scene = SceneClass()                                                       │
│ ❱ 139 │   │   │   │   scene.render()                                                             │
│   140 │   │   │   except Exception:                                                              │
│   141 │   │   │   │   error_console.print_exception()                                            │
│   142 │   │   │   │   sys.exit(1)                                                                │
│ /home/..../.local/lib/python3.10/site-packages/manim/scene/scene.py:219 in render                │
│                                                                                                  │
│    216 │   │   """                                                                               │
│    217 │   │   self.setup()                                                                      │
│    218 │   │   try:                                                                              │
│ ❱  219 │   │   │   self.construct()                                                              │
│    220 │   │   except EndSceneEarlyException:                                                    │
│    221 │   │   │   pass                                                                          │
│    222 │   │   except RerunSceneException as e:                                                  │
│                                                                                                  │
│ /home/..../downloads/manim/scene.py:5 in construct                                               │
│                                                                                                  │
│   2                                                                                              │
│   3 class TestScene(Scene):                                                                      │
│   4 │   def construct(self):                                                                     │
│ ❱ 5 │   │   t = MathTex(r'\mathbb{M}').scale(7)                                                  │
│   6 │   │   self.add(t)                                                                          │
│   7                                                                                              │
│                                                                                                  │
│ /home/.../.local/lib/python3.10/site-packages/manim/mobject/svg/tex_mobject.py:304 in __init__  │
│                                                                                                  │
│   301 │   │   │   │   │   │   """,                                                               │
│   302 │   │   │   │   │   ),                                                                     │
│   303 │   │   │   │   )                                                                          │
│ ❱ 304 │   │   │   raise compilation_error                                                        │
│   305 │   │   self.set_color_by_tex_to_color_map(self.tex_to_color_map)                          │
│   306 │   │                                                                                      │
│   307 │   │   if self.organize_left_to_right:                                                    │
│                                                                                                  │
│ /home/..../.local/lib/python3.10/site-packages/manim/mobject/svg/tex_mobject.py:283 in __init__  │
│                                                                                                  │
│   280 │   │   self.brace_notation_split_occurred = False                                         │
│   281 │   │   self.tex_strings = self.break_up_tex_strings(tex_strings)                          │
│   282 │   │   try:                                                                               │
│ ❱ 283 │   │   │   super().__init__(                                                              │
│   284 │   │   │   │   self.arg_separator.join(self.tex_strings),                                 │
│   285 │   │   │   │   tex_environment=self.tex_environment,                                      │
│   286 │   │   │   │   tex_template=self.tex_template,                                            │
│                                                                                                  │
│ /home/..../.local/lib/python3.10/site-packages/manim/mobject/svg/tex_mobject.py:90 in __init__   │
│                                                                                                  │
│    87 │   │                                                                                      │
│    88 │   │   assert isinstance(tex_string, str)                                                 │
│    89 │   │   self.tex_string = tex_string                                                       │
│ ❱  90 │   │   file_name = tex_to_svg_file(                                                       │
│    91 │   │   │   self.get_modified_expression(tex_string),                                      │
│    92 │   │   │   environment=self.tex_environment,                                              │
│    93 │   │   │   tex_template=self.tex_template,                                                │
│                                                                                                  │
│ /home/..../.local/lib/python3.10/site-packages/manim/utils/tex_file_writing.py:51 in             │
│ tex_to_svg_file                                                                                  │
│                                                                                                  │
│    48 │   │   tex_template.tex_compiler,                                                         │
│    49 │   │   tex_template.output_format,                                                        │
│    50 │   )                                                                                      │
│ ❱  51return convert_to_svg(dvi_file, tex_template.output_format)                            │
│    52                                                                                            │
│    53                                                                                            │
│    54 def generate_tex_file(expression, environment=None, tex_template=None):                    │
│                                                                                                  │
│ /home/..../.local/lib/python3.10/site-packages/manim/utils/tex_file_writing.py:226 in            │
│ convert_to_svg                                                                                   │
│                                                                                                  │
│   223 │                                                                                          │
│   224# if the file does not exist now, this means conversion failed                         │225if not os.path.exists(result):                                                         │
│ ❱ 226 │   │   raise ValueError(                                                                  │
│   227 │   │   │   f"Your installation does not support converting {extension} files to SVG."     │
│   228 │   │   │   f" Consider updating dvisvgm to at least version 2.4."                         │
│   229 │   │   │   f" If this does not solve the problem, please refer to our troubleshooting g   │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: Your installation does not support converting .dvi files to SVG. Consider updating dvisvgm to at least version 2.4.
If this does not solve the problem, please refer to our troubleshooting guide at:
https://docs.manim.community/en/stable/installation/troubleshooting.html

Doing some digging

However, my dvisvgm package is version 2.11 which is well above 2.4. When I tried running dvisvgm on its own, it gave the following result:

$ dvisvgm media/Tex/d542770d69a4bbe7.dvi
pre-processing DVI file (format version 2)
WARNING: PostScript header file tex.pro not found
WARNING: PostScript header file texps.pro not found
WARNING: PostScript header file special.pro not found
WARNING: PostScript header file color.pro not found
PostScript error: undefined in TeXDict

Searching for one of those missing files using tlmgr shows that they're provided by the dvips TeX package:

$ tlmgr search --global --file /texps.pro
tlmgr: package repository https://ctan.math.utah.edu/ctan/tex-archive/systems/texlive/tlnet (verified)
dvips:
	texmf-dist/dvips/base/texps.pro

Fixing the error

So I installed the dvips package:

$ tlmgr install dvips
tlmgr: package repository https://ctan.math.utah.edu/ctan/tex-archive/systems/texlive/tlnet (verified)
[1/2, ??:??/??:??] install: dvips.x86_64-linux [145k]
[2/2, 00:00/00:00] install: dvips [57k]
running mktexlsr ...
done running mktexlsr.

Then I ran manim again on same scene. (I deleted the media folder first for a clean build):

$ manim -qh scene.py TestScene
Manim Community v0.13.1

[12/14/21 19:23:11] INFO     Writing "\mathbb{M}" to media/Tex/d542770d69a4bbe7.tex                       tex_file_writing.py:85
[12/14/21 19:23:13] INFO                                                                                scene_file_writer.py:729
                             File ready at '/home/..../downloads/manim/media/images/scene/TestScene_Man
                             imCE_v0.13.1.png'

                    INFO     Rendered TestScene                                                                     scene.py:237
                             Played 0 animations

As you can see, it worked fine.

Figuring out why the Docker image works

I installed the Docker image manimcommunity/manim and compiling the scene using that worked fine out of the box.

Running the following command on the Docker container confirms that the dvips TeX package is in face installed on there:

$ tlmgr search dvips
dvips - A DVI to PostScript driver
...

I did a little digging and found out that dvips is installed by the collection-basic collection, which is installed by the scheme-minimal scheme specified in texlive-profile.txt.

My installation on the other hand is using the bare minimum scheme (scheme-infraonly). This installs only tlmgr and basically no other packages, not even ones to compile basic TeX documents.

So if the Docker image was built using the scheme-infraonly scheme, it would also require the dvips package to be manually installed. There may be other packages that are required my manim but are installed in the default set of packages (collection-basic).

Note: to see the packages provided by collection-basic, either see the source file at https://tug.org/svn/texlive/trunk/Master/tlpkg/tlpsrc/collection-basic.tlpsrc?view=markup or run the following command:

$ tlmgr info --list collection-basic

TL;DR

The dvips package is in fact required by Manim, but is installed in the set of packages called collection-basic. This is the collection of packages that are usually installed by default in a TeX distribution.

My error came up when I installed a completely bare TeX distribution (i.e. no packages other than tlmgr), so dvips was not installed.

Possible solutions

  1. dvips and possibly other "hidden" requirements should be listed in the list of required TeX packages
  2. The collection-basic collection should be listed as a dependency.
  3. Do nothing and point anyone who encounters the issue in the future to this thread.

Solution 2. would be easier and would probably make the most sense, as finding any other required packages that are installed in collection-basic doesn't provide much added advantage over just installing the whole collection. I can change this PR to add the collection if that's the solution you want to go with.

And finally, apologies

This is both my first time using Manim and my first time using TeX/LaTeX/TeXLive. This issue really isn't a big deal and is mostly a result of my minimalism when it comes to software so I apologize for bringing it up.

@behackl
Copy link
Member

behackl commented Dec 20, 2021

Thank you (!!!) for this clean in-depth analysis.

At this point I think both your first and second option are fine; the second one (remarking that this is a list based on collection-basic) is probably easier.

Let me know if you agree and whether you are willing to adapt this PR accordingly, otherwise I'd also be fine with including this as is.

This adds 'collection-basic' to the list of LaTeX packages on the Linux
installatioon documentation page:
docs/source/installation/linux.rst

Several packages provided by 'collection-basic' are required for Manim
to function, so the whole collection is specified rather than finding
the specific packages.
@kdkasad
Copy link
Contributor Author

kdkasad commented Dec 20, 2021

Ok, I changed it to add collection-basic instead of just dvips.

@behackl behackl added the documentation Improvements or additions to documentation label Dec 31, 2021
Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@behackl behackl enabled auto-merge (squash) December 31, 2021 01:28
@behackl behackl merged commit 86c9f69 into ManimCommunity:main Dec 31, 2021
@behackl behackl changed the title Add 'dvips' to list of required LaTeX packages on Linux Added dvips to list of required LaTeX packages on Linux Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants