A method, apparatus, computer device, and storage medium for line wrapping of formulas
By splitting complex formulas into multiple mathematical markup language fragments and rendering, the problem of line-breaking complex formulas in the prior art in different display devices and browsers is solved, achieving better display effect and user experience.
Patent Information
- Application Number
- CN202210119418.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-08
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2042-02-08
AI Technical Summary
The prior art is difficult to effectively adaptively and complex mathematical formulas for wrapping lines in different display devices and browsers, resulting in line break errors or poor viewing.
By obtaining the object file based on the mathematical markup language description of the pending formula, and splitting the node into multiple mathematical markup language fragments based on the preset line break rules, rendering to display the formula.
It realizes adaptive line wrapping of complex formulas in different display devices and browsers, improving the presentation effect and user experience of formulas.
Smart Images

Figure CN114443997B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technologies, and in particular, to a method, an apparatus, a computer device, and a storage medium for line wrapping of formulas. Background Art
[0002] With the rapid development of the Internet industry, due to the advantages of fast update and high timeliness of Internet content information, more people like to learn new knowledge and understand more different content on the Internet. Then, in order to facilitate users to view articles, during online browsing, the text content displayed on the web page needs to be adaptively typeset and adjusted according to the different display devices or browsers used by the users.
[0003] Among them, articles in the fields of mathematical and physical sciences generally contain a large number of complex formulas. When users view articles in the fields of mathematical and physical sciences using different display devices or browsers, due to different limitations on the line width of the articles by different display devices or browsers, the complex formulas need to be adaptively line-wrapped to adapt to the typesetting of the web page, so as to achieve a better viewing effect. Therefore, how to make the complex formulas in the web page be adaptively line-wrapped and typeset has become an urgent problem to be solved. Summary of the Invention
[0004] The embodiments of the present disclosure at least provide a method, an apparatus, a computer device, and a storage medium for line wrapping of formulas.
[0005] In a first aspect, the embodiments of the present disclosure provide a method for line wrapping of formulas, including:
[0006] Obtaining a target file corresponding to a formula to be processed and described in Mathematical Markup Language;
[0007] Based on a preset line wrapping rule, splitting nodes in the target file into multiple Mathematical Markup Language segments; wherein, the nodes are used to represent operators or operation parameters in the formula to be processed, nodes in the same Mathematical Markup Language segment are on the same line, and nodes in different Mathematical Markup Language segments may be on different lines;
[0008] Rendering based on the multiple Mathematical Markup Language segments to display the formula to be processed.
[0009] In a possible implementation manner, the obtaining a target file corresponding to a formula to be processed and described in Mathematical Markup Language includes:
[0010] Obtaining a text file containing the formula to be processed and other characters and represented in a first format;
[0011] Obtaining a target text corresponding to the formula to be processed from the text file;
[0012] Convert the target text from the first format to the MathML format to obtain the target file;
[0013] The rendering based on the multiple MathML segments includes:
[0014] Render based on the multiple MathML segments and render based on other characters in the text file except the target text to display the formula to be processed and the other characters.
[0015] In a possible implementation, the target file includes first-level nodes not nested under other nodes and second-level nodes nested under other nodes;
[0016] The splitting of the nodes in the target file into multiple MathML segments based on a preset line break rule includes:
[0017] Split the first-level nodes in the target file into multiple MathML segments based on a preset line break rule.
[0018] In a possible implementation, the nodes in the target file are arranged in the display order of the operators or operation parameters corresponding to the nodes in the formula to be processed;
[0019] The splitting of the nodes in the target file into multiple MathML segments based on a preset line break rule, traverse the nodes in the target file in the display order, and for each node, perform the following operations:
[0020] For the Nth node in the target file, determine whether the operator or operation parameter represented by the node satisfies the line break rule;
[0021] If not, cache the Nth node in an array;
[0022] If so, splice the Nth node and the previously stored nodes in the array into a MathML segment, store the spliced MathML segment, and empty the array; where N is an integer.
[0023] In a possible implementation, the preset line break rule includes:
[0024] Line break at the first target symbol, do not line break at the second target symbol, and do not line break for consecutive numbers.
[0025] In a possible implementation, the rendering based on the multiple MathML segments includes:
[0026] Render all the split MathML segments into an image file;
[0027] Display the image files corresponding to the multiple MathML fragments in the stated display order.
[0028] In a possible implementation, for the Nth node in the target file, after determining whether the operator or operation parameter represented by the node satisfies the line break rule, the method further includes:
[0029] If not, cache the Nth node in an array;
[0030] If so, splice the previously stored nodes in the array into a MathML fragment, store the spliced MathML fragment, clear the array, and cache the Nth node in the cleared array.
[0031] In a second aspect, an embodiment of the present disclosure further provides a formula line break device, including:
[0032] An acquisition module, configured to acquire a target file described in MathML corresponding to a formula to be processed;
[0033] A splitting module, configured to split the nodes in the target file into multiple MathML fragments based on a preset line break rule; wherein, the nodes are used to represent operators or operation parameters in the formula to be processed, and the nodes in the same MathML fragment are on the same line, and the nodes in different MathML fragments may be on different lines;
[0034] A display module, configured to perform rendering based on the multiple MathML fragments to display the formula to be processed.
[0035] In a possible implementation, when acquiring the target file described in MathML corresponding to the formula to be processed, the acquisition module is configured to:
[0036] Acquire a text file containing the formula to be processed and other characters, represented in a first format;
[0037] Acquire the target text corresponding to the formula to be processed from the text file;
[0038] Convert the target text from the first format to the MathML format to obtain the target file;
[0039] When performing rendering based on the multiple MathML fragments, the display module is configured to:
[0040] Perform rendering based on the multiple MathML fragments and perform rendering based on other characters in the text file except the target text to display the formula to be processed and the other characters.
[0041] In a possible implementation, the target file includes first-level nodes that are not nested under other nodes and second-level nodes that are nested under other nodes;
[0042] When splitting the nodes in the target file into multiple MathML fragments based on a preset line break rule, the splitting module is configured to:
[0043] Split the first-level nodes in the target file into multiple MathML fragments based on the preset line break rule.
[0044] In a possible implementation, the nodes in the target file are arranged in the display order of the operators or operation parameters corresponding to the nodes in the formula to be processed;
[0045] When splitting the nodes in the target file into multiple MathML fragments based on the preset line break rule, the splitting module is configured to traverse the nodes in the target file in the display order, and for each node, perform the following operations:
[0046] For the Nth node in the target file, determine whether the operator or operation parameter represented by the node satisfies the line break rule;
[0047] If not, cache the Nth node in an array;
[0048] If so, splice the Nth node and the previously stored nodes in the array into a MathML fragment, store the spliced MathML fragment, and clear the array; where N is an integer.
[0049] In a possible implementation, the preset line break rule includes:
[0050] Line break at the first target symbol, do not line break at the second target symbol, and do not line break for consecutive digits.
[0051] In a possible implementation, when rendering based on the multiple MathML fragments, the display module is configured to:
[0052] Render all the split MathML fragments into image files;
[0053] Display the image files corresponding to the multiple MathML fragments in the display order.
[0054] In a possible implementation, for the Nth node in the target file, after the splitting module determines whether the operator or operation parameter represented by the node satisfies the line break rule, it is further configured to:
[0055] If not satisfied, cache the Nth node into the array;
[0056] If satisfied, splice the previously stored nodes in the array into a MathML fragment, store the spliced MathML fragment, clear the array, and cache the Nth node into the cleared array.
[0057] In a third aspect, an embodiment of the present disclosure further provides a computer device, including: a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the computer device runs, the processor communicates with the memory through the bus. When the machine-readable instructions are executed by the processor, the steps in the above first aspect or any possible implementation manner in the first aspect are executed.
[0058] In a fourth aspect, an embodiment of the present disclosure further provides a computer-readable storage medium. A computer program is stored on the computer-readable storage medium. When the computer program is run by a processor, the steps in the above first aspect or any possible implementation manner in the first aspect are executed.
[0059] To make the above objects, features, and advantages of the present disclosure more obvious and understandable, the following specifically enumerates preferred embodiments and, in conjunction with the accompanying drawings, makes a detailed description as follows. Description of the Drawings
[0060] To more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following briefly introduces the drawings required to be used in the embodiments. The accompanying drawings are incorporated into the specification and constitute a part of this specification. These drawings show embodiments that conform to the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only show some embodiments of the present disclosure and should not be regarded as limiting the scope. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.
[0061] Figure 1 Shows a schematic diagram of possible problems that may occur with line breaks in the prior art;
[0062] Figure 2 Shows a flowchart of a method for line breaking of formulas provided by an embodiment of the present disclosure;
[0063] Figure 3 Shows a schematic diagram of the display of a text file to be line broken in the method for line breaking of formulas provided by an embodiment of the present disclosure;
[0064] Figure 4 Shows a schematic diagram of the array caching rule during node splitting in the method for line breaking of formulas provided by an embodiment of the present disclosure;
[0065] Figure 5 Shows a schematic diagram of the array cache rule during another node splitting in the method for line wrapping of formulas provided by the embodiments of the present disclosure;
[0066] Figure 6 Shows a schematic diagram of a device for line wrapping of formulas provided by the embodiments of the present disclosure;
[0067] Figure 7 Shows a schematic diagram of the structure of a computer device provided by the embodiments of the present disclosure. Detailed implementation manners
[0068] To make the objectives, technical solutions, and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only a part rather than all of the embodiments of the present disclosure. Components of the embodiments of the present disclosure generally described and illustrated in the accompanying drawings herein can be arranged and designed in a variety of different configurations. Therefore, the detailed description of the embodiments of the present disclosure provided in the accompanying drawings is not intended to limit the scope of the present disclosure to be protected, but merely represents selected embodiments of the present disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of the present disclosure without creative efforts fall within the scope of protection of the present disclosure.
[0069] When a user browses an article online, there can be multiple online browsing modes, and different online browsing modes can be carried by different display platforms and display carriers. Among them, the display platform can be an App (mobile application, Application), a web browser, etc.; the display carrier can be a mobile phone display screen or a computer monitor, etc. The user can use the App to browse relevant text on the mobile phone side, or browse relevant text content in a web page through a browser.
[0070] However, since different users select different online browsing modes, there are significant differences in the display effects produced after the combination of the display platform and the display carrier. Therefore, when browsing an article online, an App or a web browser generally can perform adaptive layout processing on the displayed article to achieve the best display effect.
[0071] Exemplarily, User A and User B browse the same paper content simultaneously. User A uses a 6-inch mobile phone with a screen aspect ratio of 9:16 and browses using an App. User B uses a 19-inch computer monitor with a screen aspect ratio of 16:9 and browses using a web browser. When User A displays the paper, perhaps 100 lines are needed to fully display the article. User B uses a computer monitor with a screen aspect ratio of 16:9 and can display more content in one line. Then, when User B displays the same paper content, perhaps 40 lines can fully display the article.
[0072] Similarly, when the article content browsed online is in the field of mathematical and physical sciences, using different online browsing modes, different Apps or web browsers will also perform adaptive typesetting processing on the mathematical and physical science articles to be displayed. Among them, generally, mathematical and physical science articles contain a large number of complex formulas, and these complex formulas also need to be typeset according to the typesetting methods of the App or web browser.
[0073] Therefore, when a mathematical and physical science article needs to be browsed online, when a complex formula is at the end of a line of the mathematical and physical science article to be displayed, the complex formula needs to adaptively wrap lines and be typeset mixed with other characters in the text file to achieve a better viewing effect.
[0074] It has been found through research that in the existing technology, when browsing online, there has been no relatively good solution to the problem of how to make the complex formulas in an article adaptively wrap lines, resulting in frequent line wrapping errors or poor visual effects when the existing complex formulas wrap lines.
[0075] Currently, one widely used implementation is the TeX system. Among them, the TeX system is an electronic typesetting system that is currently widely used in the fields of science and technology and mathematics. It can generate high-quality printed science and technology and mathematics documents in a short time, facilitating the rapid output of large papers or academic journals with excellent reading effects and improving the typesetting efficiency. Currently, the widely used typesetting engine based on the TeX typesetting system is the LaTeX typesetting engine. When a user wants to typeset science and technology and mathematics documents using the typesetting format of the TeX typesetting system, generally the LaTeX typesetting engine is used to typeset the article.
[0076] However, on the one hand, due to the limitations of the LaTeX typesetting engine, the formulas typeset by the LaTeX typesetting engine cannot adapt to all online browsing modes. On the other hand, when the formulas typeset by the LaTeX typesetting engine wrap lines, typesetting personnel need to manually add line break characters to the formulas to be wrapped, and the operation is rather cumbersome, which is not suitable for the fast-updated and highly time-sensitive Internet online browsing.
[0077] Another widely used implementation method is to directly perform online typesetting by MathJax (a math formula renderer for online scenarios). Specifically, MathJax can output a file described based on the Mathematical Markup Language MathML, enabling the file described based on MathML to adaptively wrap lines.
[0078] Among them, the Mathematical Markup Language MathML is a standard based on XML and is a markup language used to write mathematical symbols and formulas. Among them, XML is a general structured markup language widely used on the Internet, suitable for providing a unified transmission method to mark data and define data types, and has the advantage of being able to exchange data between incompatible systems.
[0079] However, since the formula part in the file described based on the Mathematical Markup Language MathML output by MathJax is a whole, when performing adaptive line wrapping, it is generally judged based on the current editing width and the preset line width. When the formula is too long, it may occur that the formula is displayed in multiple lines, but there are other characters interspersed in each line of the formula, as Figure 1 shown, and the display effect is poor.
[0080] Based on the above research, the present disclosure provides a method, device, computer device, and storage medium for formula line wrapping, which can obtain a target file described based on the Mathematical Markup Language corresponding to the formula to be processed, and at the same time, based on the preset line wrapping rules, split the nodes in the target file into multiple Mathematical Markup Language segments. This is equivalent to splitting the formula to be processed, which is an independent whole, into multiple independent wholes. The multiple operators or operation parameters corresponding to each Mathematical Markup Language segment can be regarded as an independent whole. Thus, when performing rendering, the multiple Mathematical Markup Language segments can perform adaptive line wrapping processing, improving the display effect of the formula.
[0081] Regarding the defects existing in the above solutions, they are all the results obtained by the inventors after practice and careful research. Therefore, the process of discovering the above problems and the solutions proposed by the present disclosure below for the above problems should all be the contributions made by the inventors to the present disclosure during the process of the present disclosure.
[0082] It should be noted that similar reference numerals and letters represent similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings.
[0083] To facilitate the understanding of this embodiment, first, a method for line wrapping of formulas disclosed in the embodiments of the present disclosure will be introduced in detail. The execution subject of the formula line wrapping method provided in the embodiments of the present disclosure is generally a terminal device or other processing devices with certain computing capabilities. Among them, the terminal device can be a smart phone, a PC (Personal Computer), a computing device, etc. In some possible implementation manners, the formula line wrapping method can be implemented by a processor calling computer-readable instructions stored in a memory.
[0084] Next, taking the execution subject as a terminal device as an example, the formula line wrapping method provided in the embodiments of the present disclosure will be described.
[0085] See Figure 2 As shown, it is a flowchart of a formula line wrapping method provided in the embodiments of the present disclosure. The method includes steps 201 to 203, where:
[0086] Step 201, obtain a target file corresponding to the formula to be processed and described in Mathematical Markup Language;
[0087] Step 202, based on a preset line wrapping rule, split the nodes in the target file into multiple Mathematical Markup Language segments; where the nodes are used to represent operators or operation parameters in the formula to be processed, and the nodes in the same Mathematical Markup Language segment are on the same line, and the nodes in different Mathematical Markup Language segments can be on different lines;
[0088] Step 203, perform rendering based on the multiple Mathematical Markup Language segments to display the formula to be processed.
[0089] Next, steps 201 to 203 will be introduced in detail.
[0090] Regarding step 201,
[0091] In practical applications of the Mathematical Markup Language, since most complex formulas contain a large number of mathematical symbols and cumbersome formula structures, and there are various logical relationships between symbols, the format of writing the Mathematical Markup Language is very cumbersome. Therefore, when dealing with complex formulas, most people do not directly write the Mathematical Markup Language, but use other tools to write.
[0092] In a possible implementation manner, when obtaining a target file corresponding to the formula to be processed and described in Mathematical Markup Language, it is possible to first obtain a text file containing the formula to be processed and other characters and represented in a first format, then obtain the target text corresponding to the formula to be processed from the text file, and convert the target text from the first format to the Mathematical Markup Language format to obtain the target file.
[0093] Exemplarily, the first format may be a typesetting format based on the TeX typesetting system, and the format of the text file containing the formula to be processed and other characters may be the LaTeX typesetting format. When converting the first format to the mathematical markup language format, exemplarily, a rendering tool may be used to convert the formula typeset by the LaTeX typesetting engine into a target file described based on the mathematical markup language. Among them, the rendering tool may use MathJax to convert the formula typeset by the LaTeX typesetting engine into a target file described based on the mathematical markup language. Since the mathematical markup language has the advantage of being able to exchange data between incompatible systems, the purpose of adapting the formula to be processed to multiple online browsing modes can be achieved.
[0094] In another possible implementation, the mathematical formula renderer MathJax may also be directly used to typeset the text file. Since MathJax supports being represented using the mathematical markup language and also supports typesetting using the LaTeX typesetting engine, the formula to be processed in the text file can be directly output as a target file described based on the mathematical markup language.
[0095] Regarding step 202,
[0096] The node is the smallest unit of a valid and complete structure in XML. Since the mathematical markup language is a standard based on XML, the target file also contains multiple nodes. In this solution, the node is used to represent the operator or operation parameter in the formula to be processed, and each node may contain multiple operators or operation parameters. The operator is a mathematical symbol, and the operation parameter may be a number or a letter, etc. Exemplarily, in the equation "x + y = 1", "=" and "+" are operators; "x", "y", and "1" are operation parameters.
[0097] In a possible implementation, the node may include a first-level node that is not nested under other nodes and a second-level node that is nested under other nodes; among them, the second-level node may further contain several sub-nodes, and the second-level node may be nested under the first-level node. Exemplarily, when the target file contains a fraction, a complete fraction is a first-level node that is not nested under other nodes in the target file, and the numerator and denominator are nested in the fraction, so they are second-level nodes nested under the first-level node.
[0098] In a possible implementation, the nodes in the target file are arranged in the order in which the operators or operation parameters corresponding to the nodes are displayed in the formula to be processed. Specifically, if the formula to be processed is "1+1+1+1+1+1=6", then each "1", "+", "=", and "6" in the expression is a node, and the corresponding nodes in the target file are arranged in the order in which they are displayed in the formula to be processed.
[0099] After the nodes in the target file are split into multiple mathematical markup language segments based on a preset line break rule, each single mathematical markup language segment is used to represent a separate, inseparable segment with independent mathematical meaning. The same mathematical markup language segment can contain multiple nodes. The nodes in the same mathematical markup language segment are located in the same line, and the nodes in different mathematical markup language segments can be located in different lines or in the same line.
[0100] In a possible implementation, the preset line break rules can be divided into two categories, namely, scenarios where line breaks are allowed and scenarios where line breaks are not allowed. In scenarios where line breaks are allowed, the corresponding nodes in the target file that allow line breaks can be split; in scenarios where line breaks are not allowed, the corresponding nodes that do not allow line breaks are not split.
[0101] The preset line breaking rules may exemplarily include: line breaking at the first target symbol, no line breaking at the second target symbol, and no line breaking for consecutive numbers.
[0102] The first target symbol is a symbol that allows line breaks in the formula. Specifically, when the formula breaks at the first target symbol position, the symbol expressing the meaning of the original formula will not be destroyed due to line break. Therefore, the first target symbol is classified as a scenario that allows line breaks.
[0103] For example, Figure 3 As shown, Figure 3 The example shown is a text file to be wrapped, the formula to be processed is "1+1+1+1+1+1=6", and the "+" is the end of the paragraph. Wrapping at the "+" will not destroy the actual meaning of the original formula to be processed, so the "+" belongs to the first target symbol, which is a scenario where wrapping is allowed.
[0104] In a possible implementation manner, the first target symbol may include symbols shown in the following Table 1:
[0105] Table 1
[0106]
[0107]
[0108] Among them, the mathematical symbol column, the LaTeX column, and the entity encoding column are used for the representation forms of the above symbols in different scenarios. Among them, the entity encoding column is an HTML encoding, which is a form in XML and can be applied in mathematical markup language. Only examples are shown in the above table, and the first target symbol can be set according to the actual situation, and the present disclosure does not limit it.
[0109] The second target symbol may be a continuous non-splittable symbol. For example, a semicolon, a square root, etc. In a possible implementation manner, when splitting the nodes in the target file into multiple mathematical markup language segments based on a preset line break rule, it may be based on the preset line break rule to split the first-level nodes in the target file into multiple mathematical markup language segments.
[0110] When the formula to be processed contains continuous numbers, in order to make the formula content complete and unambiguous, no line break operation is performed, and a continuous segment of numbers only exists in one mathematical markup language segment. For example, if the formula to be processed contains numbers such as "1220", then in order to avoid ambiguity, no line break operation is performed. At the same time, since "1220" is continuous numbers, then the segment of numbers "1220" is located in the same mathematical markup language segment. Then when rendering, the number "1220" is displayed on the same line.
[0111] In a possible implementation manner, when splitting the nodes in the target file into multiple mathematical markup language segments, the nodes in the target file can be traversed according to the display order of the operators or operation parameters corresponding to the nodes in the formula to be processed. For the Nth node in the target file, it is judged whether the operator or operation parameter represented by the node satisfies the line break rule.
[0112] If it does not meet the requirement, the Nth node is cached in the array;
[0113] If it meets the requirement, the Nth node and the previously stored nodes in the array are spliced into a mathematical markup language segment, the spliced mathematical markup language segment is stored, and the array is cleared; where N is an integer.
[0114] Specifically, the array is used to cache and splice the nodes belonging to the same mathematical markup language segment. In a possible implementation manner, the step of traversing the nodes in the target file can be carried out simultaneously with the step of splicing nodes in the array. For each detected node, the node is put into the array until the node is spliced into a complete mathematical markup language segment, and then the array is cleared.
[0115] For the Nth node in the target file, after determining whether the operator or operation parameter represented by the node satisfies the line break rule, if it satisfies, splice the Nth node and the previously stored nodes in the array into a mathematical markup language segment. After splicing the mathematical markup language segment, clear this array. Continue to sequentially retrieve the subsequent nodes, store them in the array in sequence, and repeat the above operations until all nodes in the target file are traversed. After splitting the target file into several mathematical markup language segments, stop the operation.
[0116] Exemplarily, as Figure 4 shown, in the figure, "1 + 1 + 1 + 1 + 1 + 1 = 6" is the formula to be line broken. When sequentially retrieving the nodes therein, put "1" and "+" into the array in the order shown in the formula to be processed. Since "+" meets the preset line break rule, after caching "1" and "+" in an array, splice "1" and "+" into "1+". At this time, "1+" is a mathematical markup language segment. After splicing "1+", clear this array. Continue to sequentially retrieve the subsequent nodes until all nodes in the target file are traversed. After splitting "1 + 1 + 1 + 1 + 1 + 1 = 6" into "1+", "1+", "1+", "1+", "1+", "1=", "6" in sequence, stop the operation.
[0117] In another possible implementation, for the Nth node in the target file, after determining whether the operator or operation parameter represented by the node satisfies the line break rule, then perform the following operations:
[0118] If it does not satisfy, cache the Nth node in the array; if it satisfies, splice the previously stored nodes in the array into a mathematical markup language segment, store the spliced mathematical markup language segment, clear the array, and cache the Nth node in the cleared array.
[0119] For the Nth node in the target file, after determining whether the operator or operation parameter represented by the node satisfies the line break rule, if it satisfies, splice the Nth node and the subsequently stored nodes in the array into a mathematical markup language segment. After splicing the mathematical markup language segment, clear this array. Continue to sequentially retrieve the subsequent nodes, store them in the array in sequence, and repeat the above operations until all nodes in the target file are traversed. After splitting the target file into several mathematical markup language segments, stop the operation.
[0120] Exemplarily, as Figure 5As shown, the formula "1+1+1+1+1+1=6" in the figure is the formula to be line-wrapped. When sequentially retrieving the nodes therein, the "+" and "1" are sequentially placed into an array in the display order of the formula to be processed. Since the "+" conforms to the preset line-wrapping rule, after caching the "+" and "1" in an array, the "+" and "1" are concatenated into "+1", and at this time, "+1" is a MathML fragment. After concatenating "+1", this array is cleared. Continue to sequentially retrieve the subsequent nodes until all nodes in the target file are traversed. After splitting "1+1+1+1+1+1=6" into "1", "+1", "+1", "+1", "+1", "+1", "=6" in sequence, the operation stops.
[0121] Regarding step 203,
[0122] After performing the line-wrapping operation on the target file described in MathML, the target file described in MathML can be read by a browser. However, since the target file described in MathML cannot be directly displayed in a browser, it needs to be rendered into a file that can be displayed by the browser.
[0123] In a possible implementation, when rendering based on the multiple MathML fragments, all the split MathML fragments can be rendered as image files, and the image files corresponding to the multiple MathML fragments are displayed in the described display order.
[0124] The image file can be a Scalable Vector Graphics (SVG) file. Among them, the SVG file is a vector image language developed based on XML and can be inserted into a browser for viewing at any time. In a possible implementation, the MathML fragment can be converted into an SVG file through the MathJax tool.
[0125] When rendering based on the multiple MathML fragments, in addition to the formula to be processed, there are often other characters that also need to be rendered. Therefore, in a possible implementation, rendering can be performed based on the multiple MathML fragments and other characters in the text file except the target text to display the formula to be processed and the other characters.
[0126] Specifically, when rendering a MathML fragment, each MathML fragment needs to be rendered as a separate SVG fragment. Exemplarily, such as Figure 4When rendering the formula to be processed, the part of the text "1+1+1+1+1+1=6" needs to be rendered as an SVG file. Specifically, the mathematical markup language fragments in "1+1+1+1+1+1=6", namely "1", "+1", "+1", "+1", "+1", "+1", "=6", need to be rendered as separate SVG files respectively, and the remaining characters are rendered using the rendering tools preset by the browser so that the complete text file can be displayed in the browser for users to read.
[0127] When the article layout is adaptively adjusted for different online browsing modes, if the width of the remaining characters at the end of the text line ≤ the character width of the operator or operation parameter represented by the SVG file at the end of the line, then the last SVG file cannot continue to be displayed on this line segment and needs to be adaptively transferred to the next line to complete the adaptive line break operation.
[0128] Therefore, based on the method provided by the present disclosure, the formula to be processed can be split into multiple mathematical markup language fragments. The parts of the formula to be processed represented by different mathematical markup language fragments are parts that can be line-wrapped, but not necessarily line-wrapped. Whether to perform line wrapping in actual applications can be adaptively adjusted according to the display requirements.
[0129] Those skilled in the art can understand that in the above method of the specific implementation manner, the writing order of each step does not mean a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined according to its function and possible internal logic.
[0130] Based on the same inventive concept, the present disclosure embodiments also provide a formula line break device corresponding to the formula line break method. Since the principle of solving problems by the device in the present disclosure embodiments is similar to the above formula line break method of the present disclosure embodiments, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be elaborated.
[0131] Refer to Figure 6 As shown, it is a schematic architecture diagram of a formula line break device provided by the present disclosure embodiments. The device includes: an acquisition module 601, a splitting module 602, and a display module 603; wherein,
[0132] The acquisition module 601 is used to acquire a target file described based on mathematical markup language corresponding to the formula to be processed;
[0133] The splitting module 602 is used to split the nodes in the target file into multiple mathematical markup language fragments based on a preset line break rule; wherein, the nodes are used to represent the operators or operation parameters in the formula to be processed, and the nodes in the same mathematical markup language fragment are on the same line, and the nodes in different mathematical markup language fragments can be on different lines;
[0134] A display module 603, configured to render based on the multiple MathML fragments to display the formula to be processed.
[0135] In a possible implementation, when obtaining a target file corresponding to the formula to be processed and described in MathML, the obtaining module 601 is configured to:
[0136] Obtain a text file containing the formula to be processed and other characters, represented in a first format;
[0137] Obtain target text corresponding to the formula to be processed from the text file;
[0138] Convert the target text from the first format to the MathML format to obtain the target file;
[0139] When rendering based on the multiple MathML fragments, the display module 603 is configured to:
[0140] Render based on the multiple MathML fragments and render based on other characters in the text file except the target text to display the formula to be processed and the other characters.
[0141] In a possible implementation, the target file includes first-level nodes not nested under other nodes and second-level nodes nested under other nodes;
[0142] When splitting the nodes in the target file into multiple MathML fragments based on a preset line break rule, the splitting module 602 is configured to:
[0143] Split the first-level nodes in the target file into multiple MathML fragments based on the preset line break rule.
[0144] In a possible implementation, the nodes in the target file are arranged in the display order of the operators or operation parameters corresponding to the nodes in the formula to be processed;
[0145] When splitting the nodes in the target file into multiple MathML fragments based on a preset line break rule, the splitting module 602 is configured to traverse the nodes in the target file in the display order, and for each node, perform the following operations:
[0146] For the Nth node in the target file, determine whether the operator or operation parameter represented by the node satisfies the line break rule;
[0147] If not, cache the Nth node in an array;
[0148] If it is satisfied, the Nth node and the nodes previously stored in the array are spliced into a MathML fragment, the spliced MathML fragment is stored, and the array is cleared; where N is an integer.
[0149] In a possible implementation, the preset line break rule includes:
[0150] Perform a line break at the first target symbol, do not perform a line break at the second target symbol, and do not perform a line break for consecutive digits.
[0151] In a possible implementation, when rendering based on the multiple MathML fragments, the display module 603 is used to:
[0152] Render all the split MathML fragments into image files;
[0153] Display the image files corresponding to the multiple MathML fragments in the display order.
[0154] In a possible implementation, for the Nth node in the target file, after the splitting module 602 determines whether the operator or operation parameter represented by the node satisfies the line break rule, it is further used to:
[0155] If it is not satisfied, cache the Nth node in the array;
[0156] If it is satisfied, splice the nodes previously stored in the array into a MathML fragment, store the spliced MathML fragment, clear the array, and cache the Nth node in the cleared array.
[0157] The description of the processing flow of each module in the device and the interaction flow between modules can refer to the relevant descriptions in the above method embodiments and will not be elaborated here.
[0158] Based on the same inventive concept, an embodiment of the present disclosure also provides a computer device. Refer to Figure 7 As shown, it is a schematic structural diagram of a computer device 700 provided by an embodiment of the present disclosure, including a processor 701, a memory 702, and a bus 703. Among them, the memory 702 is used to store execution instructions, including an internal memory 7021 and an external memory 7022; here, the internal memory 7021 is also called the main memory, which is used to temporarily store the operation data in the processor 701 and the data exchanged with the external memory 7022 such as a hard disk. The processor 701 exchanges data with the external memory 7022 through the internal memory 7021. When the computer device 700 runs, the processor 701 communicates with the memory 702 through the bus 703, so that the processor 701 executes the following instructions:
[0159] Obtain a target file corresponding to the formula to be processed and described in Mathematical Markup Language;
[0160] Based on a preset line break rule, split the nodes in the target file into multiple Mathematical Markup Language segments; wherein, the nodes are used to represent operators or operation parameters in the formula to be processed, and the nodes in the same Mathematical Markup Language segment are on the same line, and the nodes in different Mathematical Markup Language segments can be on different lines;
[0161] Render based on the multiple Mathematical Markup Language segments to display the formula to be processed.
[0162] In a possible implementation manner, in the instructions executed by the processor 701, the obtaining of the target file corresponding to the formula to be processed and described in Mathematical Markup Language includes:
[0163] Obtain a text file containing the formula to be processed and other characters, and represented in a first format;
[0164] Obtain the target text corresponding to the formula to be processed from the text file;
[0165] Convert the target text from the first format to the Mathematical Markup Language format to obtain the target file;
[0166] The rendering based on the multiple Mathematical Markup Language segments includes:
[0167] Render based on the multiple Mathematical Markup Language segments and render based on other characters in the text file except the target text to display the formula to be processed and the other characters.
[0168] In a possible implementation manner, in the instructions executed by the processor 701, the target file includes first-level nodes not nested under other nodes and second-level nodes nested under other nodes;
[0169] The splitting of the nodes in the target file into multiple Mathematical Markup Language segments based on the preset line break rule includes:
[0170] Based on the preset line break rule, split the first-level nodes in the target file into multiple Mathematical Markup Language segments.
[0171] In a possible implementation manner, in the instructions executed by the processor 701, the nodes in the target file are arranged in the display order of the operators or operation parameters corresponding to the nodes in the formula to be processed;
[0172] Based on a preset line break rule, split the nodes in the target file into multiple MathML fragments, traverse the nodes in the target file in the display order, and for each node, perform the following operations:
[0173] For the Nth node in the target file, determine whether the operator or operation parameter represented by the node satisfies the line break rule;
[0174] If not, cache the Nth node in an array;
[0175] If so, splice the Nth node and the previously stored nodes in the array into a MathML fragment, store the spliced MathML fragment, and clear the array; where N is an integer.
[0176] In a possible implementation, in the instructions executed by the processor 701, the preset line break rule includes:
[0177] Perform a line break at the first target symbol, do not perform a line break at the second target symbol, and do not perform a line break for consecutive numbers.
[0178] In a possible implementation, in the instructions executed by the processor 701, the rendering based on the multiple MathML fragments includes:
[0179] Render all the split MathML fragments into an image file;
[0180] Display the image files corresponding to the multiple MathML fragments in the display order.
[0181] In a possible implementation, in the instructions executed by the processor 701, after determining whether the operator or operation parameter represented by the Nth node in the target file satisfies the line break rule, the method further includes:
[0182] If not, cache the Nth node in an array;
[0183] If so, splice the previously stored nodes in the array into a MathML fragment, store the spliced MathML fragment, clear the array, and cache the Nth node in the cleared array.
[0184] The embodiments of the present disclosure further provide a computer-readable storage medium, on which a computer program is stored, and when the computer program is run by a processor, it executes the steps of the formula line break method described in the above method embodiments. Wherein, the storage medium can be a volatile or non-volatile computer-readable storage medium.
[0185] Embodiments of the present disclosure also provide a computer program product. The computer product carries program codes, and the instructions included in the program codes can be used to execute the steps of the method for line wrapping of formulas in the above method embodiments. For details, reference can be made to the above method embodiments and will not be elaborated herein.
[0186] Among them, the above computer program product can be specifically implemented in the form of hardware, software, or a combination thereof. In an alternative embodiment, the computer program product is specifically embodied as a computer storage medium. In another alternative embodiment, the computer program product is specifically embodied as a software product, such as a Software Development Kit (SDK), etc.
[0187] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems and devices described above can refer to the corresponding processes in the foregoing method embodiments and will not be elaborated herein. In several embodiments provided by the present disclosure, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division, and there may be other division methods in actual implementation. For another example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some communication interfaces. The indirect couplings or communication connections of the devices or units can be in electrical, mechanical, or other forms.
[0188] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0189] In addition, in each embodiment of the present disclosure, the functional units can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit.
[0190] When the above-mentioned functions are implemented in the form of software function units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such an understanding, the technical solution of the present disclosure, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present disclosure. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM), random access memories (RAM), magnetic disks, or optical discs that can store program codes.
[0191] Finally, it should be noted that the above-described embodiments are only specific implementation manners of the present disclosure, used to illustrate the technical solutions of the present disclosure, rather than limiting them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: any person skilled in the art within the technical scope disclosed by the present disclosure can still modify the technical solutions recorded in the foregoing embodiments or easily conceive of changes, or perform equivalent replacements on some of the technical features; and these modifications, changes, or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should all be covered by the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to the protection scope of the claims.
Claims
1. A method for line breaking of formulas, characterized in that, Including: Obtain a target file described in Mathematical Markup Language corresponding to the formula to be processed; Based on a preset line break rule, split the nodes in the target file into multiple Mathematical Markup Language segments; wherein, the nodes are used to represent operators or operation parameters in the formula to be processed, nodes in the same Mathematical Markup Language segment are on the same line, and nodes in different Mathematical Markup Language segments can be on different lines, wherein, the nodes in the target file are arranged in the display order of the operators or operation parameters corresponding to the nodes in the formula to be processed; Based on the preset line break rule, split the nodes in the target file into multiple Mathematical Markup Language segments, traverse the nodes in the target file in the display order, and for each node, perform the following operations: For the Nth node in the target file, determine whether the operator or operation parameter represented by the node satisfies the line break rule; If not, cache the Nth node into an array; If satisfied, splice the Nth node and the nodes previously stored in the array into a Mathematical Markup Language segment, store the spliced Mathematical Markup Language segment, and clear the array; wherein, N is an integer; Render based on the multiple Mathematical Markup Language segments to display the formula to be processed.
2. The method according to claim 1, wherein The obtaining of the target file described in Mathematical Markup Language corresponding to the formula to be processed includes: Obtain a text file containing the formula to be processed and other characters, represented in a first format; Obtain the target text corresponding to the formula to be processed from the text file; Convert the target text from the first format to the Mathematical Markup Language format to obtain the target file; The rendering based on the multiple Mathematical Markup Language segments includes: Render based on the multiple Mathematical Markup Language segments and render based on other characters in the text file except the target text to display the formula to be processed and the other characters.
3. The method according to claim 1, characterized in that, The target file includes first-level nodes not nested under other nodes and second-level nodes nested under other nodes; The splitting of the nodes in the target file into multiple Mathematical Markup Language segments based on the preset line break rule includes: Based on the preset line break rule, split the first-level nodes in the target file into multiple Mathematical Markup Language segments.
4. The method according to claim 1, wherein The preset line break rule includes: Line break at the first target symbol, do not line break at the second target symbol, and consecutive numbers do not line break.
5. The method according to claim 1, wherein The rendering based on the multiple Mathematical Markup Language segments includes: Render all the split Mathematical Markup Language segments into image files; Display the image files corresponding to the multiple Mathematical Markup Language segments in the display order.
6. The method according to claim 1, characterized in that, After determining whether the operator or operation parameter represented by the Nth node in the target file satisfies the line break rule, the method further includes: If not, cache the Nth node into an array; If the condition is satisfied, splice the previously stored nodes in the array into a MathML fragment, store the spliced MathML fragment, clear the array, and cache the Nth node into the cleared array.
7. An apparatus for line break of a formula, characterized in that It includes: An acquisition module for acquiring a target file described in MathML corresponding to a formula to be processed; A splitting module for splitting the nodes in the target file into multiple MathML fragments based on a preset line break rule; wherein, the nodes are used to represent operators or operation parameters in the formula to be processed, the nodes in the same MathML fragment are on the same line, and the nodes in different MathML fragments can be on different lines. Wherein, the nodes in the target file are arranged in the display order of the operators or operation parameters corresponding to the nodes in the formula to be processed. Based on the preset line break rule, split the nodes in the target file into multiple MathML fragments, traverse the nodes in the target file in the display order, and for each node, perform the following operations: For the Nth node in the target file, determine whether the operator or operation parameter represented by the node satisfies the line break rule; If not, cache the Nth node into the array; If the condition is satisfied, splice the Nth node and the previously stored nodes in the array into a MathML fragment, store the spliced MathML fragment, and clear the array; where N is an integer. A display module for rendering based on the multiple MathML fragments to display the formula to be processed.
8. A computer device, characterized in that, It includes: A processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the computer device runs, the processor communicates with the memory through the bus. When the machine-readable instructions are executed by the processor, the steps of the formula line break method according to any one of claims 1 to 6 are executed.
9. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium. When the computer program is run by the processor, the steps of the formula line break method according to any one of claims 1 to 6 are executed.
Citation Information
Patent Citations
Mathematical formula retrieval method and apparatus
CN106372073A
Method and device for type setting processing
CN106815186A