An ai test question generation method and system based on real-time latex conversion

By using a regular expression engine and dynamic processing flow, LaTeX formula code is converted into native formula objects in Word documents, solving the problems of low efficiency, non-editability, and inconsistent formatting in existing technologies. This achieves efficient and accurate formula conversion and editability, promoting the application of AI-powered test question generation systems.

CN121580993BActive Publication Date: 2026-05-29GUIZHOU EDUCATION UNIV

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
GUIZHOU EDUCATION UNIV
Filing Date
2026-01-28
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Existing technologies suffer from problems such as low efficiency in formula conversion, lack of editability, inconsistent formatting, and high error rate when generating test questions containing mathematical and physical formulas. In particular, during the detection and conversion of LaTeX formula code, nesting and inclusion relationships often lead to incorrect segmentation or inability to recognize the formula structure.

Method used

A dynamic processing flow based on a regular expression engine is adopted to detect LaTeX formula code and convert it into native formula objects in Word documents. Through ordered regular expression matching strategies and direct replacement technology of document objects, an automated process from test requirements to editable documents is achieved, ensuring the accuracy and completeness of formula conversion.

Benefits of technology

It improves the efficiency and accuracy of formula conversion, ensures the editability and format consistency of formulas, promotes the application of artificial intelligence technology in the field of education, and realizes seamless integration and native editing of formulas.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121580993B_ABST
    Figure CN121580993B_ABST
Patent Text Reader

Abstract

The present application belongs to the technical field of education and artificial intelligence, and relates to an AI test question generation method and system based on real-time LaTeX conversion, comprising: obtaining test question structured data from a preset large language model according to a test question generation instruction input by a user; analyzing the test question structured data to obtain a test question text; detecting whether the test question text contains LaTeX formula code based on a regular expression engine; executing a dynamic processing procedure according to the detection result of the LaTeX formula code; if it is detected that there is LaTeX formula code, performing document conversion processing and obtaining a Word document of an editable formula and a corresponding storage path; generating a state flag bit according to the detection result of the LaTeX formula code and assembling corresponding return content; executing display processing operations on the return content according to the state flag bit and presenting a test question generation result. The present application improves the efficiency and accuracy of formula conversion, realizes native editing of formulas and promotes the landing application of artificial intelligence technology in the education field.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of interdisciplinary technology of education and artificial intelligence, and in particular to an AI test question generation method and system based on real-time LaTeX conversion. Background Technology

[0002] With the widespread application of Large Language Models (LLMs) in education, automatically generating STEM exam questions using Artificial Intelligence (AI) has become an important means of improving teaching efficiency. Existing AI-generated exam questions typically return the content in the form of code typed using LaTeX when generating questions containing mathematical and physical formulas.

[0003] However, existing solutions for processing LaTeX formula code have significant drawbacks. First, manual formula conversion is inefficient, requiring substantial manpower and time. Second, formulas rendered as images suffer from issues such as being uneditable and having inconsistent styles, affecting subsequent modifications and usability. Third, existing formula conversion tools often employ indirect conversion methods, requiring multiple format conversions, resulting in lengthy processing paths and poor support for complex formula structures. Furthermore, in the LaTeX formula code detection stage, due to the nesting and inclusion relationships between different formula delimiters, traditional regular expression matching methods can lead to incorrect formula segmentation or failure to recognize the formula structure if the matching order is not set properly, ultimately directly impacting the completeness and accuracy of formula extraction. Summary of the Invention

[0004] Based on the above analysis, the embodiments of the present invention aim to provide an AI test question generation method and system based on real-time LaTeX conversion, in order to solve the problems of low efficiency of formula conversion, uneditable formulas and inconsistent formats, and high error rate of formula conversion in the prior art.

[0005] On one hand, embodiments of the present invention provide an AI test question generation method based on real-time LaTeX conversion, comprising: obtaining structured test question data from a preset large language model according to a test question generation instruction input by a user; parsing the structured test question data to obtain test question text; detecting whether the test question text contains LaTeX formula code based on a regular expression engine; and executing a dynamic processing flow according to the detection result of the LaTeX formula code; wherein the dynamic processing flow includes: if LaTeX formula code is detected in the test question text, performing document conversion processing on the test question text to obtain an editable formula Word document and its corresponding storage path; otherwise, directly outputting test question text containing only plain text content; generating a status flag bit according to the detection result of the LaTeX formula code, and assembling corresponding return content according to the status flag bit and the execution result of the dynamic processing flow; performing display processing operation on the return content according to the status flag bit, and presenting the test question generation result.

[0006] Furthermore, the test question text includes a question stem text and an answer text; the step of obtaining structured test question data from a preset large language model based on the user-input test question generation instruction and parsing the structured test question data to obtain the test question text includes: constructing an AI call request based on the test question parameters and question requirements in the test question generation instruction, and obtaining structured test question data from the preset large language model based on the AI ​​call request; wherein, the structured test question data includes at least the question stem data and the answer data; parsing the question stem data and the answer data to obtain the question stem text and the answer text in the test question text respectively.

[0007] Further, the step of detecting LaTeX formula code in the test question text, and then performing document conversion processing on the test question text to obtain an editable formula Word document and its corresponding storage path, includes: when LaTeX formula code is detected in the question stem text or the answer text, inserting the corresponding text containing the LaTeX formula code into a newly created Word document; matching the text content of the newly created Word document based on a predefined list of regular expression patterns, replacing each matched LaTeX formula code with a temporary placeholder, and simultaneously replacing each replaced LaTeX formula with a temporary placeholder. The code is saved to a preset list; the newly created Word document is traversed and each temporary placeholder is located; the formula conversion engine is called to convert the LaTeX formula code in the preset list into Word native formula objects; each Word native formula object is inserted into the position of the corresponding temporary placeholder, completing the replacement of each temporary placeholder, and obtaining the editable formula Word document and its corresponding storage path; wherein, the storage path includes at least one of the following: the storage path of the question stem Word document corresponding to the question stem Word document after document conversion processing, and the storage path of the answer document corresponding to the answer Word document after document conversion processing.

[0008] Furthermore, the regular expression pattern list is matched sequentially in the following order: First delimiter pattern: matched by regular expression Matching the test question text Inline formulas in the form of regular expressions; second delimiter pattern: via regular expressions Matching the test question text Inline formulas in the form of regular expressions; third delimiter pattern: via regular expressions Matching the test question text Inline formulas in the form of regular expressions; fourth delimiter pattern: via regular expressions Matching the test question text Inline formulas in the form of regular expressions; fifth delimiter pattern: via regular expressions Matching the test question text The LaTeX formula environment with defined format.

[0009] Furthermore, the step of converting the LaTeX formula code in the preset list into a Word native formula object includes: converting the LaTeX formula code in the preset list into an Office Math formula object in Office Open XML format.

[0010] Further, the step of generating a status flag based on the detection result of LaTeX formula code, and assembling the corresponding return content based on the status flag and the execution result of the dynamic processing flow, includes: if both the question text and the answer text detect LaTeX formula code, then the status flag is set to a first value, and the storage path of the question document and the storage path of the answer document are used as the return content; if only the question text detects LaTeX formula code, then the status flag is set to a second value, and the storage path of the question document and the answer text containing only plain text content are used as the return content; if only the answer text detects LaTeX formula code, then the status flag is set to a third value, and the storage path of the answer document and the question text containing only plain text content are used as the return content; if neither the question text nor the answer text detects LaTeX formula code, then the status flag is set to a fourth value, and the question text containing only plain text content and the answer text containing only plain text content are used as the return content.

[0011] Furthermore, the step of performing display processing operation on the returned content according to the status flag includes: if the status flag indicates that the returned content is all plain text content, then directly fill the plain text content into the preset display area of ​​the front end; if the status flag indicates that the returned content contains the storage path, then load the Word document of the editable formula corresponding to the storage path, and render and display it through the online Word editor control integrated in the front end.

[0012] On the other hand, embodiments of the present invention provide an AI test question generation system based on real-time LaTeX conversion, comprising: a test question generation module, used to obtain structured test question data from a preset large language model according to a test question generation instruction input by a user; and to parse the structured test question data to obtain test question text; a formula detection module, used to detect whether the test question text contains LaTeX formula code based on a regular expression engine; a dynamic conversion module, used to execute a dynamic processing flow according to the detection result of the LaTeX formula code; wherein, the dynamic processing flow includes: if LaTeX formula code is detected in the test question text, then performing document conversion processing on the test question text to obtain a Word document with editable formulas and the corresponding storage path; otherwise, directly outputting test question text containing only plain text content; a dynamic assembly module, used to generate a status flag bit according to the detection result of the LaTeX formula code, and assemble the corresponding return content according to the status flag bit and the execution result of the dynamic processing flow; and a front-end interaction module, used to perform display processing operations on the return content according to the status flag bit, and present the test question generation result.

[0013] Furthermore, the test question text includes a question stem text and an answer text; the front-end interaction module is also used to receive a test question generation instruction set by the user through the front-end interaction interface; the test question generation module is also used to construct an AI call request based on the test question parameters and question requirements in the test question generation instruction, and to obtain the test question structured data from the preset large language model based on the AI ​​call request; wherein, the test question structured data includes at least the test question stem data and the answer data; the question stem data and the answer data are parsed to obtain the question stem text and the answer text, respectively.

[0014] Furthermore, the dynamic conversion module is also used to perform document conversion processing when LaTeX formula code is detected. The document conversion processing specifically includes: when LaTeX formula code is detected in the question text or the answer text, inserting the corresponding text containing the LaTeX formula code into a newly created Word document; matching the text content of the newly created Word document based on a predefined list of regular expression patterns, replacing each matched LaTeX formula code with a temporary placeholder, and saving the replaced LaTeX formula code to a preset list; traversing the newly created Word document and locating each temporary placeholder; calling the formula conversion engine to convert the LaTeX formula code in the preset list into Word native formula objects; inserting each Word native formula object into the position of the corresponding temporary placeholder, completing the replacement of each temporary placeholder, and obtaining an editable formula Word document and its corresponding storage path; wherein the storage path includes at least one of the following: the storage path of the question text corresponding to the question text Word document after document conversion processing, and the storage path of the answer text corresponding to the answer text Word document after document conversion processing.

[0015] Compared with the prior art, the present invention can achieve at least one of the following beneficial effects:

[0016] First, unlike related technologies which suffer from low efficiency and high error rates in formula conversion, this invention deeply integrates LaTeX formula code conversion functionality into the AI ​​test question generation process. This creates a complete automated process from inputting test question requirements to outputting editable documents. Through an automated LaTeX formula code detection and conversion mechanism, the efficiency of formula conversion is improved. By employing an ordered regular expression matching strategy and direct document object replacement technology, structural misalignment and information loss during formula extraction are effectively avoided, ensuring the accuracy and completeness of formula conversion. This also effectively avoids mismatches of nested delimiters, ensuring high accuracy in recognizing complex LaTeX formula code structures.

[0017] Secondly, unlike the problems of uneditable formulas and inconsistent formatting, this invention can convert the detected and extracted LaTeX formula code into native formula objects in Word documents. Its conversion path is completely different from that of traditional formula objects embedded in Word documents. It can achieve seamless integration and native editing of formulas without relying on other external plugins or software, ensuring the uniformity and editability of formula format. The formula conversion path is short and highly compatible, which not only facilitates user editing and modification, but also presents the formulas in a standard mathematical formula visual form, improving the user experience and ensuring the stability and reliability of the system under different inputs, thus promoting the application of artificial intelligence technology in the field of education.

[0018] In this invention, the above-described technical solutions can be combined with each other to achieve more preferred combinations. Other features and advantages of this invention will be set forth in the following description, and some advantages may become apparent from the description or be learned by practicing the invention. The objects and other advantages of this invention can be realized and obtained from what is particularly pointed out in the description and drawings. Attached Figure Description

[0019] The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. Throughout the drawings, the same reference numerals denote the same parts.

[0020] Figure 1 This is a flowchart of an AI test question generation method based on real-time LaTeX conversion, according to an embodiment of the present invention.

[0021] Figure 2 This is a schematic diagram of the main modules of the AI ​​test question generation system based on real-time LaTeX conversion according to an embodiment of the present invention. Detailed Implementation

[0022] Preferred embodiments of the present invention will now be described in detail with reference to the accompanying drawings, which form part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not intended to limit the scope of the present invention.

[0023] A specific embodiment of the present invention discloses an AI-based test question generation method based on real-time LaTeX conversion, such as... Figure 1 As shown, the steps S1 to S5 are as follows:

[0024] Step S1: Based on the question generation instruction input by the user, obtain the structured data of the questions from the preset large language model; parse the structured data of the questions to obtain the question text.

[0025] The question generation instruction includes question parameters and question requirements; the question text includes question stem text and answer text. In practice, the specific steps include: constructing an AI call request based on the question parameters and question requirements in the question generation instruction, and obtaining structured question data from the preset large language model based on the AI ​​call request; wherein the structured question data includes at least question stem data and answer data; parsing the question stem data and the answer data to obtain the question stem text and answer text, respectively.

[0026] In this embodiment of the invention, the AI ​​test question refers to an assessment question automatically generated using Artificial Intelligence (AI) technology. Specifically, it is a test question text containing a complete question stem and corresponding answer, generated by a large language model based on a user-inputted command that includes test question parameters and requirements. For example, a user can receive the test question parameters and requirements set by the user through a front-end interactive interface. The test question parameters are a set of metadata defining the basic attributes of a test question, including subject, chapter, question type, difficulty, number of blanks, etc., while the requirements may include specific knowledge points and question style. Then, the back-end server constructs structured prompts based on the test question parameters and requirements, instructs the large language model to return structured data containing the test question stem and answer in a predetermined JSON (a lightweight data exchange format), and sends an AI call request to the large language model's application programming interface. The AI ​​call request is a data request assembled according to a preset structured format. Finally, the server receives and parses the JSON format response returned by the large language model to obtain the test question stem and answer text. For example, the structure of the JSON format returned data is as follows: .

[0027] The test question text may include LaTeX formula code and plain text, or it may only contain plain text. Since automatically generated test question text usually includes LaTeX formula code, the purpose of this invention is to automatically generate test question text based on user-input test question generation instructions, and simultaneously automatically identify the LaTeX formula code in the question stem and answer text, converting it into an editable and displayable mathematical formula form. LaTeX formula code is a markup language code segment used by the TeX-based typesetting system. It is used to describe and generate scientific and technological document elements such as mathematical formulas, chemical equations, and special symbols. Its characteristic is that it declares the formula structure and content through specific escape characters and delimiters.

[0028] Furthermore, the pre-built large language model in this invention is an artificial intelligence model pre-constructed based on deep learning technology, capable of generating test questions that meet the requirements based on received structured requests. This large language model can be trained using existing technologies, and historical data containing a large number of math and physics test questions, solution processes, and related subject knowledge can be used as the model's training dataset. The specific model training and construction process can be implemented with reference to existing technologies, and will not be elaborated here.

[0029] Step S2: Based on the regular expression engine, detect whether the test question text contains LaTeX formula code.

[0030] During implementation, a regular expression engine can be invoked to perform parallel checks on the question stem and answer text to determine whether they contain LaTeX formula code. For example, detection can be achieved by calling a dedicated detection function (such as the `contains` function), which has a built-in regular expression engine and pattern list; or the regular expression engine can be configured to match various LaTeX delimiter patterns, including inline formulas, inline formulas, and various defined LaTeX environments.

[0031] As we can understand, a regular expression engine is a software component used to process strings. It searches, matches, and replaces fragments in text that conform to specific grammatical rules by interpreting and executing predefined pattern rules. An inline formula is a mathematical formula embedded in a line of text, meaning the formula and text are displayed on the same line. An inline formula is a mathematical formula that occupies a separate line, meaning the formula is separated from the other text. Various LaTeX environments can be used to define formula formats and behaviors. For example, the `equation` environment is used to create numbered single-line formulas, and the `align` environment is used to create multi-line aligned formulas. Both the `equation` and `align` environments are mathematical environments in the LaTeX system.

[0032] It should be noted that the LaTeX formula code detection process here, as well as the LaTeX formula code matching process in the subsequent document conversion process, both achieve the identification and matching of LaTeX formula code by calling the regular expression engine and its delimiter pattern list. The specific form of the pattern list will be explained in subsequent steps.

[0033] Step S3: Based on the detection results of the LaTeX formula code, execute the dynamic processing flow; wherein, the dynamic processing flow includes: if LaTeX formula code is detected in the test question text, perform document conversion processing on the test question text and obtain an editable Word document with the formula and the corresponding storage path; otherwise, directly output the test question text containing only plain text content.

[0034] During implementation, in the dynamic processing flow of the test question text, plain text content that does not contain any LaTeX formula code can be directly output without document conversion processing. That is, the execution result of the dynamic processing flow is the test question text, which will not be elaborated here. When LaTeX formula code is detected in the test question text, document conversion processing of the test question text is initiated.

[0035] The document conversion process specifically includes: First, creating a new Word document and inserting the test question text into the corresponding paragraphs; then, initiating the formula conversion process, iterating through the document content based on regular expressions, matching all LaTeX formula codes and replacing them with temporary placeholders of a uniform format; iterating through all temporary placeholders in the document, converting the LaTeX code corresponding to each placeholder into a native Word formula object using the formula conversion engine, and inserting these native formula objects into the document sequentially to replace the corresponding placeholders; finally, saving the complete Word document containing editable formulas to a preset storage path, and providing this storage path as the return content to the front end for calling.

[0036] Preferably, the document conversion process includes: when LaTeX formula code is detected in the question text or the answer text, inserting the corresponding text containing the LaTeX formula code into a newly created Word document; matching the text content of the newly created Word document based on a predefined list of regular expression patterns; and replacing each matched LaTeX formula code with a temporary placeholder, for example, replacing each matched LaTeX formula code with a unique temporary placeholder string. Simultaneously, the original LaTeX formula codes to be replaced are saved to a preset list. After completing one round of delimiter pattern matching and replacement, the newly created Word document is traversed and each temporary placeholder is located. The formula conversion engine is called to convert the LaTeX formula codes in the preset list into Word native formula objects. Preferably, the formula conversion engine is implemented through an existing class library that can directly convert the LaTeX formula codes taken from the preset list into Office Math formula objects in Office Open XML format. Then, each Word native formula object is inserted into the position of the corresponding temporary placeholder, completing the deletion and replacement of each temporary placeholder. After the conversion is completed, additional text cleaning operations are also required, such as removing the document's Markdown tags, etc., finally obtaining an editable formula Word document and its corresponding storage path. That is, the editable formula Word document is saved to the server's temporary directory, and a unique filename corresponding to the document is generated. The storage path includes at least one of the following: the storage path of the question stem Word document corresponding to the question stem document after document conversion, and the storage path of the answer document corresponding to the answer Word document after document conversion.

[0037] It is understood that, in this embodiment of the invention, a placeholder refers to a unique identifier temporarily used during text processing to mark that a specific piece of content will be replaced; a Word document refers to an electronic document created and edited by relevant document editing software and following a specific structured format. An editable formula refers to a formula object that can be directly clicked, modified, and formatted by the user in document editing software, and whose mathematical structure remains complete. Its essence is the OfficeMath element in the Office Open XML format, distinguishing it from formulas that are images or OLE (Object Linking and Embedding) embedded objects. Office Open XML (OOXML) format is a standardized electronic document format based on XML; a ".docx" file is a ZIP archive using this format. An Office Math object refers to a standardized XML object model in the OOXML format used to represent mathematical formulas. A series of child elements enclosed by an element.

[0038] It is important to note that when both the question text and the answer text contain LaTeX formula code, separate Word documents need to be created. For example, insert the question text into the question text Word document and the answer text into the answer text Word document. Then, based on a predefined list of regular expression patterns, match and transform the question text in the question text Word document and the answer text in the answer text Word document, respectively, and finally obtain two editable formula Word documents and their corresponding storage paths.

[0039] Furthermore, when performing formula matching on the text content of the newly created Word document, it is achieved through a regular expression pattern list configured in the regular expression engine. This regular expression pattern list contains various delimiter patterns. A delimiter pattern refers to a character or character sequence used in text to mark the beginning and end of specific content; in regular expressions, it refers to the pattern rules used to match these delimiters and the content they enclose. In this embodiment of the invention, the regular expression pattern list adopts a multi-pattern sequential matching strategy based on delimiter priority, following the core principle of "from long to short, from outside to inside," that is, prioritizing the matching of patterns with longer delimiters, and then matching nested patterns with shorter delimiters. This design can solve the misidentification problem caused by nested delimiters in LaTeX, for example, to prevent inline formula delimiters from being misidentified. Inline formula delimiters If the internal match is incorrectly prioritized, then the match in the text must be performed first. The inline formulas in this form ensure the completeness and accuracy of the formula extraction.

[0040] Preferably, the matching order of the regular expression pattern list is fixed, and the matching is performed sequentially in the following order:

[0041] First delimiter pattern: via regular expression Matching the test question text Inline formulas in the form of;

[0042] Second delimiter pattern: via regular expression Matching the test question text Inline formulas in the form of;

[0043] Third delimiter pattern: via regular expression Matching the test question text Inline formulas in the form of;

[0044] Fourth delimiter pattern: via regular expression Matching the test question text Inline formulas in the form of;

[0045] Fifth delimiter pattern: via regular expressions Matching the test question text The LaTeX formula environment with defined format.

[0046] For example, the problem text containing LaTeX formula code is as follows: Given a plane Pass A point, its normal vector Then the plane The equation is:

[0047] ;

[0048] Therefore, the first delimiter pattern can be used to match the inline formula “A(x - x_0) + B(y - y_0) + C(z - z_0) = 0” first; then the second delimiter pattern can be used to match the inline formulas “\pi”, “M(x_0,y_0,z_0)”, “\boldsymbol{n} = \{A,B,C\}”, etc.

[0049] For example, the answer text containing LaTeX formula code is: Considering the function The derivative is calculated as follows:

[0050] ;

[0051] Therefore, the inline formula matched by the third delimiter pattern is " The inline formula matched by the fourth delimiter pattern is " ".

[0052] To illustrate the matching order of the delimiter patterns of the present invention, a specific embodiment is provided below.

[0053] Suppose the question text returned by the large language model is as follows:

[0054] Given three points A(1, 2, -1), B(2, 3, 1), and C(-1, 0, 2) in three-dimensional space, use the determinant form of the three-point equation to find the equation of the plane passing through these three points.

[0055] The determinant form of the three-point equation of a plane is: for three non-collinear points on a plane... , , and any point on the plane The equation of the plane is:

[0056]

[0057] After testing, it was found that the question text contained LaTeX formula code. A new Word document was created, the question text was inserted into the document as a new paragraph, and a loop was used to perform document conversion.

[0058] First, execute the first loop, which performs regular expression matching on each of the following patterns in turn, based on the list of regular expression patterns.

[0059] In the first iteration of the first loop, the expression is executed according to the first delimiter pattern. match The inline formula in the form of a regular expression failed to match; no matching LaTeX formula code was found.

[0060] In the second iteration of the first loop, the expression is executed according to the second delimiter pattern. match The inline formula in the form of regular expression failed to match; no matching LaTeX formula code was found.

[0061] In the third iteration of the first loop, the expression is executed according to the third delimiter pattern. match The inline formula in the form of a regular expression failed to match; no matching LaTeX formula code was found.

[0062] In the fourth iteration of the first loop, the expression is executed according to the fourth delimiter pattern. match The inline formula in the form of [formula name] was successfully matched by regular expressions, and four LaTeX formula code strings were extracted, as follows: , , , .

[0063] In a new Word document, replace all four LaTeX formula codes that match the fourth delimiter pattern with temporary placeholders, such as strings. Then, these four LaTeX formula code strings are stored in a preset list.

[0064] After the placeholders were replaced, the content of this Word document is as follows:

[0065] Given three points A(1, 2, -1), B(2, 3, 1), and C(-1, 0, 2) in three-dimensional space, use the determinant form of the three-point equation to find the equation of the plane passing through these three points.

[0066] The determinant form of the three-point equation of a plane is: for three non-collinear points on a plane... , , and any point on the plane The equation of the plane is:

[0067] .

[0068] Next, execute the second loop, which processes the four matched LaTeX formula codes, converts them into mathematical formulas, and inserts them into a Word document.

[0069] In the first iteration of the second loop, the formula conversion engine is invoked to directly convert the LaTeX formula code in the list into the native Office Math object of the Word document, and the string is searched from beginning to end in the Word document. , to match the first string Replace with the first Office Math object obtained from the conversion. ".

[0070] Execute the second, third, and fourth iterations of the second loop in sequence, and then extract the string from subsequent positions in the Word document. Replace with " " " After four iterations, the text content in the Word document is:

[0071] Given three points A(1, 2, -1), B(2, 3, 1), and C(-1, 0, 2) in three-dimensional space, use the determinant form of the three-point equation to find the equation of the plane passing through these three points.

[0072] The determinant form of the three-point equation of a plane is: for three non-collinear points on a plane... , , and any point on the plane The equation of the plane is:

[0073] .

[0074] Next, continue executing the first loop, that is, based on the list of regular expression patterns, continue to perform regular expression matching for subsequent patterns.

[0075] In the 5th iteration of the first loop, the expression is executed according to the fifth delimiter pattern. match The LaTeX formula environment defined in the format is successfully matched via regular expression. The extracted LaTeX formula code is stored in a preset list, and the LaTeX formula code that matches the fifth delimiter pattern is replaced with... After the placeholders were replaced, the content of this Word document is as follows:

[0076] Given three points A(1, 2, -1), B(2, 3, 1), and C(-1, 0, 2) in three-dimensional space, use the determinant form of the three-point equation to find the equation of the plane passing through these three points.

[0077] The determinant form of the three-point equation of a plane is: for three non-collinear points on a plane... , , and any point on the plane The equation of the plane is:

[0078] .

[0079] Finally, the second loop is executed, calling the formula conversion engine to directly convert the LaTeX formula code into a native Office Math object in the Word document, and then searching for the corresponding string in the Word document. And replace it with an Office Math object.

[0080] After the second loop completes, the text content in the Word document is as follows:

[0081] Given three points A(1, 2, -1), B(2, 3, 1), and C(-1, 0, 2) in three-dimensional space, use the determinant form of the three-point equation to find the equation of the plane passing through these three points.

[0082] The determinant form of the three-point equation of a plane is: for three non-collinear points on a plane... , , and any point on the plane The equation of the plane is:

[0083] .

[0084] Thus, the document conversion of the question text is completed, resulting in an editable Word document of the formula and its corresponding storage path. This ensures high accuracy in recognizing complex LaTeX formula code structures, thereby achieving seamless integration and native editing of the formula.

[0085] Step S4: Generate a status flag bit based on the detection result of the LaTeX formula code, and assemble the corresponding return content based on the status flag bit and the execution result of the dynamic processing flow.

[0086] Specifically, the process includes: if both the question text and the answer text detect LaTeX formula code, then the status flag is set to a first value, for example, flag=4, and the storage paths of the question and answer documents are returned as the content; if only the question text detects LaTeX formula code, then the status flag is set to a second value, for example, flag=2, and the storage paths of the question and answer documents containing only plain text are returned as the content; if only the answer text detects LaTeX formula code, then the status flag is set to a third value, for example, flag=3, and the storage paths of the answer documents containing only plain text are returned as the content; if neither the question text nor the answer text detects LaTeX formula code, then the status flag is set to a fourth value, for example, flag=1, and the question and answer documents containing only plain text are returned as the content.

[0087] Preferably, different response content can be dynamically assembled based on the flag value of the status flag. For example, if the status flag is set to the first value (flag=4), the storage paths of the question stem Word document and the answer Word document are used as the return content; if the status flag is set to the second value (flag=2), the plain text of the answer and the storage path of the question stem Word document are used as the return content; if the status flag is set to the third value (flag=3), the plain text of the question stem and the storage path of the answer Word document are used as the return content; if the status flag is set to the fourth value (flag=1), the plain text of the question stem and the plain text of the answer are used as the return content, thereby enabling collaborative rendering and display of the front end based on different return content.

[0088] Step S5: Perform display processing on the returned content according to the status flag bit, and present the test question generation result.

[0089] Specifically, if the status flag indicates that the returned content is all plain text, then the plain text content is directly filled into the preset display area of ​​the front end; if the status flag indicates that the returned content contains the storage path, then the Word document with editable formulas corresponding to the storage path is loaded and rendered and displayed through the online Word editor control integrated into the front end.

[0090] During implementation, after receiving the response, the front-end parses the status flags and executes the corresponding rendering strategy. Specifically, the composition of the returned content can be determined based on the flag value. For plain text portions in the returned content, it is directly filled into the corresponding display area of ​​the front-end editor; for Word document storage paths in the returned content, the corresponding Word document file containing editable formulas needs to be loaded and rendered in the embedded online Word editor control. The online Word editor includes controls or components embedded in a web browser that provide document viewing and editing functions.

[0091] For example, if the status flag is set to the fourth value, the plain text of the question stem and the plain text of the answer are directly filled into the question stem area and answer area of ​​the front-end editor; if the status flag is set to the second value, the plain text of the answer is filled into the answer area of ​​the front-end editor, and a question stem Word document containing editable formulas is requested to be loaded in the question stem area of ​​the editor; if the status flag is set to the third value, the plain text of the question stem is filled into the question stem area of ​​the editor, and a question stem Word document containing editable formulas is requested to be loaded in the answer area of ​​the editor; if the status flag is set to the first value, the question stem Word document and the answer Word document containing editable formulas are requested to be loaded through the front-end editor, and rendered and displayed in the corresponding areas.

[0092] Meanwhile, the application scenarios of this invention have significant versatility and scalability, not limited to the internal application of the question generation system. It can also be independently packaged and developed into a specialized document format conversion tool. Users can directly copy and paste text content containing LaTeX formula code generated by various artificial intelligence models into the question generation system of this invention to complete batch conversion of LaTeX formula code. Furthermore, the content displayed on the system interface needs to be presented to the user for final confirmation, identification, and necessary modifications. After the user confirms that the content is correct, clicking the submit button on the interface will save the final approved question and answer data to the backend database, thus completing the entire processing flow from original generated content to standardized, reusable question resources.

[0093] It is evident that this adaptive response and collaborative rendering mechanism based on status flags enables seamless mixed display of plain text and documents containing formulas on the same interface. This facilitates user editing and modification while presenting the text in the visual form of standard mathematical formulas, thereby achieving more user-friendly intelligent interaction and improving the user experience.

[0094] It is understood that the above implementation methods are only for ease of understanding and simplification of description, and should not be construed as limitations on the present invention. The present invention does not impose specific limitations on the regular expression pattern list, the detection method of LaTeX formula code, the matching method, etc.

[0095] Therefore, the embodiments of the present invention, on the one hand, construct a complete automated process from inputting test requirements to outputting editable documents. Through an automated LaTeX formula code detection and conversion mechanism, the efficiency of formula conversion is improved. By adopting an ordered regular expression matching strategy and document object direct replacement technology, the accuracy and completeness of formula conversion are guaranteed, effectively avoiding the mismatch problem of nested delimiters, and ensuring high accuracy in recognizing complex LaTeX formula code structures. On the other hand, the detected and extracted LaTeX formula code can be converted into native formula objects in Word documents. Without relying on other external plugins or software, seamless native editing of formulas can be achieved. The formula conversion path is short and highly compatible, which is convenient for users to edit and modify, and can be presented in the visual form of standard mathematical formulas. This ensures the stability and reliability of the system under different inputs and promotes the application of artificial intelligence technology in the field of education.

[0096] In another embodiment of the present invention, an AI-based test question generation system based on real-time LaTeX conversion is proposed, such as... Figure 2 As shown, it specifically includes the following modules:

[0097] The test question generation module is used to obtain structured test question data from a preset large language model based on the test question generation command input by the user; and parse the structured test question data to obtain test question text. The formula detection module is used to detect whether the test question text contains LaTeX formula code based on a regular expression engine. The dynamic conversion module is used to execute a dynamic processing flow based on the detection result of the LaTeX formula code; wherein, the dynamic processing flow includes: if LaTeX formula code is detected in the test question text, the test question text is converted into a document, and an editable formula Word document and its corresponding storage path are obtained; otherwise, the test question text containing only plain text content is directly output. The dynamic assembly module is used to generate a status flag based on the detection result of the LaTeX formula code, and assemble the corresponding return content based on the status flag and the execution result of the dynamic processing flow. The front-end interaction module is used to perform display processing operations on the return content based on the status flag and present the test question generation result. The front-end interactive module integrates an online Word editor, which can include a question stem area and an answer area, used to render and display plain text or request and load the corresponding Word document content based on the storage path.

[0098] Furthermore, the front-end interaction module is also used to receive a question generation instruction set by the user through the front-end interaction interface; the question generation module is also used to construct an AI call request based on the question parameters and question requirements in the question generation instruction, and to obtain the question structured data from the preset large language model based on the AI ​​call request; wherein, the question structured data includes at least the question stem data and answer data; the question stem data and the answer data are parsed to obtain the question stem text and answer text in the question text, respectively.

[0099] Furthermore, the dynamic conversion module is also used to perform document conversion processing when LaTeX formula code is detected. The document conversion processing specifically includes: when LaTeX formula code is detected in the question text or the answer text, inserting the corresponding text containing the LaTeX formula code into a newly created Word document; matching the text content of the newly created Word document based on a predefined list of regular expression patterns, replacing each matched LaTeX formula code with a temporary placeholder, and saving the replaced LaTeX formula code to a preset list; traversing the newly created Word document and locating each temporary placeholder; calling the formula conversion engine to convert the LaTeX formula code in the preset list into Word native formula objects; inserting each Word native formula object into the position of the corresponding temporary placeholder, completing the replacement of each temporary placeholder, and obtaining an editable formula Word document and its corresponding storage path; wherein the storage path includes at least one of the following: the storage path of the question text corresponding to the question text Word document after document conversion processing, and the storage path of the answer text corresponding to the answer text Word document after document conversion processing.

[0100] The above-described method and system embodiments are based on the same principles, and their related aspects can be referenced from each other to achieve the same technical effects. For specific implementation processes, please refer to the foregoing embodiments, which will not be repeated here.

[0101] Those skilled in the art will understand that all or part of the processes of the methods described in the above embodiments can be implemented by a computer program instructing related hardware, and the program can be stored in a computer-readable storage medium. The computer-readable storage medium may be a disk, optical disk, read-only memory, or random access memory, etc.

[0102] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the scope of protection of the present invention.

Claims

1. An AI-based test question generation method based on real-time LaTeX conversion, characterized in that, include: Based on the user's input of the question generation instructions, the structured data of the questions is obtained from the preset large language model; The structured data of the test questions is parsed to obtain the test question text, which includes the question stem text and the answer text. Based on a regular expression engine, the system detects whether the test question text contains LaTeX formula code. Based on the detection results of LaTeX formula code, a dynamic processing flow is executed. This dynamic processing flow includes: if LaTeX formula code is detected in the question text, the question text undergoes document conversion processing to obtain an editable Word document with corresponding storage paths. Specifically, this includes: when LaTeX formula code is detected in the question stem or answer text, the corresponding text containing the LaTeX formula code is inserted into a newly created Word document; based on a predefined list of regular expression patterns, the text content of the newly created Word document is matched, and each matched LaTeX formula code is replaced with a temporary placeholder, while the replaced LaTeX formula code is saved to a preset list; the newly created Word document is traversed and each temporary placeholder is located; the formula conversion engine is invoked to convert the LaTeX formula code in the preset list into Word native formula objects; each Word native formula object is inserted into the position of the corresponding temporary placeholder, completing the replacement of each temporary placeholder, and obtaining an editable Word document with corresponding storage paths; otherwise, the question text containing only plain text is directly output. The regular expression pattern list is matched sequentially in the following order: First delimiter pattern: via regular expression Matching the test question text Inline formulas in the form of; Second delimiter pattern: via regular expression Matching the test question text Inline formulas in the form of; Third delimiter pattern: via regular expression Matching the test question text Inline formulas in the form of; Fourth delimiter pattern: via regular expression Matching the test question text Inline formulas in the form of; Fifth delimiter pattern: via regular expressions Matching the test question text The format-defined LaTeX formula environment; A status flag is generated based on the detection result of the LaTeX formula code, and the corresponding return content is assembled based on the status flag and the execution result of the dynamic processing flow. The returned content is processed according to the status flag, and the test question generation result is presented.

2. The AI ​​test question generation method based on real-time LaTeX conversion according to claim 1, characterized in that, The process involves generating test questions based on user-inputted instructions, and then obtaining structured test question data from a pre-defined large language model. The structured data of the test questions is parsed to obtain the test question text, including: Based on the question parameters and question requirements in the question generation instruction, an AI call request is constructed, and based on the AI ​​call request, structured question data is obtained from the preset large language model; wherein, the structured question data includes at least the question stem data and answer data; The question stem data and the answer data are parsed to obtain the question stem text and the answer text, respectively.

3. The AI ​​test question generation method based on real-time LaTeX conversion according to claim 2, characterized in that, The storage path includes at least one of the following: the storage path of the question stem Word document corresponding to the question stem document after document conversion, and the storage path of the answer document corresponding to the answer Word document after document conversion.

4. The AI ​​test question generation method based on real-time LaTeX conversion according to claim 3, characterized in that, The step of converting LaTeX formula codes in the preset list into Word native formula objects includes: Convert the LaTeX formula code in the preset list into Office Math formula objects in Office Open XML format.

5. The AI ​​test question generation method based on real-time LaTeX conversion according to claim 4, characterized in that, The step of generating a status flag based on the detection result of the LaTeX formula code, and assembling the corresponding return content based on the status flag and the execution result of the dynamic processing flow, includes: If both the question text and the answer text detect LaTeX formula code, then the status flag is set to the first value, and the storage path of the question document and the storage path of the answer document are returned as the content. If only the question text detects LaTeX formula code, then the status flag is set to the second value, and the question document storage path and the answer text containing only plain text content are returned as the content. If only the answer text detects LaTeX formula code, then the status flag is set to the third value, and the answer document storage path and the question text containing only plain text content are returned as the content. If no LaTeX formula code is detected in either the question text or the answer text, the status flag is set to the fourth value, and the question text containing only plain text and the answer text containing only plain text are returned as the content.

6. The AI ​​test question generation method based on real-time LaTeX conversion according to claim 1, characterized in that, The step of performing display processing operation on the returned content according to the status flag bit includes: If the status flag indicates that the returned content is all plain text, then the plain text content is directly filled into the preset display area of ​​the front end; If the status flag indicates that the returned content contains the storage path, then the Word document containing the editable formulas corresponding to the storage path is loaded and rendered and displayed using the online Word editor control integrated into the front end.

7. An AI-powered test question generation system based on real-time LaTeX conversion, characterized in that, include: The question generation module is used to obtain structured question data from a preset large language model based on the question generation instructions input by the user. The structured data of the test questions is parsed to obtain the test question text, which includes the question stem text and the answer text. The formula detection module is used to detect whether the test question text contains LaTeX formula code based on a regular expression engine; The dynamic conversion module is used to execute a dynamic processing flow based on the detection results of LaTeX formula code. The dynamic processing flow includes: if LaTeX formula code is detected in the question text, the question text is converted into an editable Word document with the corresponding storage path. Specifically, this includes: when LaTeX formula code is detected in the question stem or answer text, the corresponding text containing the LaTeX formula code is inserted into a newly created Word document; based on a predefined list of regular expression patterns, the text content of the newly created Word document is matched, and each matched LaTeX formula code is replaced with a temporary placeholder, while the replaced LaTeX formula code is saved to a preset list; the newly created Word document is traversed and each temporary placeholder is located; the formula conversion engine is called to convert the LaTeX formula code in the preset list into Word native formula objects; each Word native formula object is inserted into the position of the corresponding temporary placeholder, completing the replacement of each temporary placeholder, and obtaining an editable Word document with the corresponding storage path; otherwise, the question text containing only plain text is directly output. The regular expression pattern list is matched sequentially in the following order: First delimiter pattern: via regular expression Matching the test question text Inline formulas in the form of; Second delimiter pattern: via regular expression Matching the test question text Inline formulas in the form of; Third delimiter pattern: via regular expression Matching the test question text Inline formulas in the form of; Fourth delimiter pattern: via regular expression Matching the test question text Inline formulas in the form of; Fifth delimiter pattern: via regular expressions Matching the test question text The format-defined LaTeX formula environment; The dynamic assembly module is used to generate a status flag based on the detection result of the LaTeX formula code, and assemble the corresponding return content based on the status flag and the execution result of the dynamic processing flow. The front-end interaction module is used to perform display processing operations on the returned content according to the status flag and present the test question generation result.

8. The AI ​​test question generation system based on real-time LaTeX conversion according to claim 7, characterized in that, The front-end interaction module is also used to receive user-defined test question generation instructions through the front-end interaction interface; The question generation module is further configured to construct an AI call request based on the question parameters and question requirements in the question generation instruction, and to obtain structured question data from the preset large language model based on the AI ​​call request; wherein the structured question data includes at least the question stem data and answer data; and to parse the question stem data and the answer data to obtain the question stem text and the answer text, respectively.

9. The AI ​​test question generation system based on real-time LaTeX conversion according to claim 8, characterized in that, The storage path includes at least one of the following: the storage path of the question stem Word document corresponding to the question stem document after document conversion, and the storage path of the answer document corresponding to the answer Word document after document conversion.