ManimCommunity / ManimCommunity/manim

Nested Tex Environments

Open
#4,329 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

new feature
Dominant language
Python
Stars
40.9k
Forks
3.1k
Avg merge
3d 12h
Merged PRs (30d)
25

Description

## Description of proposed feature

It should be possible to set multiple tex enviroments such that they become nested inside each other.
### Motivation for this suggestion
I had a problem a an arabic text that needed `tex_enviroment="Arabic"` with my custom template but this led to have a left aligned text. To solve that I needed another tex environment `flushright`, which I needed to add manually in my string
```
text= r"""
\begin{flushright}
تقوم الدالة $f$ بإسناد عدد وحيد من مجموعة عددية $R$ تسمى مجموعة الوصول أو مدى الدالة إلى عدد من مجموعة عددية $D$ تسمى مجموعة التعريف
\end{flushright}
"""
arabicText = Tex(text, tex_template=my_template, tex_environment="Arabic")
```

## How can the new feature be used?

The `tex_enviroment` parameter should take a list of strings as entry rather than a string.
then it should use something similar to `get_texcode_for_expression_in_env` function (exist in `tex.py`) in a recursive manner.
Finally, the code should be
```
text= r"""
تقوم الدالة $f$ بإسناد عدد وحيد من مجموعة عددية $R$ تسمى مجموعة الوصول أو مدى الدالة إلى عدد من مجموعة عددية $D$ تسمى مجموعة التعريف
"""
arabicText = Tex(text, tex_template=my_template, tex_environment=["Arabic", "flushright"])
```
## Additional comments

I know that I can create a custom function to achieve this nested enviroment behavior, just liked to share the idea that it might be implemented in a standard manner by the library.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in tex.py by reading get_texcode_for_expression_in_env and the handling of tex_environment in Tex. Trace how a string environment is converted into TeX code, then determine how a list such as ["Arabic", "flushright"] should be processed recursively. Done means the listed environments are nested in order without requiring manually embedded TeX.

Written by the indexing model from the issue text.

Assessment

Tech stack
latex, python
Domain
computer-graphics
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.