Search

CN-116069293-B - Method, medium and equipment for realizing automatic mathematical operation of formula based on LaTeX

CN116069293BCN 116069293 BCN116069293 BCN 116069293BCN-116069293-B

Abstract

The invention discloses a method, a storage medium and electronic equipment for realizing automatic mathematical operation of a formula based on LaTeX, wherein the method comprises the steps of preprocessing the LaTeX formula and codes; acquiring a LaTeX formula and a set of mathematical objects in codes, determining a DOM element mathematical object which can be selected, dragged and placed in the LaTeX formula, highlighting the DOM element mathematical object which can be placed when dragged, determining a source DOM element mathematical object and a target DOM element mathematical object, prompting a user to select among a plurality of possible mathematical operations, adding an animation effect in the mathematical operation process, finding LaTeX codes of the corresponding source and target character string mathematical objects, modifying the LaTeX codes according with the mathematical operation, refreshing the formula, and prompting the changed DOM element mathematical object by the animation. The invention provides a new formula deduction mode, which relieves most of mechanical brain work in the mathematical formula deduction process.

Inventors

  • HUANG KAIPENG

Assignees

  • 黄凯鹏

Dates

Publication Date
20260512
Application Date
20230228

Claims (12)

  1. 1. A method for implementing automatic mathematical operation of a formula based on LaTeX, comprising: Preprocessing a LaTeX formula and LaTeX codes; acquiring a set of DOM element mathematical objects in a LaTeX formula; acquiring a set of character string mathematical objects in LaTeX codes; determining a selectable DOM element mathematical object in the LaTeX formula; determining a draggable DOM element mathematical object in a LaTeX formula; determining a DOM element mathematical object which can be placed in a LaTeX formula; highlighting the placeable DOM element mathematical object with different colors when the user drags the DOM element mathematical object; Determining a source DOM element mathematical object and a target DOM element mathematical object according to selection, dragging and placing operations of a user; Detecting ambiguity of mathematical operations that may exist for selection, dragging, and dropping events, prompting a user to select among possible multiple mathematical operations; adding animation effects of changing colors, moving, disappearing and adding related DOM element mathematical objects in the mathematical operation process; according to the positions of the source DOM element mathematical object and the target DOM element mathematical object in the DOM element mathematical object set in the LaTeX formula, finding out LaTeX codes of the source character string mathematical object and the target character string mathematical object corresponding to the corresponding positions in the character string mathematical object set in the LaTeX codes; Modifying LaTeX codes of the source character string mathematical object and the target character string mathematical object according to the types of the source DOM element mathematical object and the target DOM element mathematical object and the positions of the source DOM element mathematical object and the target DOM element mathematical object in the LaTeX formula and according to mathematical operations selected by a user; splicing and integrating the modified LaTeX codes, placing the LaTeX codes into a LaTeX code input box, and refreshing the rendering and display of a LaTeX formula; Find the changed DOM element mathematical object in the LaTeX formula after refreshing and highlight the animation prompt.
  2. 2. The method for performing automatic mathematical operations of a formula based on LaTeX as set forth in claim 1, wherein the preprocessing of LaTeX formulas and LaTeX codes comprises: packaging each polynomial of each equal sign in the LaTeX formula into a DOM element respectively; packaging each item in the LaTeX formula into a DOM element; Packing each factor formed by a plurality of DOM elements at the same level in the LaTeX formula into a DOM element; Each LaTeX code that may cause confusion in the LaTeX formula structure is detected and automatically corrected.
  3. 3. The method for realizing automatic mathematical operation of a formula based on LaTeX as claimed in claim 1, wherein the collection of DOM element mathematical objects in the LaTeX formula and the collection of string mathematical objects in LaTeX code respectively comprise: a set of all plus and minus signs; A set of all multiplier numbers; a set of all equal signs; a set of all polynomials; a collection of all items; a set of all brackets; a set of all factors; a set of all scores; A set of all roots; a set of all triple curly brackets; a set of all indices; all sets of formulas to be substituted.
  4. 4. The method for implementing automatic mathematical operations of a formula based on LaTeX as claimed in claim 1, wherein determining the selectable DOM element mathematical objects in the LaTeX formula comprises: When a user opens a multi-selection mode and clicks and selects one draggable DOM element mathematical object, marking the DOM element mathematical object as selected; And defining the selectable DOM element mathematical object range as DOM element mathematical objects which are of the same type and can participate in mathematical operation at the same time according to the selected DOM element mathematical object.
  5. 5. The method for implementing automatic mathematical operations of a formula based on LaTeX as claimed in claim 1, wherein the determining a draggable DOM element mathematical object in LaTeX formula comprises: when no DOM element mathematical object is marked as selected, the draggable DOM element mathematical object comprises all equal signs, terms, factors, indexes, brackets and formulas to be substituted; when an existing DOM element mathematical object is marked as selected, the draggable DOM element mathematical object is defined as the DOM element mathematical object marked as selected.
  6. 6. The method for implementing automatic mathematical operations of a formula based on LaTeX as claimed in claim 1, wherein the determining a mathematical object of a DOM element placeable in the LaTeX formula comprises: determining a source DOM element mathematical object by a selection and dragging event; and defining the placeable DOM element mathematical objects as DOM element mathematical objects at all corresponding positions possibly participating in operation according to the positions of the source DOM element mathematical objects in the LaTeX formula.
  7. 7. The method for realizing automatic mathematical operation of a formula based on LaTeX of claim 1, wherein highlighting the placeable DOM element mathematical object with a different color when the user drags the DOM element mathematical object comprises: Comparing each placeable DOM element mathematical object with the source DOM element mathematical object, or comparing LaTeX codes of the character string mathematical objects corresponding to the two mathematical objects, and judging whether the mathematical objects are the same mathematical elements; marking the placeable DOM element mathematical object which is the same mathematical element as the source DOM element mathematical object as being capable of mathematical operation by a certain color, and marking the placeable DOM element mathematical object which is different as being capable of ordering or switching by a certain color.
  8. 8. The method for realizing automatic mathematical operation of formula based on LaTeX according to claim 1, wherein modifying LaTeX codes of source string mathematical object and target string mathematical object according to the types of source DOM element mathematical object and target DOM element mathematical object and the positions thereof in LaTeX formula and according to mathematical operation selected by user comprises: Judging which mathematical operation or operation is to be performed according to the types of the source DOM element mathematical object and the target DOM element mathematical object and the positions of the source DOM element mathematical object in the LaTeX formula and according to mathematical operations selected by a user, wherein the mathematical operations comprise adding, subtracting, multiplying, dividing, multiplying and distributing, extracting a common factor, expanding polynomial power, dividing terms, adding and subtracting the same term, dividing the factor, multiplying and dividing the same factor, adding brackets, removing brackets, substituting formulas, respectively adding or subtracting or multiplying or dividing two sides of two equations, simultaneously multiplying or dividing the same factor, shifting terms, sequencing, switching bracket forms and copying equations; Comparing the LaTeX codes of the source character string mathematical object and the target character string mathematical object, or comparing DOM element mathematical objects corresponding to the source character string mathematical object and the target character string mathematical object, and judging whether the source character string mathematical object and the target character string mathematical object are the same mathematical element; Separating mathematical elements in LaTeX codes of the source character string mathematical object and the target character string mathematical object, wherein the mathematical elements comprise symbols and coefficients in terms, factors in terms, terms in brackets and custom wild cards used for representing any mathematical element; Mathematical elements in the LaTeX code are calculated and processed respectively according to rules of mathematical operation, including calculating and processing symbols, coefficients, factors, indexes, terms and brackets.
  9. 9. The method for realizing automatic mathematical operation of a formula based on LaTeX as claimed in claim 7 or 8, wherein the determining whether the mathematical elements are identical or not supports both disorder recognition and wild card recognition, comprises: Two items formed by the same group of a plurality of factors in different arrangements can be identified and judged as the same mathematical element; The same set of several items are included in two brackets in different arrangements, identifiable and judged as the same mathematical element; wild cards of a particular structure may match any number of mathematical elements from the corresponding location to the end mark.
  10. 10. The method for realizing automatic mathematical operation of a formula based on LaTeX as claimed in claim 1, wherein the steps of finding the changed mathematical object of DOM element in the refreshed LaTeX formula and highlighting the animation prompt comprise: Recording the positions of a source DOM element mathematical object and a target DOM element mathematical object in a LaTeX formula; calculating the number of DOM element mathematical objects that increase or decrease after performing the mathematical operation; Calculating the position of the DOM element mathematical object which changes after mathematical operation in the LaTeX formula; and adding highlight animation to the DOM element mathematical object at the pushed position after refreshing.
  11. 11. A computer readable storage medium, characterized in that instructions in the storage medium, when executed by a processor of an electronic device, enable the electronic device to perform the method of any one of claims 1-8 or 10.
  12. 12. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the method of any one of claims 1-8 or 10 when the program is executed.

Description

Method, medium and equipment for realizing automatic mathematical operation of formula based on LaTeX Technical Field The invention relates to the technical field of computers, in particular to a method for realizing automatic mathematical operation of a formula based on LaTeX, a storage medium and electronic equipment. Background In the teaching and research process of mathematics and related disciplines, formula derivation is inevitably carried out, but traditional handwriting formula derivation efficiency is too low, and the problems of high expenditure on observing the operational part, manual calculation, time consumption for writing, complex transcription of the unchanged part, easy copying and error calculation, and difficult error checking are presented. At present, some mathematical software such as MATLAB is used, and some deduction processes of formulas can be realized by a computer, including combination of similar items, polynomial expansion, factorization and the like, but in the man-machine interaction process, only character string texts which can be understood by the computer can be used, so that the problems that people read the character string texts difficultly, the positions of the edited character string texts are easy to find out, and the like are solved, and the corresponding code knowledge is required to be learned, so that the problem of high learning cost is solved. In teaching, even if a teacher edits the formula derivation process in advance, the formula derivation process is displayed one line at a time by using a slide in class, students should carefully observe whether partial operation processes of which the formula is unchanged, where the formula is changed and the formula is changed in the upper line and the lower line can be understood or not when the students understand the derivation process, and the teaching is very mental. The prior art can convert the text code of the character string into a formula conforming to the reading habit of people by using a computer, for example, can convert the LaTeX code into a LaTeX formula on a webpage, and can change the LaTeX formula by modifying the LaTeX code, but cannot change the LaTeX code by operating the LaTeX formula. Disclosure of Invention In view of the above background, the invention aims to provide a method, a storage medium and electronic equipment for realizing automatic mathematical operation of a formula based on LaTeX, and provides a novel man-machine interaction mode for deducing a formula which is simple to operate, clear and difficult to make mistakes, wherein a user can finish the automatic mathematical operation of mathematical elements in the formula by only selecting and dragging and dropping a part which needs to be operated in the LaTeX formula, thereby realizing quick and accurate formula deduction, automatically giving out prompts which can be operated when the user drags, saving the mental consumption of people for observing the formula by naked eyes, avoiding manual transcription and almost eliminating manual editing codes, reducing the possibility of human mistakes, and enabling students to see more clear calculation details and understand the idea deduction of the formula during the operation of the user. The invention provides a method for realizing automatic mathematical operation of a formula based on LaTeX, which adopts the following technical scheme: Preprocessing a LaTeX formula and LaTeX codes; acquiring a set of DOM element mathematical objects in a LaTeX formula; acquiring a set of character string mathematical objects in LaTeX codes; determining a selectable DOM element mathematical object in the LaTeX formula; determining a draggable DOM element mathematical object in a LaTeX formula; determining a DOM element mathematical object which can be placed in a LaTeX formula; highlighting the placeable DOM element mathematical object with different colors when the user drags the DOM element mathematical object; Determining a source DOM element mathematical object and a target DOM element mathematical object according to selection, dragging and placing operations of a user; Detecting ambiguity of mathematical operations that may exist for selection, dragging, and dropping events, prompting a user to select among possible multiple mathematical operations; adding animation effects of changing colors, moving, disappearing and adding related DOM element mathematical objects in the mathematical operation process; according to the positions of the source DOM element mathematical object and the target DOM element mathematical object in the DOM element mathematical object set in the LaTeX formula, finding out LaTeX codes of the source character string mathematical object and the target character string mathematical object corresponding to the corresponding positions in the character string mathematical object set in the LaTeX codes; Modifying LaTeX codes of the source character string mathematical object a