Skip to content

Conversation

@PhilippImhof
Copy link
Member

I have completely rewritten the code for managing the TeX template:

  • Full backwards compatibility: if you do nothing, everything will work as before, the old default template will be used for LaTeX or XeLaTeX
  • New command line option --tex_template allows for a custom tex file
  • New class TeXTemplate starting with the current default values for maximum backwards compatibility.
  • New class has methods to append or prepend custom packages and/or custom preamble commands.
  • Added method register_tex_template allows to register a new or modified template

Example

class ExampleScene(Scene):
    def construct(self):
        tpl=TeXTemplate()
        tpl.append_package(["esvect",["f"]])
        register_tex_template(tpl)

        text=TextMobject(r"$\vv{vb}$")
        self.play(Write(text))

As you may have guessed, the syntax for packages is

  • append_package("package") if you do not have any options
  • append_package(["package",["option1","option2=value2"]]) if you do have options to give

When using the command line approach with a custom template file, the simpler class TeXTemplateFromFile is used. It does not allow adding/removing packages from within the scene. However, I do not think there is a need for it, because if one specifies a custom template file, we can surely assume they will not need to dynamically adapt it later on.

@PhilippImhof
Copy link
Member Author

This PR has been sent to 3b1b's repository a few months ago, but never got merged as (probably) Grant did not consider this useful to his own projects. It might be different in a community maintained version of manim that is used by many people in different situations.

See 3b1b/manim#745 for discussion

@PgBiel PgBiel added the new feature Enhancement specifically adding a new feature (feature request should be used for issues instead) label May 21, 2020
Copy link
Member

@PgBiel PgBiel left a comment

Choose a reason for hiding this comment

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

note: I didn't analyze the code yet, just pointing out a few ideas that stand out

@yoshiask
Copy link
Contributor

I don't think this is something to address immediately in this PR, but we should consider putting this somewhere other than constants.py. By definition, dynamically loading TeX templates is not constant.

@PhilippImhof
Copy link
Member Author

@PgBiel I added documentation and (hopefully) cleaned up the list of commits. Please do not hesitate to suggest further improvements, if necessary.

@PgBiel
Copy link
Member

PgBiel commented May 23, 2020

@PhilippImhof you might want to add the parameters, their types and the return types of each function to the documentation. I'll then modify it to use our format for you

@PhilippImhof PhilippImhof requested a review from PgBiel May 23, 2020 07:53
Copy link
Member

@PgBiel PgBiel left a comment

Choose a reason for hiding this comment

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

Just a few QoL suggestions

@PhilippImhof
Copy link
Member Author

@PgBiel Thanks for those improvements.

Copy link
Member

@PgBiel PgBiel left a comment

Choose a reason for hiding this comment

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

i'll commit those bugs i left off

@PhilippImhof
Copy link
Member Author

Shame on me, I didn't even see it.... Thanks

@PgBiel PgBiel added the refactor Refactor or redesign of existing code label May 23, 2020
@PhilippImhof PhilippImhof requested a review from leotrs May 23, 2020 17:36
@leotrs
Copy link
Contributor

leotrs commented May 23, 2020

I'm removing myself as a requested reviewer and requesting @yoshiask instead, since they seem to have thoughts about this PR.

@leotrs leotrs requested a review from yoshiask May 23, 2020 18:48
@PhilippImhof
Copy link
Member Author

@yoshiask Certainly true. On the other hand, the TeX template will probably never ever be changed in the middle of an animation. Once initialized and set up, it will remain constant at least for one scene. (The only reason I can see for changing the template in between would be that one absolutely needs a certain package or definition in one scene, but cannot have it in the remainder of the animation because of a bad conflict.)

@PgBiel
Copy link
Member

PgBiel commented May 23, 2020

Note that we also need to replace all print instances here with logging.<x> when resolving conflicts

@PhilippImhof
Copy link
Member Author

Good point. I will have a look at this tomorrow.

@PhilippImhof
Copy link
Member Author

PhilippImhof commented May 24, 2020

Commit 550c8b4 (and only this one) is untested, as I was unsure about the right way to pull from this master branch without having all those commits in the PR again. Also, I did not add the necessary imports, as they are already done in previously merged commit 00a786e in PR #59

@PhilippImhof
Copy link
Member Author

As nothing has happened for a few days, I wondered whether I could do anything to help in moving on? With the refactoring going on, merging will become more difficult.

I think this PR would be useful for those who need additional packages (typically people who do not live in the US or other English speaking countries, like me) and it comes with no risk.

@leotrs
Copy link
Contributor

leotrs commented May 27, 2020

@PhilippImhof thanks for the bump :) Just approved it. Now you need to take care of the merge conflicts. Please post here if you get stuck there (as quite a bit is happening on the repo these days).

@PhilippImhof
Copy link
Member Author

@PhilippImhof Now you need to take care of the merge conflicts. Please post here if you get stuck there (as quite a bit is happening on the repo these days).

Thanks for approving the PR. I'm afraid I'm already stuck. I do not see the conflicts, I just see: "This branch has conflicts that must be resolved. Only those with write access to this repository can merge pull requests."

Should I just pull the last version of ManimCommunity/master, rebase my branch, solve the conflicts locally and push another commit? (Rebasing is still somewhat difficult to me, it seems I still haven't come to a very deep understanding of this part of git.)

@leotrs
Copy link
Contributor

leotrs commented May 27, 2020

Should I just pull the last version of ManimCommunity/master, rebase my branch, solve the conflicts locally and push another commit?

An alternative is to directly try to pull ManimCommunity/master into your customtex branch, and resolve the conflicts. No rebasing necessary. Then push a new commit.

(Rebasing is still somewhat difficult to me, it seems I still haven't come to a very deep understanding of this part of git.)

Same, rebases are scary :)

@PhilippImhof
Copy link
Member Author

PhilippImhof commented May 27, 2020

Thanks @leotrs

An alternative is to directly try to pull ManimCommunity/master into your customtex branch, and resolve the conflicts. No rebasing necessary. Then push a new commit.

I will try. Just to make sure: Won't this bring all those other commits into this PR again, like I had it at the very beginning?

Also, won't this trigger another need for approvals? (What I mean: While waiting for new approvals, development in master goes on and new merge conflicts will probably appear.)

@leotrs
Copy link
Contributor

leotrs commented May 27, 2020

If you are worried about all the commits, you can squash them! (Though I guess this will require a rebase...) In any case, as long as there are no conflicts between your branch and current master, I say don't worry about those commits.

@PgBiel
Copy link
Member

PgBiel commented May 28, 2020

Also, won't this trigger another need for approvals? (...)

No

@PhilippImhof
Copy link
Member Author

Unfortunately, I am still stuck. I pulled the community's master, but for now, manim has stopped working. (ModuleNotFoundError: No module named 'manim' when trying to render the basic example scene.)

This happens even in a brand new directory populated with git clone https://github.com/ManimCommunity/manim.git.

@Aathish04
Copy link
Member

Unfortunately, I am still stuck. I pulled the community's master, but for now, manim has stopped working. (ModuleNotFoundError: No module named 'manim' when trying to render the basic example scene.)

This happens even in a brand new directory populated with git clone https://github.com/ManimCommunity/manim.git.

Have you run pip install -e . when inside the cloned repository?

@PhilippImhof
Copy link
Member Author

Have you run pip install -e . when inside the cloned repository?

Yes, sorry for not mentioning it. I was just editing my comment when the notification of your question popped up...

@Aathish04
Copy link
Member

Have you run pip install -e . when inside the cloned repository?

Yes, sorry for not mentioning it. I was just editing my comment when the notification of your question popped up...

Have you checked if manim is present in your installed packages with pip freeze? It should be there...

@PhilippImhof
Copy link
Member Author

Thanks for taking the time to help me.

Have you checked if manim is present in your installed packages with pip freeze? It should be there...

$ pip freeze | grep manim
-e git+https://github.com/ManimCommunity/manim.git@a29eabdf877442d3bee89a1d66bd0ff721484221#egg=manimlib

@Aathish04
Copy link
Member

$ pip freeze | grep manim
-e git+https://github.com/ManimCommunity/manim.git@a29eabdf877442d3bee89a1d66bd0ff721484221#egg=manimlib

Thats very strange indeed. How are you running manim in your scripts and in the command line?

Importing manim in the file with from manim import * and running from the command line with manim <path to file> <flags> works for me. Is your method of use different?

@PhilippImhof
Copy link
Member Author

Importing manim in the file with from manim import * and running from the command line with manim <path to file> <flags> works for me. Is your method of use different?

That's exactly what I do. example_scenes/basic.py has from manim import * and I invoke it just like you. (I used to invoke it in the old way python3 manim.py <file> <scene> <flags> before, but I obviously prefer the new way.)

@Aathish04
Copy link
Member

Importing manim in the file with from manim import * and running from the command line with manim <path to file> <flags> works for me. Is your method of use different?

That's exactly what I do. example_scenes/basic.py has from manim import * and I invoke it just like you. (I used to invoke it in the old way python3 manim.py <file> <scene> <flags> before, but I obviously prefer the new way.)

Do you have any other manim installations that might conflict with this? If you aren't able to solve it, it might be worth filing an issue...

@PhilippImhof
Copy link
Member Author

Do you have any other manim installations that might conflict with this? If you aren't able to solve it, it might be worth filing an issue...

I suspect so, because if it was a problem in the repo, someone would have noticed way earlier. I will try to clean up the whole mess. It might be conflicting with the original 3b1b manim installation I had. Once I find out, I will post an update.

@leotrs
Copy link
Contributor

leotrs commented May 28, 2020 via email

@PhilippImhof
Copy link
Member Author

So I got it all working again, by deleting all virtualenv stuff, removing everything that was related to manim and installing it all again.

I also managed to resolve all conflicts, there have been quite a lot of changes. Now, before I push my changes to this PR, I just want to make sure not to blow things up:

GitHub Desktop shows me 233 commits to push, which of course includes all the commits I pulled from master. Can I be sure that it will not cause any problems if I just push? (I tried squashing, but it resulted in strange conflicts.)

@leotrs
Copy link
Contributor

leotrs commented May 28, 2020

Are you sure those 233 are with respect to ManimCommunity/manim:master? GitHub is showing only 16 commits:
2020-05-28-093940_927x118_scrot

@leotrs
Copy link
Contributor

leotrs commented May 28, 2020

Uhm wait, I guess you didn't push the latest commit yet, right? If that would imply the 233 commits, then I'd consult @eulertour.

@PhilippImhof
Copy link
Member Author

PhilippImhof commented May 28, 2020

I am not sure of anything. But as I can only push to my own repository, they should be with respect to this one. However, I just do not know GitHub well enough to know, whether it is smart enough to leave them out in the PR.

Correct, I did not push after resolving the merge, because I did not want to flood the PR with "unnecessary" commits.

@PhilippImhof
Copy link
Member Author

To be more precise: git log origin/master..HEAD shows me all commits starting with

f9bb278d Add python -m for windows pytest

up to

a29eabdf (upstream/master) Merge pull request #99 from [...] remove_unnecessary_files

and then finally my last three commits

d7381997 (HEAD -> customtex) Resolved merge conflicts
64d774ae Merge branch 'master' into customtex
a7e42f54 (master) Merge branch 'master' of https://github.com/ManimCommunity/manim

It is 249 lines, probably the 16 already in this PR plus the 233 to push (of which 230 are imported from here)

@PgBiel
Copy link
Member

PgBiel commented May 28, 2020

You can prob try pushing to your branch and, if bad stuff happens, you can revert to the current state

@PhilippImhof
Copy link
Member Author

Finally....

@PhilippImhof
Copy link
Member Author

It is all cleaned up now. I am sorry, but as a consequence, proper attribution of and credit for @PgBiel's improvements is gone.

@leotrs leotrs merged commit 9c8913f into ManimCommunity:master May 29, 2020
eulertour added a commit that referenced this pull request Jun 3, 2020
This reverts commit 9c8913f, reversing
changes made to a29eabd.
Aathish04 added a commit that referenced this pull request Jun 3, 2020
Revert "Merge pull request #48 from PhilippImhof/customtex"

Changes made in #48 will be added back after ensuring that they do not introduce older code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature Enhancement specifically adding a new feature (feature request should be used for issues instead) refactor Refactor or redesign of existing code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants