@@ -130,25 +130,39 @@ def generate_cross_reference_order(self):
130130 self .annotations ["orders" ].extend (annotations )
131131
132132 def generate_float_envs_order (self ):
133- # annotations = []
134133 label_pattern = r"\\label\{(.*?)\}"
134+
135+ with open (self .tex_file , "r" ) as f :
136+ latex_content = f .read ()
135137 # 0, add labels for titles
136138 # TODO: add labels for other types of titles
137139 for block in self .annotations ["annotations" ]:
138140 if config .category2name [block .category ] != "Title" :
139141 continue
140142 block .labels = re .findall (label_pattern , block .source_code )
141143
144+ start_index = latex_content .find (block .source_code )
145+ if start_index == - 1 :
146+ continue
147+ end_index = start_index + len (block .source_code )
148+ _matches = re .finditer (label_pattern , latex_content [end_index :], re .DOTALL )
149+ for _match in _matches :
150+ label_start_index , label_end_index = (
151+ _match .start () + end_index ,
152+ _match .end () + end_index ,
153+ )
154+ label_content = latex_content [label_start_index :label_end_index ]
155+ if latex_content [end_index :label_start_index ].isspace ():
156+ block .labels = re .findall (label_pattern , label_content )
157+ break
158+
142159 # 1. add labels for equations
143160 for block in self .annotations ["annotations" ]:
144161 if config .category2name [block .category ] != "Equation" :
145162 continue
146163 block .labels = re .findall (label_pattern , block .source_code )
147164
148165 # 2. add labels for float envs
149- # colored_tex_file = self.tex_file.replace("paper_original", "paper_colored")
150- with open (self .tex_file , "r" ) as f :
151- latex_content = f .read ()
152166 # find the intetval of tables
153167 category_to_patterns = {
154168 "Table" : re .compile (
0 commit comments