@@ -242,8 +242,8 @@ def handle_equations_in_text(self, element, text):
242
242
def handle_text_elements (self , element , docx_obj , doc ):
243
243
paragraph = docx .text .paragraph .Paragraph (element , docx_obj )
244
244
245
- text = paragraph .text
246
- text = self .handle_equations_in_text (element = element , text = text )
245
+ raw_text = paragraph .text
246
+ text = self .handle_equations_in_text (element = element , text = raw_text )
247
247
248
248
if text is None :
249
249
return
@@ -281,21 +281,20 @@ def handle_text_elements(self, element, docx_obj, doc):
281
281
self .parents [key ] = None
282
282
self .level = self .level_at_new_list - 1
283
283
self .level_at_new_list = None
284
+
284
285
if p_style_id in ["Title" ]:
285
286
for key , val in self .parents .items ():
286
287
self .parents [key ] = None
287
288
self .parents [0 ] = doc .add_text (
288
289
parent = None , label = DocItemLabel .TITLE , text = text
289
290
)
291
+
290
292
elif "Heading" in p_style_id :
291
293
self .add_header (element , docx_obj , doc , p_style_id , p_level , text )
292
294
293
295
elif p_style_id in [
294
- "Paragraph" ,
295
- "Normal" ,
296
296
"Subtitle" ,
297
297
"Author" ,
298
- "DefaultText" ,
299
298
"ListParagraph" ,
300
299
"ListBullet" ,
301
300
"Quote" ,
@@ -305,12 +304,32 @@ def handle_text_elements(self, element, docx_obj, doc):
305
304
label = DocItemLabel .PARAGRAPH , parent = self .parents [level - 1 ], text = text
306
305
)
307
306
307
+ elif (raw_text is None or len (raw_text ) == 0 ) and len (text ) > 0 :
308
+ # Standalone equation
309
+ # Entities in which all text comes from equations
310
+ level = self .get_level ()
311
+ if text .strip ().startswith ("$" ) and text .strip ().endswith ("$" ):
312
+ text = text .strip ()[1 :- 1 ]
313
+ doc .add_text (
314
+ label = DocItemLabel .FORMULA , parent = self .parents [level - 1 ], text = text
315
+ )
316
+
317
+ elif p_style_id in [
318
+ "Paragraph" ,
319
+ "Normal" ,
320
+ "DefaultText" ,
321
+ ]:
322
+ level = self .get_level ()
323
+ doc .add_text (
324
+ label = DocItemLabel .PARAGRAPH , parent = self .parents [level - 1 ], text = text
325
+ )
326
+
308
327
else :
309
328
# Text style names can, and will have, not only default values but user values too
310
329
# hence we treat all other labels as pure text
311
330
level = self .get_level ()
312
331
doc .add_text (
313
- label = DocItemLabel .PARAGRAPH , parent = self .parents [level - 1 ], text = text
332
+ label = DocItemLabel .TEXT , parent = self .parents [level - 1 ], text = text
314
333
)
315
334
self .update_history (p_style_id , p_level , numid , ilevel )
316
335
return
0 commit comments