add regex latex for $$ tags
@@ -18,12 +18,24 @@ import json
from pprint import pprint
+import re
+
import numpy as np
import cv2
from imageio import imread, imsave
from explanations.explanations.bounding_box import bbs_for_color, find_connected_components, cluster_nearby_connected_components, merge_bbs
from explanations.explanations.image_diff import diff_two_images
+from collections import namedtuple
+Span = namedtuple('Span', 'start end text')
+
+def find_all_math_tags(input_latex_file: str) -> List[Span]:
+ with open(input_latex_file, "rb") as f:
+ # Some files may cause a UnicodeDecodeError if read directly as text, e.g. '/net/nfs.corp/s2-research/figure-extraction/data/distant-data/arxiv/src/0001/cond-mat0001356/s10677c.tex'
+ text = bs4.UnicodeDammit(f.read()).unicode_markup
+ spans = [Span(matches.start(0), matches.end(0), text[matches.start(0):matches.end(0)]) for matches in re.finditer(r'(\$(.*?)\$)', text)]
+ return spans
+
def call_pdflatex(input_latex_dir: str, output_latex_dir: str):
pass
