feat(jats/inline-formula): Support emphasis elements and Inline formulas - #3726
Conversation
|
✅ DCO Check Passed Thanks @taru-garg-2000, all your commits are properly signed off. 🎉 |
Merge Protections🟢 All 2 merge protections satisfied — ready to merge. Show 2 satisfied protections🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 Require two reviewer for test updatesWhen test data is updated, we require two reviewers
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This is correct and it affects all parsers. Just accept it as the normal behavior for now. There is another PR in docling-core that will fix it. |
ceberam
left a comment
There was a problem hiding this comment.
Thanks @taru-garg-2000 for your PR. Please, see my comments below.
I was also wondering if you could extend the styling of text beyond the inline formulas, since it is still missing. I guess it would be pretty simple to reuse the static methods you created to add the formatting of text.
|
Hi @ceberam , Thanks a lot for the review! Happy to extend it for generalised implementation on formatting tags, I was wondering though if it would be better to keep it as a separate PR ? |
Let's do it in this PR since it will help us better design the formatting in a reusable manner. |
|
Hi @ceberam, There's some polishing still left I feel, however was looking to get an early review if the approach looks good ? For \documentclass[12pt]{minimal} \usepackage{wasysym} \usepackage[substack]{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage[mathscr]{eucal} \usepackage{mathrsfs} \DeclareFontFamily{T1}{linotext}{} \DeclareFontShape{T1}{linotext}{m}{n} { <-> linotext }{} \DeclareSymbolFont{linotext}{T1}{linotext}{m}{n} \DeclareSymbolFontAlphabet{\mathLINOTEXT}{linotext} \begin{document} $$ \frac{dA(t)}{dt}={\gamma}_{i,j,B} \left( { \,\substack{ ^{3} \\ {\sum} \\ _{i=1} }\, }I_{i,F,B}(t)+I_{i,M,B}(t) \right) -{\mu}_{A}A(t)-{\delta}A(t), $$ \end{document}Which kind of corrupts the render of actual formula \frac{dA(t)}{dt}={\gamma}_{i,j,B} \left( { \,\substack{ ^{3} \\ {\sum} \\ _{i=1} }\, }I_{i,F,B}(t)+I_{i,M,B}(t) \right) -{\mu}_{A}A(t)-{\delta}A(t)Although it is latex, we don't really render it correctly when the conversion to markdown happens. |
|
Polished up the remaining bit, so for the current implementation we check if the text in a |
|
@taru-garg-2000 I have added the commit 9d55328 , which replaces my previous JATS example with another one having |
|
Great! Could you please rebase to |
Signed-off-by: Taru Garg <taru.garg@hashicorp.com>
Signed-off-by: Taru Garg <taru.garg@hashicorp.com>
Signed-off-by: Taru Garg <taru.garg@hashicorp.com>
Generalize the inline walker to accumulate styled InlineSegments so bold, italic, underline, strike, sub, and sup formatting is preserved for all paragraph text, not only inside inline formulas. Regenerate JATS groundtruth to include the recovered body emphasis. Signed-off-by: Taru Garg <taru.garg@hashicorp.com>
Condense the multi-line docstring/comments added for the inline emphasis walker, and remove the markdown-rendering test that duplicated the italic-inside-formula structural case. Signed-off-by: Taru Garg <taru.garg@hashicorp.com>
Add a PMC article to test the parsing of formulas in JATS documents. Add third-party attribution notice for JATS test data. Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
9d55328 to
53b0a45
Compare
ceberam
left a comment
There was a problem hiding this comment.
Thanks @taru-garg-2000 for addressing the previous comments. I went through a detailed review. I can confirm that inline JATS formulas are now emitted as ordered inline pieces, with surrounding emphasis preserved as formatted text and tex-math kept as formula content. The targeted behavior is covered by meaningful tests, and I don't see significant security or performance concerns from these changes.
Must fix
InlineSegmentis a plain@dataclass, but its fields are annotated with Pydantic-styleField(...). That pattern should be reserved for actual Pydantic models. For a normal dataclass, plain type annotations are the right fit here. For documentation, usedataclass.fieldinstead of pydantic'sFieldfunction.
Notes
- The whitespace policy in
_strip_segments()is a bit aggressive since it strips every segment independently. It may need to be reviewed after docling-project/docling-core#605 and #3527
Signed-off-by: Taru Garg <taru.garg@hashicorp.com>
|
Hi @ceberam, Thanks a lot for the feedback, since the Let me know in case we lean towards another approach. |
|
Hi @ceberam, Not really sure why the test is failing but it seems like a timeout than something to do with change, wondering if you can re-trigger this? |

#3696 landed inline
tex-mathrendering for JATS as the first step. This continues that work by handling the styling that can sit alongside the formula inside an<inline-formula>.When we walk an
<inline-formula>, we now break it into ordered inline pieces instead of one flat string: thetex-mathbecomes the formula, and emphasis around it (italic,bold,underline,strike,sub,sup) is kept as styled text. MathML<mml:math>or other alternatives are skipped — as MathML isn't parsed yet, so we rely on thetex-mathsibling instead. The pieces go into an inline group so everything still reads as one continuous line.A couple of examples:
The
xstays italic right next to thea^2formula.One thing I noticed with things like Superscript or Subscript, there is a space in between the element which carry that super/sub-script and the actual element in the sub/super-script. To explain, when parsing something like
We would expect to be rendered as x2 but it actually renders as x
2 (notice the space), it seems this is because how the elements are serialized, but I haven't looked into it that much.