diff --git a/docling/utils/layout_postprocessor.py b/docling/utils/layout_postprocessor.py index effce01b..edc6b396 100644 --- a/docling/utils/layout_postprocessor.py +++ b/docling/utils/layout_postprocessor.py @@ -267,9 +267,14 @@ class LayoutPostprocessor: # Initial cell assignment clusters = self._assign_cells_to_clusters(clusters) - # Remove clusters with no cells (if keep_empty_clusters is False) + # Remove clusters with no cells (if keep_empty_clusters is False), + # but always keep clusters with label DocItemLabel.FORMULA if not self.options.keep_empty_clusters: - clusters = [cluster for cluster in clusters if cluster.cells] + clusters = [ + cluster + for cluster in clusters + if cluster.cells or cluster.label == DocItemLabel.FORMULA + ] # Handle orphaned cells unassigned = self._find_unassigned_cells(clusters)