Repository: ManimCommunity/manim

Issue:
TransformMatchingTex doesn't works well with sqrt square root operator
## Description of bug / unexpected behavior

`TransformMatchingTex` does not work as expected when transforming from one `MathTex` object to an other which contains a Latex `sqrt` operator
- The last character  in the square-root of the last MathTex object is invisible (in the following example, the parenthesis )
- The transform_mismatches is therefore badly rendered

## Expected behavior

- In the following example, the exponent 2 should transform into the square root.
- The last character under the square root (the closing parenthesis ) should be visible.

## How to reproduce the issue
``
<details><summary>Code for reproducing the problem. Adapted and simplfied version from 3B1B manim's TExTransformExample in his repository, https://3b1b.github.io/manim/getting_started/example_scenes.html </summary>

```py
class TexTransformExampleSimple(Scene):
    def construct(self):
        to_isolate = ["A", "B", "C", "=", "(", ")"]
        lines = VGroup(
            MathTex("A^2 = (C + B)(C - B)", substrings_to_isolate=to_isolate),
            MathTex("A = \\sqrt{(C + B)(C - B)}", substrings_to_isolate=to_isolate)
        )
        lines.arrange(DOWN, buff=LARGE_BUFF)
        self.add(lines[0])
        self.play(TransformMatchingTex(lines[0], lines[1], transform_mismatches=True), run_time=2)
        self.wait()
```

</details>


## Additional media files
<!-- Paste in the files manim produced on rendering the code above. -->



<details><summary>Images/GIFs</summary>

<!-- PASTE MEDIA HERE -->

![TexTransformExampleSimple_ManimCE_v0 6 0](https://user-images.githubusercontent.com/25033218/118413705-f8324a00-b6a0-11eb-948b-0a2d7da421d4.gif)



</details>


## Logs
<details><summary>Terminal output</summary>
<!-- Add "-v DEBUG" when calling manim to generate more detailed logs -->

```
Manim Community v0.6.0

[05/16/21 23:42:15] 
                    DEBUG    Animation received extra kwargs: {'final_alpha_value': 0}                                                     animation.py:50
                    DEBUG    Animation received extra kwargs: {'final_alpha_value': 0}                                                     animation.py:50
                    DEBUG    Animation received extra kwargs: {'final_alpha_value': 0}                                                     animation.py:50
                    DEBUG    Hashing ...                                                                                                    hashing.py:240
                    DEBUG    Hashing done in 0.333753 s.                                                                                    hashing.py:253
                    DEBUG    Hash generated :  450974505_3223459120_2098723146                                                              hashing.py:257
                    DEBUG    List of the first few animation hashes of the scene: ['450974505_3223459120_2098723146']                cairo_renderer.py:108
[05/16/21 23:42:21] INFO     Animation 0 : Partial movie file written in {'/path/to/project/mani scene_file_writer.py:401
                             m/media/videos/scene/1080p60/partial_movie_files/TexTransformExampleSimple/450974505_3223459120_2098
                             723146.mp4'}
                    DEBUG    Animation with empty mobject                                                                                  animation.py:62
                    DEBUG    Hashing ...                                                                                                    hashing.py:240
                    DEBUG    Hashing done in 0.196513 s.                                                                                    hashing.py:253
                    DEBUG    Hash generated :  2788726626_1615497636_227427286                                                              hashing.py:257
                    INFO     Animation 1 : Using cached data (hash : 2788726626_1615497636_227427286)                                cairo_renderer.py:100
                    DEBUG    List of the first few animation hashes of the scene: ['450974505_3223459120_2098723146',                cairo_renderer.py:108
                             '2788726626_1615497636_227427286']
                    DEBUG    Partial movie files to combine (2 files): ['/path/to/project/manim/ scene_file_writer.py:450
                             media/videos/scene/1080p60/partial_movie_files/TexTransformExampleSimple/450974505_3223459120_209872
                             3146.mp4', '/path/to/project/manim/media/videos/scene/1080p60/parti
                             al_movie_files/TexTransformExampleSimple/2788726626_1615497636_227427286.mp4']
[05/16/21 23:42:25] INFO                                                                                                          scene_file_writer.py:585
                             File ready at /path/to/project/manim/media/videos/scene/1080p60/Tex
                             TransformExampleSimple_ManimCE_v0.6.0.gif

                    INFO     Rendered TexTransformExampleSimple                                                                               scene.py:217
                             Played 2 animations
```

<!-- Insert screenshots here (only when absolutely necessary, we prefer copy/pasted output!) -->

</details>


## System specifications

<details><summary>System Details</summary>

- MacOS 10.14.6 Mojave (patcher), macbook pro 2011
- RAM: 16 Go
- Python 3.9.5
- Installed modules (provide output from `pip list`):
```
appnope                0.1.2
backcall               0.2.0
certifi                2020.12.5
chardet                4.0.0
click                  7.1.2
click-default-group    1.2.2
cloup                  0.7.1
colorama               0.4.4
colour                 0.1.5
commonmark             0.9.1
cycler                 0.10.0
Cython                 0.29.22
decorator              4.4.2
glcontext              2.3.3
idna                   2.10
ipython                7.22.0
ipython-genutils       0.2.0
jedi                   0.18.0
kiwisolver             1.3.1
manim                  0.6.0
manimgl                1.0.1.dev18 /Users/sylvann/GitCloned/manim/manim
ManimPango             0.2.4
mapbox-earcut          0.12.10
matplotlib             3.4.0
mccabe                 0.6.1
moderngl               5.6.4
moderngl-window        2.3.0
mpmath                 1.2.1
multipledispatch       0.6.0
networkx               2.5.1
numpy                  1.20.2
parso                  0.8.2
pexpect                4.8.0
pickleshare            0.7.5
Pillow                 8.1.2
pip                    21.1.1
prompt-toolkit         3.0.18
ptyprocess             0.7.0
pybind11               2.6.2
pycairo                1.20.0
pycodestyle            2.7.0
pydub                  0.25.1
pyflakes               2.3.1
pyglet                 1.5.15
Pygments               2.8.1
PyGObject              3.40.1
pyobjc-core            7.1
pyobjc-framework-Cocoa 7.1
PyOpenGL               3.1.5
pyparsing              2.4.7
pyrr                   0.10.3
python-dateutil        2.8.1
PyYAML                 5.4.1
requests               2.25.1
rich                   6.2.0
scipy                  1.6.3
screeninfo             0.6.7
setuptools             56.0.0
six                    1.15.0
sympy                  1.7.1
tqdm                   4.59.0
traitlets              5.0.5
typing-extensions      3.10.0.0
urllib3                1.26.4
validators             0.18.2
watchdog               2.1.0
wcwidth                0.2.5
wheel                  0.36.2
```
</details>

<details><summary>LaTeX details</summary>

+ LaTeX distribution : MacTeX 2021
</details>

<details><summary>FFMPEG</summary>

Output of `ffmpeg -version`: 

```
4.4
```
</details>

## Additional comments
<!-- Add further context that you think might be relevant for this issue here. -->

A work around for the disapearing of the last character under the sqrt is to add an other random character to its right. But it is clearly not viable, and doesn't solve the morphing issue.



Discussion:

Resolving patch:
diff --git a/manim/animation/transform_matching_parts.py b/manim/animation/transform_matching_parts.py
--- a/manim/animation/transform_matching_parts.py
+++ b/manim/animation/transform_matching_parts.py
@@ -121,8 +121,10 @@ def __init__(
             fade_target.add(target_map[key])
 
         if transform_mismatches:
-            anims.append(Transform(fade_source.copy(), fade_target, **kwargs))
-        if fade_transform_mismatches:
+            if "replace_mobject_with_target_in_scene" not in kwargs:
+                kwargs["replace_mobject_with_target_in_scene"] = True
+            anims.append(Transform(fade_source, fade_target, **kwargs))
+        elif fade_transform_mismatches:
             anims.append(FadeTransformPieces(fade_source, fade_target, **kwargs))
         else:
             anims.append(FadeOut(fade_source, target_position=fade_target, **kwargs))
diff --git a/manim/mobject/svg/tex_mobject.py b/manim/mobject/svg/tex_mobject.py
--- a/manim/mobject/svg/tex_mobject.py
+++ b/manim/mobject/svg/tex_mobject.py
@@ -287,7 +287,7 @@ def get_modified_expression(self, tex_string):
         return result
 
     def modify_special_strings(self, tex):
-        tex = self.remove_stray_braces(tex)
+        tex = tex.strip()
         should_add_filler = reduce(
             op.or_,
             [
@@ -296,12 +296,14 @@ def modify_special_strings(self, tex):
                 tex == "\\overline",
                 # Make sure sqrt has overbar
                 tex == "\\sqrt",
+                tex == "\\sqrt{",
                 # Need to add blank subscript or superscript
                 tex.endswith("_"),
                 tex.endswith("^"),
                 tex.endswith("dot"),
             ],
         )
+
         if should_add_filler:
             filler = "{\\quad}"
             tex += filler
@@ -325,6 +327,8 @@ def modify_special_strings(self, tex):
             tex = tex.replace("\\left", "\\big")
             tex = tex.replace("\\right", "\\big")
 
+        tex = self.remove_stray_braces(tex)
+
         for context in ["array"]:
             begin_in = ("\\begin{%s}" % context) in tex
             end_in = ("\\end{%s}" % context) in tex


Test patch: