Skip to content

Commit

Permalink
Merge pull request #459 from VikParuchuri/dev
Browse files Browse the repository at this point in the history
Fix error with delimiters
  • Loading branch information
VikParuchuri authored Jan 3, 2025
2 parents 4f6a089 + c471187 commit 3a20621
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
15 changes: 14 additions & 1 deletion marker/schema/blocks/equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ class Equation(Block):
def assemble_html(self, child_blocks, parent_structure=None):
if self.latex:
html_out = f"<p block-type='{self.block_type}'>"
for el in self.parse_latex(html.escape(self.latex)):

try:
latex = self.parse_latex(html.escape(self.latex))
except ValueError as e:
# If we have mismatched delimiters, we'll treat it as a single block
# Strip the $'s from the latex
latex = [
{"class": "block", "content": self.latex.replace("$", "")}
]

for el in latex:
if el["class"] == "block":
html_out += f'<math display="block">{el["content"]}</math>'
elif el["class"] == "inline":
Expand All @@ -26,6 +36,9 @@ def assemble_html(self, child_blocks, parent_structure=None):

@staticmethod
def parse_latex(text: str):
if text.count("$") % 2 != 0:
raise ValueError("Mismatched delimiters in LaTeX")

DELIMITERS = [
("$$", "block"),
("$", "inline")
Expand Down
1 change: 0 additions & 1 deletion marker/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Settings(BaseSettings):

# General models
TORCH_DEVICE: Optional[str] = None # Note: MPS device does not work for text detection, and will default to CPU
GOOGLE_API_KEY: Optional[str] = None

@computed_field
@property
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "marker-pdf"
version = "1.2.2"
version = "1.2.3"
description = "Convert PDF to markdown with high speed and accuracy."
authors = ["Vik Paruchuri <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 3a20621

Please sign in to comment.