Skip to content

text-extraction: figure-region math glyphs (subscripts/superscripts) emitted line-per-glyph and interleaved with adjacent captions #556

Description

@yfedoseev

Summary

On math-heavy single-column pages (gnuplot-rendered figures + equations) the extractor mis-orders inline math fragments and orphaned subscripts/superscripts. Numerals and superscripts emitted by \textsuperscript{} / _{...} ^{...} blocks land on their own short lines, separated from the base symbol.

Examples from https://arxiv.org/pdf/1601.03642.pdf:

expected: ... activation function ϕ is applied ...
actual:   '... activation func- is blue.\n  tion ϕ is applied. ...'   (sub-caption interleaves)
expected: 1 / (1 + e^{-x})
actual:   '1+1e−x'  (figure-region equation collapsed)
expected:  ... E with respect to some class of tasks T and ...
actual:    'wxxx... w0 \n x0 \n x1 \n w1 \n w2 \n Martin Thoma x2 Σ ϕ \n w \n ...'

The first page of 1601.03642 contains an artificial-neuron figure whose math glyphs (x_i, w_i, Σ, ϕ) are scattered single-per-line. Identical behaviour seen on 2201.00021 page 1 (NH₃ subscripts) and 2201.00200 page 1 (overshoot equations).

Reproduction

import pdf_oxide  # 0.3.54
doc = pdf_oxide.PdfDocument("1601.03642.pdf")
print(doc.extract_text(0)[:600])

Expected (ground truth)

Equations and figure-internal labels either grouped into a single coherent text block or omitted entirely.

Actual

Each subscript / superscript / single glyph emitted on its own line, interleaved with caption text of an adjacent figure region. Score on 1601.03642: 74.0% (markdown mode recovers to 93.0% by keeping the figure region contained).

Impact

  • 1601.03642 (creativity-in-ml.pdf by Thoma): -19 pt vs markdown mode
  • 1602.06541 (survey-of-semantic-segmentation.pdf): -16 pt vs markdown mode
  • 2201.00200, 2201.00021 (equation-rich astro papers): -10 pt each

Hypothesis

The figure regions are detected as text regions by extract_text, and within them every glyph from the gnuplot/PSTricks figure becomes a separate "line" because the y-coordinate sort treats each glyph as its own row (figures often have lots of glyphs at slightly different y). The XY-cut pipeline (used in markdown) correctly clusters them into a single block.

Suggested fix

When extract_text runs, apply a coarse y-band clustering (tolerance ≥ 0.5 × line-height) before emitting glyphs in y-order. Alternatively, integrate the figure-detector that to_markdown_all evidently uses to skip image-region text entirely.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions