mirror of
https://github.com/DS4SD/docling.git
synced 2025-07-26 20:14:47 +00:00
fix(docx): Adding plain latex equations to table cells (#1986)
* Adding plain latex equations to table cells Signed-off-by: Rafael Teixeira de Lima <Rafael.td.lima@gmail.com> * Adding test files Signed-off-by: Rafael Teixeira de Lima <Rafael.td.lima@gmail.com> --------- Signed-off-by: Rafael Teixeira de Lima <Rafael.td.lima@gmail.com>
This commit is contained in:
parent
98e2fcff63
commit
0b83609531
@ -1104,8 +1104,17 @@ class MsWordDocumentBackend(DeclarativeDocumentBackend):
|
||||
)
|
||||
_log.debug(f" spanned before row {spanned_idx}")
|
||||
|
||||
# Detect equations in cell text
|
||||
text, equations = self._handle_equations_in_text(
|
||||
element=cell._element, text=cell.text
|
||||
)
|
||||
if len(equations) == 0:
|
||||
text = cell.text
|
||||
else:
|
||||
text = text.replace("<eq>", "$").replace("</eq>", "$")
|
||||
|
||||
table_cell = TableCell(
|
||||
text=cell.text,
|
||||
text=text,
|
||||
row_span=spanned_idx - row_idx,
|
||||
col_span=cell.grid_span,
|
||||
start_row_offset_idx=row.grid_cols_before + row_idx,
|
||||
|
BIN
tests/data/docx/table_with_equations.docx
vendored
Normal file
BIN
tests/data/docx/table_with_equations.docx
vendored
Normal file
Binary file not shown.
3
tests/data/groundtruth/docling_v2/table_with_equations.docx.itxt
vendored
Normal file
3
tests/data/groundtruth/docling_v2/table_with_equations.docx.itxt
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
item-0 at level 0: unspecified: group _root_
|
||||
item-1 at level 1: table with [2x2]
|
||||
item-2 at level 1: paragraph:
|
174
tests/data/groundtruth/docling_v2/table_with_equations.docx.json
vendored
Normal file
174
tests/data/groundtruth/docling_v2/table_with_equations.docx.json
vendored
Normal file
@ -0,0 +1,174 @@
|
||||
{
|
||||
"schema_name": "DoclingDocument",
|
||||
"version": "1.5.0",
|
||||
"name": "table_with_equations",
|
||||
"origin": {
|
||||
"mimetype": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"binary_hash": 6528760837820727976,
|
||||
"filename": "table_with_equations.docx"
|
||||
},
|
||||
"furniture": {
|
||||
"self_ref": "#/furniture",
|
||||
"children": [],
|
||||
"content_layer": "furniture",
|
||||
"name": "_root_",
|
||||
"label": "unspecified"
|
||||
},
|
||||
"body": {
|
||||
"self_ref": "#/body",
|
||||
"children": [
|
||||
{
|
||||
"$ref": "#/tables/0"
|
||||
},
|
||||
{
|
||||
"$ref": "#/texts/0"
|
||||
}
|
||||
],
|
||||
"content_layer": "body",
|
||||
"name": "_root_",
|
||||
"label": "unspecified"
|
||||
},
|
||||
"groups": [],
|
||||
"texts": [
|
||||
{
|
||||
"self_ref": "#/texts/0",
|
||||
"parent": {
|
||||
"$ref": "#/body"
|
||||
},
|
||||
"children": [],
|
||||
"content_layer": "body",
|
||||
"label": "paragraph",
|
||||
"prov": [],
|
||||
"orig": "",
|
||||
"text": ""
|
||||
}
|
||||
],
|
||||
"pictures": [],
|
||||
"tables": [
|
||||
{
|
||||
"self_ref": "#/tables/0",
|
||||
"parent": {
|
||||
"$ref": "#/body"
|
||||
},
|
||||
"children": [],
|
||||
"content_layer": "body",
|
||||
"label": "table",
|
||||
"prov": [],
|
||||
"captions": [],
|
||||
"references": [],
|
||||
"footnotes": [],
|
||||
"data": {
|
||||
"table_cells": [
|
||||
{
|
||||
"row_span": 1,
|
||||
"col_span": 1,
|
||||
"start_row_offset_idx": 0,
|
||||
"end_row_offset_idx": 1,
|
||||
"start_col_offset_idx": 0,
|
||||
"end_col_offset_idx": 1,
|
||||
"text": "The next cell has an equation",
|
||||
"column_header": true,
|
||||
"row_header": false,
|
||||
"row_section": false
|
||||
},
|
||||
{
|
||||
"row_span": 1,
|
||||
"col_span": 1,
|
||||
"start_row_offset_idx": 0,
|
||||
"end_row_offset_idx": 1,
|
||||
"start_col_offset_idx": 1,
|
||||
"end_col_offset_idx": 2,
|
||||
"text": "$A= \\pi r^{2}$",
|
||||
"column_header": true,
|
||||
"row_header": false,
|
||||
"row_section": false
|
||||
},
|
||||
{
|
||||
"row_span": 1,
|
||||
"col_span": 1,
|
||||
"start_row_offset_idx": 1,
|
||||
"end_row_offset_idx": 2,
|
||||
"start_col_offset_idx": 0,
|
||||
"end_col_offset_idx": 1,
|
||||
"text": "The next cell has another equation",
|
||||
"column_header": false,
|
||||
"row_header": false,
|
||||
"row_section": false
|
||||
},
|
||||
{
|
||||
"row_span": 1,
|
||||
"col_span": 1,
|
||||
"start_row_offset_idx": 1,
|
||||
"end_row_offset_idx": 2,
|
||||
"start_col_offset_idx": 1,
|
||||
"end_col_offset_idx": 2,
|
||||
"text": "$x=\\frac{-b \\pm \\sqrt{b^{2}-4ac}}{2a}$",
|
||||
"column_header": false,
|
||||
"row_header": false,
|
||||
"row_section": false
|
||||
}
|
||||
],
|
||||
"num_rows": 2,
|
||||
"num_cols": 2,
|
||||
"grid": [
|
||||
[
|
||||
{
|
||||
"row_span": 1,
|
||||
"col_span": 1,
|
||||
"start_row_offset_idx": 0,
|
||||
"end_row_offset_idx": 1,
|
||||
"start_col_offset_idx": 0,
|
||||
"end_col_offset_idx": 1,
|
||||
"text": "The next cell has an equation",
|
||||
"column_header": true,
|
||||
"row_header": false,
|
||||
"row_section": false
|
||||
},
|
||||
{
|
||||
"row_span": 1,
|
||||
"col_span": 1,
|
||||
"start_row_offset_idx": 0,
|
||||
"end_row_offset_idx": 1,
|
||||
"start_col_offset_idx": 1,
|
||||
"end_col_offset_idx": 2,
|
||||
"text": "$A= \\pi r^{2}$",
|
||||
"column_header": true,
|
||||
"row_header": false,
|
||||
"row_section": false
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"row_span": 1,
|
||||
"col_span": 1,
|
||||
"start_row_offset_idx": 1,
|
||||
"end_row_offset_idx": 2,
|
||||
"start_col_offset_idx": 0,
|
||||
"end_col_offset_idx": 1,
|
||||
"text": "The next cell has another equation",
|
||||
"column_header": false,
|
||||
"row_header": false,
|
||||
"row_section": false
|
||||
},
|
||||
{
|
||||
"row_span": 1,
|
||||
"col_span": 1,
|
||||
"start_row_offset_idx": 1,
|
||||
"end_row_offset_idx": 2,
|
||||
"start_col_offset_idx": 1,
|
||||
"end_col_offset_idx": 2,
|
||||
"text": "$x=\\frac{-b \\pm \\sqrt{b^{2}-4ac}}{2a}$",
|
||||
"column_header": false,
|
||||
"row_header": false,
|
||||
"row_section": false
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"annotations": []
|
||||
}
|
||||
],
|
||||
"key_value_items": [],
|
||||
"form_items": [],
|
||||
"pages": {}
|
||||
}
|
3
tests/data/groundtruth/docling_v2/table_with_equations.docx.md
vendored
Normal file
3
tests/data/groundtruth/docling_v2/table_with_equations.docx.md
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
| The next cell has an equation | $A= \pi r^{2}$ |
|
||||
|------------------------------------|----------------------------------------|
|
||||
| The next cell has another equation | $x=\frac{-b \pm \sqrt{b^{2}-4ac}}{2a}$ |
|
Loading…
Reference in New Issue
Block a user