Automatic typesetting method for double-line entrainment text
Through concise marking grammar and transparent floating body technology, the double-line clip text is automatically calculated and partitioned, which solves the problems of low efficiency and poor adaptability of double-line clip text typesetting in the existing technology, and realizes the adaptive and accurate ancient book typesetting effect.
Patent Information
- Application Number
- CN202510456149.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-11
- Publication Date
- 2025-08-12
AI Technical Summary
The existing technology cannot efficiently and accurately realize the automatic layout of double-line clip-on text, resulting in waste of layout, reduced visual distinction, complex editing, and inability to adapt to the screen, limiting the informatization and digital application of ancient books.
Receive text through concise marking grammar, identify and separate the body and clamped text, calculate the grid count, judge cross-row layout, partition and generate double-line clamped layout results, and use transparent floating bodies to achieve grid alignment, support plain text input and dynamic adjustment.
It realizes adaptive layout of double-line clip-on text on any size layout, ensuring visual effects and academic value, supporting retrieval and lossless copying, lowering the threshold for use, and is suitable for the compilation and research of ancient books.
Smart Images

Figure CN120471018A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electronic digital data processing, in particular to an automatic typesetting method for double-line interleaved text. Background Art
[0002] Double-line footnotes are a major feature of Chinese character typesetting, commonly found in various ancient books from China, Japan, South Korea, and Vietnam. Their function is equivalent to modern popular bracketed notes, where the notes are embedded in the main text in fine, small characters, following the annotated text. In ancient books, the two lines (small lines) of double-line footnotes occupy one line (large line) of the main text. This design not only saves space and facilitates reading, but also changes the flow of the text. In the information age, the informatization of ancient books has become an urgent need. However, because double-line footnotes are connected to the text flow of the single-line main text and have different rules and methods for line breaking, their automatic typesetting has always been a problem.
[0003] In the prior art, when traditional publishing houses were typeset and proofread ancient books, they often changed double-line footnote text to single-line footnote text due to technical limitations, resulting in wasted space and reducing the visual distinction between the main text and the footnotes, affecting the reading experience. Document software (such as Microsoft Word and Kingsoft Word) provides a "double-line merge" function, but there are problems such as uneven punctuation alignment, unreasonable text size ratio, and inability to align with the main text grid, and there are serious defects in editing and retrieval. Although LaTeX typesetting engines (such as XeLaTeX and UpTeX) have macro packages to support double-line footnote text, they are complex to use and slow to compile. In automatic mode, line break misjudgment is prone to occur, and manual mode requires manual intervention, which is time-consuming and labor-intensive. Design software such as InDesign uses a page-by-page design method, which is not suitable for large-scale typesetting, and the main text and footnote text will be confused during editing and copying. The file format is closed-source binary, which limits the scope of use.
[0004] The main drawback of the existing technology is that it is unable to realize the automatic typesetting of double-line annotated text efficiently and accurately. The functions of the document software are limited and cannot meet the grid alignment and precise punctuation processing requirements of ancient book typesetting; the LaTeX engine is complex to use, the automatic mode is prone to errors, and the manual mode requires a lot of manual intervention and cannot adapt to dynamic layout changes; design software such as InDesign is not suitable for large-scale typesetting, and it is impossible to distinguish between the main text and the annotated text during editing and copying. In addition, the existing technology generally has the problem of static typesetting results and the inability to adapt to the screen, which limits its application in digital media. Therefore, there is an urgent need for a typesetting solution that can automatically, efficiently and accurately process double-line annotated text to meet the needs of the informatization and digitization of ancient books. Summary of the Invention
[0005] In light of this, the present invention provides an automatic typesetting method for double-line annotation text. By using a concise markup syntax to write a plain text document and using simple symbols to mark the beginning and end of the double-line annotation text, the method can automatically layout scroll-style and leaf-style books with double-line annotation text. This method solves the problem that existing technologies cannot align the annotation text with the main text and require manual adjustment.
[0006] To this end, the present invention provides the following technical solutions:
[0007] A method for automatically typesetting double-line annotation text, comprising:
[0008] Receive input text, identify and separate the main text and the annotation text;
[0009] Calculate the number of spaces occupied by the annotation text based on the number of characters in the input text and the preset typesetting rules;
[0010] Based on the number of spaces occupied by the annotation text and the preset typesetting rules, determine whether the annotation text needs to be typeset across multiple lines;
[0011] Divide the annotation text that needs to be typeset across multiple lines into sections and calculate the length of the first section, the width of the middle section, and the length of the last section.
[0012] Combine the length of the first area, the width of the middle area and the length of the last area to generate a double-line annotation layout result for the annotation text that needs to be typeset across large lines.
[0013] Furthermore, the calculation of the number of spaces occupied by the annotation text according to the number of characters in the input text and the preset typesetting rules includes:
[0014] Punctuation marks do not occupy character spaces;
[0015] One main text grid is large, and one footnote text grid is small;
[0016] The height of the main text grid and the annotation text grid is the same;
[0017] The width of one large grid is equal to the width of two small grids;
[0018] The main text has one large line, and the footnote text has one small line.
[0019] The width of one large row is equal to the width of two small rows.
[0020] Furthermore, judging whether the annotated text needs to be typeset across multiple lines based on the number of spaces occupied by the annotated text and the preset typesetting rules includes:
[0021] If the number of spaces occupied by the annotation text is greater than twice the remaining space of the main text in the line where its starting point is located, the annotation text will be typeset across the lines.
[0022] If the number of spaces occupied by the annotation text is less than or equal to twice the remaining number of spaces occupied by the main text in the line where it is located, the text will be typeset without crossing lines.
[0023] Furthermore, the length of the first area is the remaining number of spaces occupied by the main text of the large line in which it is located; and the first area is located in the large line where the starting point of the interleaved text is located.
[0024] Furthermore, the width of the middle area is an integer multiple of the large row:
[0025]
[0026] Among them, S represents the number of large grids occupied by the middle and last large lines; L represents the number of large grids contained in the preset large line; and R represents the number of large grids indented for the natural paragraph.
[0027] Furthermore, the length of the end zone is:
[0028] H=SX(LR)
[0029] Wherein, H represents the length of the last area; the last area is located in the line where the end point of the annotated text is located.
[0030] Furthermore, the method of generating a double-line interleaved annotation typesetting result of the interleaved text that needs to be typeset across large lines by combining the first area length, the middle area width, and the last area length includes:
[0031] At the position where a double-line footnote is required, the footnote text is embedded in the main text flow as a block-level element; the width of the block-level element is the width of the middle area plus 2 large lines; the left and right margins of the block-level element are each indented by 1 large line; a transparent floating body is set at the upper right corner and the lower left corner of the block-level element where it overlaps with the main text, so as to make the text in the first and last areas of the footnote be arranged into two small lines of equal length; a transparent floating body of the same shape as the last area is inserted in the last area of the block-level element, so as to make the main text flow after the footnote continue to the end point of the footnote.
[0032] Furthermore, it also includes:
[0033] For parenthetical text that does not span multiple lines, insert it into the main text via inline blocks;
[0034] Determine the length of the inline block based on the number of spaces occupied by the annotation text;
[0035] The inline block is located in the line where the starting point of the annotated text is located.
[0036] Furthermore, determining the length of the inline block includes:
[0037] If the number of spaces occupied by the annotation text is less than or equal to 2, the length of the inline block is 1 character space;
[0038] If the number of spaces occupied by the annotation text is greater than 2, the length of the inline block is g represents the number of grids occupied by the annotation text.
[0039] Furthermore, it also includes:
[0040] When a change in the typesetting rules is detected, it is determined again whether the annotation text needs to be typeset across multiple lines;
[0041] If typesetting is required across multiple rows, a new typesetting result will be generated based on the new first area length, middle area width, and last area length;
[0042] If the interleaved text before the typesetting rule change needs to span a large line, but the interleaved text does not need to span a large line after the typesetting rule change, the inserted transparent floating body will be deleted.
[0043] Advantages and positive effects of the present invention:
[0044] The present invention can realize the adaptive typesetting of double-line annotated text on a layout of any size by automatically calculating the size and shape of the annotated text placeholder. Because the calculation method of dynamically measuring the line length and the number of grids occupied by the annotated text is adopted, the width and distribution of the small lines can be quickly adjusted according to the layout size and content changes, without manual intervention, and significantly improving the typesetting efficiency. At the same time, due to the design that the annotated text grid is the same height as the main text grid, and punctuation marks do not occupy grids, it is possible to achieve grid typesetting with vertical and horizontal alignment, accurately restore the double-line annotated text style widely used in ancient books, and ensure the visual effect and academic value of typesetting. In addition, since it supports plain text input (such as .txt documents) and does not rely on special editing software, it is possible to lower the threshold for use and has wider applicability. Also because the typesetting algorithm strictly follows the character order of the source text, it is possible to generate a typesetting result consistent with the original text, support retrieval and lossless copying, meet the rigorous needs of academic research and publishing fields, and provide an efficient and accurate solution for the arrangement and research of ancient books. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0046] Figure 1 Flowchart of a method for automatically typesetting double-line annotation text in an embodiment of the present invention;
[0047] Figure 2 This is a schematic diagram of typesetting in an embodiment of the present invention;
[0048] Figure 3 This is a diagram showing the typesetting result of ancient books in an embodiment of the present invention;
[0049] Figure 4 Schematic diagram of the space occupied by a long interline note spanning across large lines in an embodiment of the present invention. DETAILED DESCRIPTION
[0050] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0051] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0052] The present invention provides an automatic typesetting method for double-line annotated text, which typesets the double-line annotated text according to the line length, takes plain text as input, and uses symbols to mark the start and end points of each paragraph of double-line annotated text in the input text; without considering factors unrelated to the content, such as setting line breaks and squeezing punctuation marks. The method of the present invention is adaptable to any line length, and does not require manual adjustment when the page size, font size, or number of words changes. The character grid of the annotated text is the same height as the character grid of the main text, and punctuation marks are arranged between characters and do not occupy the grid, which is in line with the convention of traditional books. The typesetting result is consistent with the character order of the source file and can be retrieved and copied losslessly.
[0053] Combine Figure 1 and 2 As shown, the present invention is further described with specific embodiments:
[0054] Large grid: represents the unit grid occupied by one text character in the text;
[0055] Small grid: represents the unit grid occupied by one annotation text character in the annotation text;
[0056] In terms of width, 1 large grid = 2 small grids;
[0057] The small grid is the same height as the large grid, so when measuring height, both are collectively referred to as grids.
[0058] Large line: represents one line in the body text.
[0059] Small line: represents 1 line in the bracketed text.
[0060] The width of one major line of body text is the sum of the widths of two minor lines of footer text.
[0061] S1, receiving the annotation text and the main text partitioned by symbols, and the preset number of large grids for large lines;
[0062] In this embodiment:
[0063] First paragraph of footnote text: ((=The name of beauty=)) + Main text: Main text in large format, this example + Second paragraph of footnote text: ((=Long footnote does not cross lines=)) + Main text: Line length is sixteen grids + Third paragraph of footnote text: ((=Long footnote crosses large lines...=) Main text continues...
[0064] The preset number of large cells in each large row is L=16;
[0065] S2. Extract all the annotated texts; process each annotated text separately according to the symbols;
[0066] S3, extracting the punctuation marks and anchors that do not occupy a grid in the annotated text, and obtaining the number of small grids of each plain text annotated text;
[0067] In this embodiment, the number of small grids for the second plain text segment and the annotation text is g=6; the number of small grids for the third plain text segment and the annotation text is g=152;
[0068] S4, assigning a typesetting strategy to each paragraph of the annotation text according to the number of cells of the plain text annotation text;
[0069] Specifically:
[0070] 1. If g≤2, that is, the paragraph of annotation text only occupies one large grid, then the paragraph of annotation text is set as an inline block;
[0071] 2. If g > 2, that is, the number of cells occupied by the annotation is greater than 1, then the annotation is a long one. Calculate the number of cells Y remaining in the line where the annotation starts. Determine the layout strategy based on the relationship between g and Y. Specifically:
[0072] 2.1、If 2<g≤2Y, then the paragraph of annotation text is the annotation text that does not span the line length, set as the inline block, located in the line where the paragraph of annotation text starts, and the length is
[0073] In this embodiment, the second paragraph of the annotation text satisfies 2<g≤2Y; therefore, the second paragraph of the annotation text is the annotation text that does not span the line length, and the typesetting strategy is the inline block located in the line where the starting point of the paragraph of the annotation text is located, with a length of 3.
[0074] 2.2. If g>2Y, then this paragraph of interleaved text spans multiple lines. The interleaved text needs to occupy three sections:
[0075] The first area is located in the row where the starting point is located, and its length is the number of remaining large grids Y in the row where the starting point is located;
[0076] The middle area is composed of a whole line, has the same height as the paragraph, and its width is an integer multiple of the large line;
[0077] The last area is located on the line where the annotation text ends.
[0078] Get the indentation number R of the paragraph where the annotation text is located;
[0079] Calculate the number of cells occupied by the middle and end areas of the annotation text
[0080] According to the number of large grids S occupied by the middle and end areas of the annotated text and the preset number of large grids L in each line, the number of large lines occupied by the middle area and the number of large grids that the end area should occupy in the line where the end of the annotated text is located are calculated;
[0081] Specifically, the central area needs to account for the majority of the rows: The last area of the paragraph needs to occupy a large number of grids on the line where the end point of the annotation text is located: H=SX(LR).
[0082] In the main text flow, place a Figure 4 The block-level element shown above fills the annotation text into the block-level element block.
[0083] The width of the block-level element is X+2 lines; the left and right margins of the block-level element are each inset by 1 line (that is, the margin-left and margin-right properties are set to -1 line width);
[0084] Place a transparent float at the top right and bottom left corners of the block-level element where they overlap with the body text, such as Figure 4 As shown in the black block, it is used to prevent the text from being inserted.
[0085] A transparent floating body of the same shape as the end area is placed at the end area; the length of the floating body is H grids and the width is 1 line, so that the main text after the interleaved text continues to the end point of the interleaved text.
[0086] Combine Figure 2 As shown, in this embodiment, the third annotation text g=152, g>2Y, Y=15;
[0087] Calculate the number of cells occupied by the middle and end areas of the paragraph annotation text
[0088] The central area needs to occupy a large number of rows:
[0089] The last area of the paragraph where the end of the annotation text ends needs to occupy the maximum number of grids: H = SX (LR) = 61-3 × 16 = 13;
[0090] The third paragraph of the annotation text has the following layout strategy:
[0091] Construct a block-level element with a width of 5 lines; the left and right margins of the block-level element are indented by one line each;
[0092] Place a transparent floating body at the upper right corner and lower left corner of the block-level element where it overlaps with the main text to prevent the text from being inserted.
[0093] A transparent floating body is set at the end area; the length of the floating body is 13 grids and the width is 1 line, so that the main text after the annotation text continues to the end point of the annotation text.
[0094] S5. When the font size, word count, or page size changes, the line length L will change accordingly and the layout will be re-formatted.
[0095] For each long annotation, re-determine whether it spans lines. Measure the number of remaining grid cells, Y, on the line where the annotation begins. Based on the relationship between g and 2Y, repeat steps 2.1 and 2.2. If the annotation spanned lines before the change but does not after the change, delete the inserted float.
[0096] Figure 3 The following is a typesetting example of "Chuci Buzhu·Li Sao" using the method of this embodiment, where the line length is 16 grids and the indentation is 0 grids. In addition to the first five small characters of the interleaved text, it contains a paragraph of interleaved text that does not span the line length and another paragraph of interleaved text that spans the line length. The interleaved text spanning the line length is g = 152 small grids, the first area is Y = 15 grids long, the middle area is X = 3 large lines wide, and the last area is H = 13 grids long. The layout diagram is as follows: Figure 4 As shown, the black block in the upper right corner represents the main text before the annotation, the right slash area below it represents the first area, the dotted shaded area in the middle represents the middle area, the left slash on the left represents the last area, and the black block in the lower left corner represents the main text after the annotation. The typesetting effect of the present method can be found at https: / / vert.neocities.org / .
[0097] Figure 3As can be seen, the method presented here achieves a grid-aligned effect for double-line annotations in ancient books. That is, on any page length, the double-line annotations are aligned with the main text, forming a grid-like pattern vertically and horizontally throughout the text. This method not only restores the style of the ancient book but also achieves a neat typesetting effect on any layout. It can adapt to any screen size for on-screen reading, but can also output PDF files for printing.
[0098] The method of the present invention enables double-line annotated text to adapt to the layout and can automatically arrange double-line annotated text on a layout of any size without manual adjustment. The size and shape of the annotated text space are calculated and classified based on the measured value of the line and the number of grids occupied by the annotated text. This allows the algorithm to quickly and automatically adjust and rearrange when the layout or content changes. In this method, the grid of the annotated text is the same height as the grid of the main text, and punctuation marks do not occupy grids, achieving a grid-like layout with vertical and horizontal alignment. This is the most widely used double-line annotated text style for ancient books. The typesetting result is consistent with the character order of the source text, can be retrieved, and can be copied losslessly.
[0099] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for automatically typesetting double-line annotation text, characterized in that: include: Receive input text, identify and separate the main text and the annotation text; Calculate the number of spaces occupied by the annotation text based on the number of characters in the input text and the preset typesetting rules; Based on the number of spaces occupied by the annotation text and the preset typesetting rules, determine whether the annotation text needs to be typeset across multiple lines; Divide the annotation text that needs to be typeset across multiple lines into sections and calculate the length of the first section, the width of the middle section, and the length of the last section. Combine the length of the first area, the width of the middle area and the length of the last area to generate a double-line annotation layout result for the annotation text that needs to be typeset across large lines.
2. The automatic typesetting method for double-line annotation text according to claim 1, characterized in that: The step of calculating the number of spaces occupied by the annotation text according to the number of characters in the input text and the preset typesetting rules includes: Punctuation marks do not occupy character spaces; One main text grid is large, and one footnote text grid is small; The height of the main text grid and the annotation text grid is the same; The width of one large grid is equal to the width of two small grids; The main text has one large line, and the footnote text has one small line. The width of one large row is equal to the width of two small rows.
3. The automatic typesetting method for double-line annotation text according to claim 2, characterized in that: The step of determining whether the annotated text needs to be typeset across multiple lines based on the number of spaces occupied by the annotated text and the preset typesetting rules includes: If the number of spaces occupied by the annotation text is greater than twice the remaining space of the main text in the line where its starting point is located, the annotation text will be typeset across the lines. If the number of spaces occupied by the annotation text is less than or equal to twice the remaining number of spaces occupied by the main text in the line where it is located, the text will be typeset without crossing lines.
4. The automatic typesetting method for double-line annotation text according to claim 2, characterized in that: The length of the first area is the remaining number of spaces occupied by the main text of the large line in which it is located; and the first area is located in the large line where the starting point of the interleaved text is located.
5. The automatic typesetting method for double-line annotation text according to claim 4, characterized in that: The width of the middle area is an integer multiple of the large row: Among them, S represents the number of large grids occupied by the middle and last large lines; L represents the number of large grids contained in the preset large line; and R represents the number of large grids indented for the natural paragraph.
6. The automatic typesetting method for double-line annotation text according to claim 5, characterized in that: The length of the end zone is: H=SX(LR) Wherein, H represents the length of the last area; the last area is located in the line where the end point of the annotated text is located.
7. The automatic typesetting method for double-line annotation text according to claim 1, characterized in that: The method of generating a double-line interleaved annotation typesetting result of the interleaved text that needs to be typeset across large lines by combining the first area length, the middle area width, and the last area length includes: At the position where a double-line footnote is required, the footnote text is embedded in the main text flow as a block-level element; the width of the block-level element is the width of the middle area plus 2 large lines; the left and right margins of the block-level element are each indented by 1 large line; a transparent floating body is set at the upper right corner and the lower left corner of the block-level element where it overlaps with the main text, so as to make the text in the first and last areas of the footnote be arranged into two small lines of equal length; a transparent floating body of the same shape as the last area is inserted in the last area of the block-level element, so as to make the main text flow after the footnote continue to the end point of the footnote.
8. The automatic typesetting method for double-line annotation text according to claim 3, characterized in that: Also includes: For parenthetical text that does not span multiple lines, insert it into the main text via inline blocks; Determine the length of the inline block based on the number of spaces occupied by the annotation text; The inline block is located in the line where the starting point of the annotated text is located.
9. The automatic typesetting method for double-line annotation text according to claim 8, characterized in that: The determining of the length of the inline block based on the number of spaces occupied by the annotated text includes: If the number of spaces occupied by the annotation text is less than or equal to 2, the length of the inline block is 1 character space; If the number of spaces occupied by the annotation text is greater than 2, the length of the inline block is g represents the number of grids occupied by the annotation text.
10. The automatic typesetting method for double-line annotation text according to claim 1, characterized in that: Also includes: When a change in the typesetting rules is detected, it is determined again whether the annotation text needs to be typeset across multiple lines; If typesetting is required across multiple rows, a new typesetting result will be generated based on the new first area length, middle area width, and last area length; If the interleaved text before the typesetting rule change needs to span a large line, but the interleaved text does not need to span a large line after the typesetting rule change, the inserted transparent floating body will be deleted.