@@ -302,6 +302,7 @@ def _read(self):
302
302
# Pages appear to start with the sequence
303
303
# bop (begin of page)
304
304
# xxx comment
305
+ # <push, ..., pop> # if using chemformula
305
306
# down
306
307
# push
307
308
# down
@@ -313,17 +314,24 @@ def _read(self):
313
314
# etc.
314
315
# (dviasm is useful to explore this structure.)
315
316
# Thus, we use the vertical position at the first time the stack depth
316
- # reaches 3, while at least three "downs" have been executed, as the
317
+ # reaches 3, while at least three "downs" have been executed (excluding
318
+ # those popped out (corresponding to the chemformula preamble)), as the
317
319
# baseline (the "down" count is necessary to handle xcolor).
318
- downs = 0
320
+ down_stack = [ 0 ]
319
321
self ._baseline_v = None
320
322
while True :
321
323
byte = self .file .read (1 )[0 ]
322
324
self ._dtable [byte ](self , byte )
323
- downs += self ._dtable [byte ].__name__ == "_down"
325
+ name = self ._dtable [byte ].__name__
326
+ if name == "_push" :
327
+ down_stack .append (down_stack [- 1 ])
328
+ elif name == "_pop" :
329
+ down_stack .pop ()
330
+ elif name == "_down" :
331
+ down_stack [- 1 ] += 1
324
332
if (self ._baseline_v is None
325
333
and len (getattr (self , "stack" , [])) == 3
326
- and downs >= 4 ):
334
+ and down_stack [ - 1 ] >= 4 ):
327
335
self ._baseline_v = self .v
328
336
if byte == 140 : # end of page
329
337
return True
0 commit comments