Skip to content

Requirements for latex line operations #4541

@qasz384

Description

@qasz384

Description of proposed feature

Add a new function to control latex content line by line
Using vgroup to manage multiple single-line latex content will break the multi-line typesetting of latex.
If you treat each line as a sub-string of MathTex(), you will lose the ability to operate more granularly.
If latex is manually split into small enough contents in MathTex(), latex becomes difficult to read when modifying the code.
So I hope this function can accept a long single latex string or multiple short strings, identify the latex newline character r "\" from it, and then return the corresponding line as required without destroying the splitting of MathTex()

How can the new feature be used?

Display mathematical derivation line by line and provide line-level control over latex content

Additional comments

This is a simple example when writing r"\\" alone

def GetLine(txt, TargetLineIndex): 
            LineIndex = 0
            LineStart = 0
            LineEnd = 0
            isNextLine = 0
            for WordIndex in range(len(txt.submobjects)):
                if isNextLine:
                    LineStart = WordIndex
                    isNextLine = 0
                if txt.submobjects[WordIndex].get_tex_string() == r"\\":
                    LineIndex += 1
                    LineEnd = WordIndex
                    isNextLine = 1
                if TargetLineIndex == LineIndex or WordIndex==len(txt.submobjects):
                    return txt.submobjects[LineStart:LineEnd]
                WordIndex += 1
        multiline_tex = MathTex(
            r"a^2", "+"," b^2 &= c^2 ", r"\\",
            r"x^3" , "+", "y^3 &= z^3 ", r"\\",r"E &= mc^2", r"\\")
        self.play([Write(i)for i in GetLine(multiline_tex,1)])
        self.play([Write(i)for i in GetLine(multiline_tex,2)])
        self.play([Write(i)for i in GetLine(multiline_tex,3)])
        self.wait()
        all_x_parts = multiline_tex.get_parts_by_tex("+")
        self.play(all_x_parts.animate.set_color(RED))
        self.wait()

Metadata

Metadata

Assignees

No one assigned

    Labels

    new featureEnhancement specifically adding a new feature (feature request should be used for issues instead)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions