Method, medium and device for realizing automatic mathematical operation of formula based on latex
By preprocessing LaTeX formulas and providing animated prompts, mathematical calculations can be completed automatically, solving the problems of low efficiency in traditional handwritten formula derivation and complex computer operation, and achieving an efficient and accurate formula derivation process.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 黄凯鹏
- Filing Date
- 2023-02-28
- Publication Date
- 2026-05-12
AI Technical Summary
Traditional handwritten formula derivation is inefficient, and computer-based formula derivation suffers from reading difficulties and high learning costs. Furthermore, current technology cannot modify LaTeX code by manipulating LaTeX formulas.
By preprocessing the LaTeX formulas, obtaining DOM elements and string mathematical objects, determining selectable, draggable, and placeable objects, using animation effects to prompt the user's operation, and performing mathematical calculations based on the user's selections, the LaTeX code is automatically modified to achieve automatic mathematical calculations for the formulas.
It eliminates the need for handwritten copying and almost no manual code editing, reducing human error, improving the efficiency and accuracy of formula derivation, simplifying user operation, reducing mental effort, and making it suitable for primary and secondary school students.
Smart Images

Figure CN116069293B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, storage medium, and electronic device for performing automatic mathematical calculations of formulas based on LaTeX. Background Technology
[0002] In the teaching and research of mathematics and related disciplines, it is inevitable to derive formulas. However, the traditional handwritten formula derivation is too inefficient, as it is time-consuming to observe the calculable parts, requires manual calculation, is time-consuming to write, is too tedious to copy the unchanged parts, is easy to copy incorrectly, is easy to calculate incorrectly, and is very difficult to check for errors.
[0003] Currently, some mathematical software, such as MATLAB, can be used to perform some derivation processes of formulas by computers, including combining like terms, polynomial expansion, factorization, etc. However, in the process of human-computer interaction, only computer-understandable string text can be used, which has problems such as difficulty in reading string text and easy misplacement when editing string text; it also requires learning the corresponding coding knowledge, which has the problem of high learning cost.
[0004] In teaching, even if the teacher prepares the derivation process of the formula in advance and displays the derivation process line by line on the slides in class, students still have to carefully observe which parts of the formula above and below are unchanged and which parts are changed, and whether they can understand the changed part of the calculation process, which is very mentally taxing.
[0005] Existing technology can already use computers to convert string text code into formulas that conform to people's reading habits. For example, LaTeX code can be converted into LaTeX formulas on a webpage, and LaTeX formulas can be changed by modifying LaTeX code. However, it is not yet possible to change LaTeX code by manipulating LaTeX formulas. Summary of the Invention
[0006] In view of the above background, the purpose of this invention is to provide a method, storage medium, and electronic device for automatic mathematical calculation of formulas based on LaTeX, and to provide a new human-computer interaction method for formula derivation that is simple to operate, clear at a glance, and less prone to errors: users only need to select and drag the parts of the LaTeX formula that need to be calculated to complete the automatic mathematical calculation of the mathematical elements in the formula, thereby achieving fast and accurate formula derivation; when the user drags, it will automatically give prompts on whether the calculation is possible, saving people the mental effort of visually observing the formula; there is no need for manual copying or almost no need for manual editing of code, reducing the possibility of human error; when the user operates, there will be animated prompts for the calculation process and the calculation results, making it easier for students to see the calculation details and understand the reasoning of the formula derivation during teaching.
[0007] The method for automatic mathematical calculation of formulas based on LaTeX proposed in this invention employs the following technical solution:
[0008] Preprocessing of LaTeX formulas and LaTeX code;
[0009] Retrieves a collection of mathematical objects of DOM elements in a LaTeX formula;
[0010] Retrieves a collection of string math objects from LaTeX code;
[0011] Determine the selectable DOM element mathematical objects in a LaTeX formula;
[0012] Identify draggable DOM element mathematical objects in LaTeX formulas;
[0013] Determine the DOM element mathematical objects that can be placed in the LaTeX formula;
[0014] Use different colors to highlight the placeable DOM element mathematical objects when the user drags and drops them;
[0015] The source DOM element mathematical object and the target DOM element mathematical object are determined based on the user's selection, dragging, and placement operations;
[0016] Detect the ambiguity of mathematical operations that may exist in selection, drag, and placement events, and prompt the user to make a choice among the possible mathematical operations;
[0017] Add animation effects to related DOM elements during mathematical operations, such as changing color, moving, disappearing, and being added to the mathematical object;
[0018] Based on the positions of the source DOM element mathematical object and the target DOM element mathematical object in the set of DOM element mathematical objects in the LaTeX formula, find the LaTeX code of the source string mathematical object and the target string mathematical object at the corresponding positions in the set of string mathematical objects in the corresponding LaTeX code;
[0019] Based on the types of the source DOM element mathematical objects and the target DOM element mathematical objects and their positions in the LaTeX formula, and according to the mathematical operations selected by the user, the LaTeX code of the source string mathematical objects and the target string mathematical objects is modified to conform to the corresponding mathematical operations.
[0020] The modified LaTeX code is then assembled, placed into the LaTeX code input box, and the rendering and display of the LaTeX formula are refreshed.
[0021] Locate the DOM element mathematical objects that have changed in the refreshed LaTeX formula and highlight them with animation hints.
[0022] Furthermore, by using an existing LaTeX editor on a webpage to assist in inputting or directly inputting the LaTeX code of the formula to be performed mathematical calculations, a converted webpage version of the initial LaTeX formula can be obtained. At this point, the LaTeX formula does not have any user-interactive functionality, and its DOM structure does not meet the conditions for subsequent processing. Therefore, preprocessing is required, including:
[0023] Package each polynomial to the left and right of each equal sign in the LaTeX formula into a separate DOM element;
[0024] Package each term in a LaTeX formula into a DOM element;
[0025] Pack each factor in a LaTeX formula, which consists of multiple sibling DOM elements, into a single DOM element, including bracket objects, trigonometric function objects, logarithm objects, and factorial objects.
[0026] Furthermore, the system detects and automatically corrects any LaTeX code that might cause structural errors in the LaTeX formula, including the proper use of brackets and alignment symbols. After automatic correction, the LaTeX formula is automatically refreshed. This step is completed after the LaTeX code is entered but before the LaTeX formula preprocessing.
[0027] Furthermore, after preprocessing, the set of mathematical objects of DOM elements in the LaTeX formula can be found, including: the set of all plus and minus signs; the set of all multiplication signs; the set of all equal signs; the set of all polynomials; the set of all terms; the set of all parentheses; the set of all factors; the set of all fractions; the set of all radicals; the set of all triple braces; the set of all exponents; and the set of all elements to be substituted into the formula.
[0028] Furthermore, corresponding to the above, we can also find the set of string mathematical objects in LaTeX code, including: the set of all plus and minus signs; the set of all multiplication signs; the set of all equal signs; the set of all polynomials; the set of all terms; the set of all parentheses; the set of all factors; the set of all fractions; the set of all radicals; the set of all triple braces; the set of all exponents; and the set of all objects to be substituted into the formula.
[0029] Furthermore, in order to add operability to DOM element mathematical objects in LaTeX formulas later, it is necessary to first determine which DOM element mathematical objects are operable, including selectable, draggable, and placeable operations. To this end, a radio button is set to restrict selection and dragging actions to DOM element items, DOM element factors, or DOM element exponents to avoid potential ambiguity in selection and dragging actions.
[0030] Furthermore, the selectable DOM element mathematical objects in the LaTeX formula are determined, including:
[0031] When a user enables multi-select mode and clicks to select one of the draggable DOM element mathematical objects, the DOM element mathematical object is marked as selected;
[0032] Based on the selected DOM element mathematical object, the range of selectable DOM element mathematical objects is limited to those DOM element mathematical objects of the same level and type that can participate in mathematical operations simultaneously.
[0033] Furthermore, the draggable DOM element mathematical objects in the LaTeX formulas are identified, including:
[0034] When no DOM element math objects are marked as selected, draggable DOM element math objects include all equal signs, terms, factors, exponents, parentheses, and formulas to be substituted.
[0035] When an existing DOM element is marked as selected, the draggable DOM element is limited to the DOM element marked as selected.
[0036] Furthermore, the mathematical objects of DOM elements that can be placed in LaTeX formulas are determined, including:
[0037] The source DOM element's mathematical object is determined by selection and drag events;
[0038] Based on the position of the source DOM element mathematical object in the LaTeX formula, the placeable DOM element mathematical objects are limited to all DOM element mathematical objects at the corresponding positions that may participate in the calculation.
[0039] Furthermore, when a user drags a DOM element mathematical object, the placeable DOM element mathematical objects are highlighted with different colors, including:
[0040] Each of the placeable DOM element mathematical objects is compared with the source DOM element mathematical object. The main comparison is between the class name of the DOM element and the string content of the text node, or the LaTeX code of the corresponding string mathematical objects is compared to determine whether they are the same mathematical elements. The comparison supports out-of-order recognition and wildcard recognition.
[0041] Placeable DOM element mathematical objects that have the same mathematical elements as the source DOM element mathematical object are marked with a certain color to indicate that they can be used for mathematical operations, while those that are different are marked with a certain color to indicate that they can be sorted or toggled.
[0042] Furthermore, when a user drags a DOM element object onto a placeable DOM element object, the dragged DOM element object, including those already selected in multi-select mode, is recorded as the source DOM element object; the placed DOM element object is recorded as the target DOM element object. In subsequent operations, when the user selects to expand the calculation range, any unselected DOM element objects within the selected range that can participate in the calculation will be appended and recorded as source DOM element objects.
[0043] Furthermore, the system detects the ambiguity of mathematical operations that may exist in selection, drag, and placement events, prompting the user to choose from multiple possible mathematical operations. When the user chooses to expand the scope of the operation, the mathematical objects of the unselected DOM elements within the selected scope that can participate in the operation are appended to the source DOM element mathematical object collection.
[0044] Furthermore, animation effects are added to the DOM elements related to mathematical objects that change color, move, disappear, or are added during mathematical operations. This serves to indicate which mathematical objects will change and allows the unchanged parts to transition smoothly, reducing the visual jerking when refreshing the formula later.
[0045] Furthermore, based on the positions of the source DOM element mathematical object and the target DOM element mathematical object in the set of DOM element mathematical objects in the LaTeX formula, the LaTeX code of the source string mathematical object and the target string mathematical object at the corresponding positions in the set of string mathematical objects in the corresponding LaTeX code is found.
[0046] Furthermore, based on the types of the source and target DOM element mathematical objects and their positions in the LaTeX formula, and according to the mathematical operations selected by the user, the LaTeX code of the source and target string mathematical objects is modified to conform to the corresponding mathematical operations, including:
[0047] Based on the types of the source DOM element mathematical objects and the target DOM element mathematical objects, and their positions in the LaTeX formula, and according to the mathematical operation selected by the user, determine which mathematical operation or operation will be performed, including addition, subtraction, multiplication, division, multiplication distribution, factoring out common factors, polynomial exponentiation expansion, splitting terms, adding or subtracting the same term, factoring, multiplying or dividing the same factor, adding parentheses, removing parentheses, substituting into a formula, adding, subtracting, multiplying or dividing both sides of two equations, multiplying or dividing both sides of an equation by the same factor, transposing terms, sorting, switching parenthesis forms, and copying equations;
[0048] The LaTeX code of the source string mathematical object and the target string mathematical object is compared, or the mathematical objects of the corresponding DOM elements are compared to determine whether they are the same mathematical elements. The comparison supports out-of-order recognition and wildcard recognition.
[0049] Separate mathematical elements from the source string math object and the target string math object in LaTeX code, including signs, coefficients and factors in terms, terms in parentheses, and custom wildcards used to represent arbitrary mathematical elements;
[0050] According to the rules of mathematical operations, calculate and process the mathematical elements in LaTeX code, including calculating and processing symbols, coefficients, factors, exponents, terms, and parentheses.
[0051] Furthermore, the out-of-order recognition and wildcard recognition include:
[0052] Two terms formed by different arrangements of the same set of factors can be identified and judged as having the same mathematical elements.
[0053] The same set of several items, arranged in different ways, can be identified and judged as the same mathematical elements when enclosed in two parentheses;
[0054] Wildcards with specific structures can match any number of mathematical elements from the corresponding position to the end marker.
[0055] Furthermore, the modified LaTeX code is concatenated and integrated, placed into the LaTeX code input box, and the rendering and display of the LaTeX formula are refreshed. The LaTeX code after automatic mathematical calculations can be manually edited by the user again, or it can be copied and used directly elsewhere.
[0056] Furthermore, locate the DOM element mathematical objects that have changed in the refreshed LaTeX formulas and highlight them with animation hints, including:
[0057] Record the positions of the source DOM element mathematical object and the target DOM element mathematical object in the LaTeX formula;
[0058] Calculates the number of DOM element mathematical objects that are added or removed after performing mathematical operations;
[0059] Calculate the position of the mathematical object of the DOM element that has changed after mathematical operations in the LaTeX formula;
[0060] Add a highlight animation to the mathematical object of the DOM element at the calculated position after the refresh.
[0061] The present invention also proposes a computer-readable storage medium, wherein when the instructions in the storage medium are executed by the processor of an electronic device, the electronic device is able to perform the above-described method for automatic mathematical calculation of formulas based on LaTeX.
[0062] The present invention also proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the above-described method for automatic mathematical calculation of formulas based on LaTeX.
[0063] This invention brings at least the following beneficial effects:
[0064] No need to manually copy or select code to copy and paste; simply drag and drop to copy a line, improving efficiency and reducing errors.
[0065] The LaTeX formulas are easy to read and can be directly manipulated, conforming to natural mathematical language habits, making them easy for primary and secondary school students to learn.
[0066] Automatic prompts indicate whether the calculation is possible, saving you the mental effort of visually observing formulas;
[0067] Simple point-and-drop operations allow you to specify the objects to be operated on, and the calculation process is completed automatically without the need for mechanical calculations by the human brain.
[0068] Abundant animated prompts help people quickly distinguish between the changing and constant parts of a formula, saving them the mental effort of visually searching for differences;
[0069] After completing the formula derivation, the corresponding accurate LaTeX code can be obtained immediately and used for other purposes.
[0070] In summary, this invention can liberate people from most of the mechanical mental labor in the process of deriving mathematical formulas, allowing people to concentrate their energy on mathematical thinking and thus focus on making decisions rather than doing calculations. Attached Figure Description
[0071] Figure 1 This is a flowchart of the method for automatic mathematical calculation of formulas based on LaTeX according to the present invention;
[0072] Figure 2 This is a schematic diagram illustrating the set of DOM element mathematical objects in a LaTeX formula and the set of string mathematical objects in LaTeX code, according to an embodiment of the present invention.
[0073] Figure 3 This is a schematic diagram illustrating how different colors are used to highlight placeable DOM element mathematical objects when a user drags and drops a DOM element mathematical object, according to an embodiment of the present invention.
[0074] Figure 4 This is a schematic diagram of the electronic device for automatic mathematical calculation of formulas based on LaTeX, according to the present invention. Detailed Implementation
[0075] The technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0076] This embodiment will achieve the following functions: when a user drags an item in a LaTeX formula, all similar items that can be merged will be automatically highlighted; when the item is dragged onto another similar item and placed down, the two similar items will be automatically merged; when there are other similar items at the same level, the user will be prompted whether to merge all of them, and the user will perform the corresponding operation by clicking the button.
[0077] To implement the above functions on the webpage, we first use MathJax.js to convert the input LaTeX code into an initial LaTeX formula. Here, we need to set the output format of the LaTeX formula to CHTML format.
[0078] S101, Check if the LaTeX code contains a text fragment of the form (X)_{a}^{b}. If it does, replace it with {(X)}_{a}^{b} and refresh the formula rendering. This step prevents errors in selecting the set of brackets for DOM elements due to a messy LaTeX formula structure.
[0079] Using jQuery.js, the code `$('.mjx-mo:contains("(")')` retrieves all left parentheses of DOM elements, and similarly, all right parentheses can be retrieved. Based on the parenthesis pairings, each pair of DOM element parentheses and all DOM elements within them are enclosed in a `span` element, which is then given the class name "isBracket" and placed in the original position of the parentheses.
[0080] Use code like $('.mjx-mo:contains("+")') to get all DOM element plus signs; similarly, you can get all DOM element minus signs. Using a DOM element plus or minus sign as a separator, take all sibling elements before the first DOM element with a plus or minus sign as the first item. Take each DOM element with a plus or minus sign and all other sibling elements after it up to the separator or end as an item. Place each item into a span element, assign the span element the class name "isTerm", and place this span element in the original item's position.
[0081] S102, the code $(".isTerm") can be used to get a collection of all DOM element items; the code $(".isBracket") can be used to get a collection of all DOM element brackets.
[0082] Analyzing the LaTeX code: After removing environment description code text fragments such as \begin{align} and \end{align}, the text of each polynomial code segment is obtained by using the equals sign = and the newline character \\ as delimiters. For each polynomial code text segment, the plus sign + or minus sign - is used as the delimiter (but the plus or minus sign inside a pair of parentheses is excluded; if the parentheses contain plus or minus signs, the entire content inside the parentheses is treated as a polynomial). The code text segment before the first plus sign + or minus sign - of the polynomial is taken as the first item, and the code text segment after each plus sign + or minus sign - up to the delimiter or end is taken as an item. The code text of each item, its polynomial number, start position, end position, etc., are packaged and stored in the same array to obtain the collection of string items.
[0083] Analyze the code for each term: Use regular expressions such as / \d+(\.\d+)? / to extract the complete coefficient code text; extract a pair of parentheses and all the content inside the parentheses as a factor; extract code text fragments of the form \log_{a}{b} as a logarithmic factor; extract code text fragments of the form X_{a}^{b} as a power factor; extract code text fragments of the form \frac{a}{b} as a fractional factor; similarly, factorials, radicals, trigonometric functions, and other factors are also extracted according to their specific code text format.
[0084] Adjust the order of elements in a collection of DOM element items or a collection of string items so that they mathematically correspond one-to-one. For example... Figure 2 As shown, array 201 is a set of string items after the order has been adjusted, and set 202 is a set of DOM element items after the order has been adjusted. The elements with corresponding numbers in the two arrays are the corresponding string items and DOM element items.
[0085] S103 uses jquery-ui.js and the code $(".isTerm").draggable() to add draggable functionality to all DOM elements.
[0086] Create a multi-select button. When the button is pressed, enter multi-select mode, add selectability to all DOM elements, and simultaneously disable draggable functionality for all DOM elements. When a DOM element is clicked, add the class name "isSelected" to it (distinguished by blue) and enable its draggable functionality. When a DOM element with the "isSelected" class name is clicked, remove the class name and disable its draggable functionality. When multi-select mode is deactivated, enable draggable functionality for all DOM elements.
[0087] Use code like `$(".isTerm").droppable({accept:function(){}, drop:function(){}})` to add droppable functionality to all DOM element items. The `accept` function limits each DOM element item to accepting all its sibling DOM elements.
[0088] S104, when a DOM element is dragged, each dropable DOM element that receives it is compared with the dragged DOM element. Here, the LaTeX code of the corresponding string items is compared, separating the symbols, coefficients, and factors other than coefficients from each code text. For each factor in the source string item (excluding coefficients), the corresponding factor is searched one by one in the target string item. If they match one-to-one (not necessarily in order), the two items are of the same type, and the corresponding dropable DOM element item is given the class name "isLike" in green; otherwise, they are not of the same type, and the corresponding dropable DOM element item is given the class name "isUnlike" in red. For example... Figure 3 As shown, when DOM element 301 is dragged, DOM element items 303 and 304, which are of the same type as it, are highlighted in green, while DOM element items 302, 305, 306, and 307, which are not of the same type as it, are highlighted in red.
[0089] When more than one DOM element is selected in multi-select mode, dragging one of the DOM elements will drag all the selected DOM elements together. In this case, the process first checks if all selected items are of the same type. If so, one of the selected items is compared with each of the drop-able DOM elements that accept it, and the drop-able DOM elements are assigned the class name "isLike" or "isUnlike" based on whether they are of the same type. If not, the drop-able DOM elements are assigned the class name "isUnlike".
[0090] When a DOM element is dragged into a placeable DOM element, the placeable DOM element's color darkens to indicate that it will be placed on top of it; when it is dragged away from the placeable DOM element, its color returns to normal.
[0091] S105, the dragged DOM element item, including multiple selected DOM elements dragged together, is the source DOM element item; the placed DOM element item is the target DOM element item.
[0092] S106. When the source DOM element is placed on the target DOM element containing the "isLike" class, it is determined that the user wants to merge similar items. If, in addition to the source DOM element and the target DOM element, there are n other DOM element items containing the "isLike" class (n≥1), a pop-up prompts "Merge the remaining n similar items in the target polynomial?", and provides the options "Merge all" and "Merge selected".
[0093] If the user selects "Merge All", the remaining n DOM element items containing the "isLike" class will be appended to the source DOM element item set.
[0094] Record the position of the target DOM element in the DOM document tree, and record the number of source DOM elements that precede the target DOM element.
[0095] S107 adds an animation to the width of all source DOM element items, gradually fading to 0, smoothly demonstrating the process of related items disappearing when merging similar items.
[0096] S108: Based on the sequential position of each source DOM element item in the set of all DOM element items, find the element at the corresponding sequential position in the set of string items, and you can get the corresponding code text, its position in the polynomial, its starting position, its ending position, and other information; the same applies to the target DOM element item.
[0097] S109, Modification of LaTeX code for merging like items: In this embodiment, since it is placed on the target DOM element containing the "isLike" class, it can be ensured that the source string item and the target string item are like items, so there is no need to compare them again; Separate the symbols and coefficients in the code text of each source string item and target string item, convert them into numbers for addition and subtraction operations; Convert the calculated numbers into strings, and combine them with factors other than the coefficient of the target string item to obtain the string item after merging like items.
[0098] S110: After modifying the LaTeX code to merge like terms, remove all source and target string term code text from the polynomial code text containing the target string term. Then, fill the original target string term's code text into the merged string term's position to obtain the concatenated polynomial code text. Concatenate the equals sign = and newline character \\ with the polynomial code text one by one, and then concatenate them back into the environment description code text fragments such as \begin{align} and \end{align} to obtain the complete modified LaTeX code. Clear the LaTeX code input box, then place the complete modified LaTeX code into the LaTeX code input box, and use MathJax.js to refresh the rendering and display of the LaTeX formula.
[0099] S111: Based on the previously recorded position of the target DOM element in the DOM document tree and the number of source DOM elements preceding the target DOM element, calculate the position of the DOM element after merging similar items in the DOM document tree after the LaTeX formula refresh, and add a highlight animation to the DOM element at this position.
[0100] To implement the above embodiments, the present invention also proposes a computer-readable storage medium. When the instructions in this computer-readable storage medium are executed by the processor of an electronic device, the electronic device is able to perform the previously described method for automatic mathematical calculations of formulas based on LaTeX. Optionally, the computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, or optical data storage device, etc.
[0101] like Figure 4 As shown, the present invention also proposes an electronic device, including a processor 401, a memory 402, and a computer program 403 stored in the memory and executable on the processor. When the processor 401 executes the computer program 403, it implements the method for automatic mathematical calculation of formulas based on LaTeX as described above.
[0102] Although embodiments of the present invention have been shown and described above, they should not be construed as limiting the scope of the invention. It should be noted that those skilled in the art can make various modifications and alterations without departing from the inventive concept, and these modifications and alterations are all within the scope of protection of the present invention. The scope of protection of the present invention should be determined by the appended claims.
Claims
1. A method for automatic mathematical calculation of formulas based on LaTeX, characterized in that, include: Preprocessing of LaTeX formulas and LaTeX code; Retrieves a collection of mathematical objects of DOM elements in a LaTeX formula; Retrieves a collection of string math objects from LaTeX code; Determine the selectable DOM element mathematical objects in a LaTeX formula; Identify draggable DOM element mathematical objects in LaTeX formulas; Determine the DOM element mathematical objects that can be placed in the LaTeX formula; Use different colors to highlight the placeable DOM element mathematical objects when the user drags and drops them; The source DOM element mathematical object and the target DOM element mathematical object are determined based on the user's selection, dragging, and placement operations; Detect the ambiguity of mathematical operations that may exist in selection, drag, and placement events, and prompt the user to make a choice among the possible mathematical operations; Add animation effects to related DOM elements during mathematical operations, such as changing color, moving, disappearing, and being added to the mathematical object; Based on the positions of the source DOM element mathematical object and the target DOM element mathematical object in the set of DOM element mathematical objects in the LaTeX formula, find the LaTeX code of the source string mathematical object and the target string mathematical object at the corresponding positions in the set of string mathematical objects in the corresponding LaTeX code; Based on the types of the source DOM element mathematical objects and the target DOM element mathematical objects and their positions in the LaTeX formula, and according to the mathematical operations selected by the user, the LaTeX code of the source string mathematical objects and the target string mathematical objects is modified to conform to the corresponding mathematical operations. The modified LaTeX code is then assembled, placed into the LaTeX code input box, and the rendering and display of the LaTeX formula are refreshed. Locate the DOM element mathematical objects that have changed in the refreshed LaTeX formula and highlight them with animation hints.
2. The method for automatic mathematical calculation of formulas based on LaTeX as described in claim 1, characterized in that, The preprocessing of LaTeX formulas and LaTeX code includes: Package each polynomial to the left and right of each equal sign in the LaTeX formula into a separate DOM element; Package each term in a LaTeX formula into a DOM element; Pack each factor in a LaTeX formula that consists of multiple sibling DOM elements into a single DOM element. It detects and automatically corrects every instance of LaTeX code that might cause confusion in the structure of LaTeX formulas.
3. The method for automatic mathematical calculation of formulas based on LaTeX as described in claim 1, characterized in that, The set of DOM element mathematical objects in the LaTeX formula and the set of string mathematical objects in the LaTeX code respectively include: The set of all plus and minus signs; The set of all multiplication signs; The set of all equal signs; The set of all polynomials; The set of all items; The set of all parentheses; The set of all factors; The set of all fractions; The set of all radicals; The set of all triple curly braces; The set of all indices; The set of all formulas to be substituted.
4. The method for automatic mathematical calculation of formulas based on LaTeX as described in claim 1, characterized in that, The determination of selectable DOM element mathematical objects in a LaTeX formula includes: When a user enables multi-select mode and clicks to select one of the draggable DOM element mathematical objects, mark this DOM element mathematical object as selected; Based on the selected DOM element mathematical object, the range of selectable DOM element mathematical objects is limited to those DOM element mathematical objects of the same level and type that can participate in mathematical operations simultaneously.
5. The method for automatic mathematical calculation of formulas based on LaTeX as described in claim 1, characterized in that, The process of determining the draggable DOM element mathematical object in the LaTeX formula includes: When no DOM element math objects are marked as selected, draggable DOM element math objects include all equal signs, terms, factors, exponents, parentheses, and formulas to be substituted. When an existing DOM element is marked as selected, the draggable DOM element is limited to the DOM element marked as selected.
6. The method for automatic mathematical calculation of formulas based on LaTeX as described in claim 1, characterized in that, The determination of the DOM element mathematical objects that can be placed in the LaTeX formula includes: The source DOM element's mathematical object is determined by selection and drag events; Based on the position of the source DOM element mathematical object in the LaTeX formula, the placeable DOM element mathematical objects are limited to all DOM element mathematical objects at the corresponding positions that may participate in the calculation.
7. The method for automatic mathematical calculation of formulas based on LaTeX as described in claim 1, characterized in that, The method of highlighting dropable DOM element mathematical objects with different colors when the user drags and drops them includes: Compare each of the placeable DOM element mathematical objects with the source DOM element mathematical object, or compare the LaTeX code of the corresponding string mathematical objects of the two to determine whether they are the same mathematical elements; Placeable DOM element mathematical objects that have the same mathematical elements as the source DOM element mathematical object are marked with a certain color to indicate that they can be used for mathematical operations, while those that are different are marked with a certain color to indicate that they can be sorted or toggled.
8. The method for automatic mathematical calculation of formulas based on LaTeX as described in claim 1, characterized in that, The modification of the LaTeX code for the source and target string mathematical objects according to their types and positions in the LaTeX formula, and based on the mathematical operations selected by the user, includes: Based on the types of the source DOM element mathematical objects and the target DOM element mathematical objects, and their positions in the LaTeX formula, and according to the mathematical operation selected by the user, determine which mathematical operation or operation will be performed, including addition, subtraction, multiplication, division, multiplication distribution, factoring out common factors, polynomial exponentiation expansion, splitting terms, adding or subtracting the same term, factoring, multiplying or dividing the same factor, adding parentheses, removing parentheses, substituting into a formula, adding, subtracting, multiplying or dividing both sides of two equations, multiplying or dividing both sides of an equation by the same factor, transposing terms, sorting, switching parenthesis forms, and copying equations; The LaTeX code of the source string mathematical object and the target string mathematical object are compared, or the corresponding DOM element mathematical objects are compared to determine whether they are the same mathematical elements. Separate the mathematical elements in the LaTeX code of the source string mathematical object and the target string mathematical object, including the symbols, coefficients and factors in the terms, the terms in parentheses, and custom wildcards used to represent arbitrary mathematical elements; According to the rules of mathematical operations, calculate and process the mathematical elements in LaTeX code, including calculating and processing symbols, coefficients, factors, exponents, terms, and parentheses.
9. The method for automatic mathematical calculation of formulas based on LaTeX as described in claim 7 or 8, characterized in that, The determination of whether mathematical elements are the same supports both out-of-order recognition and wildcard recognition, including: Two terms formed by different arrangements of the same set of factors can be identified and judged as having the same mathematical elements. The same set of several items, arranged in different ways, can be identified and judged as the same mathematical elements when enclosed in two parentheses; Wildcards with specific structures can match any number of mathematical elements from the corresponding position to the end marker.
10. The method for automatic mathematical calculation of formulas based on LaTeX as described in claim 1, characterized in that, The step of finding and highlighting the changed DOM element mathematical objects in the refreshed LaTeX formula includes: Record the positions of the source DOM element mathematical object and the target DOM element mathematical object in the LaTeX formula; Calculates the number of DOM element mathematical objects that are added or removed after performing mathematical operations; Calculate the position of the mathematical object of the DOM element that has changed after mathematical operations in the LaTeX formula; Add a highlight animation to the mathematical object of the DOM element at the calculated position after the refresh.
11. A computer-readable storage medium, characterized in that, When the instructions in the storage medium are executed by the processor of the electronic device, the electronic device is able to perform the method as described in any one of claims 1-8 or 10.
12. An electronic device, characterized in that, It includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, it implements the method as described in any one of claims 1-8 or 10.