|
32 | 32 | } |
33 | 33 |
|
34 | 34 |
|
| 35 | +RE_COMMENT = re.compile(r'(?<!\\)%') # % character but not \% |
| 36 | + |
35 | 37 | def add_dictval_to_list(adict, key, alist): |
36 | 38 | ''' |
37 | 39 | Add a value from a dictionary to a list |
@@ -80,13 +82,21 @@ class LatexSplitter(core.BaseSplitter): |
80 | 82 | ''' |
81 | 83 | delimiter = '&' |
82 | 84 |
|
| 85 | + def __call__(self, lines): |
| 86 | + last_line = RE_COMMENT.split(lines[-1])[0].strip() |
| 87 | + if not last_line.endswith(r'\\'): |
| 88 | + print(last_line) |
| 89 | + lines[-1] = last_line + r'\\' |
| 90 | + |
| 91 | + return super(LatexSplitter, self).__call__(lines) |
| 92 | + |
83 | 93 | def process_line(self, line): |
84 | 94 | """Remove whitespace at the beginning or end of line. Also remove |
85 | 95 | \\ at end of line""" |
86 | | - line = line.split('%')[0] |
| 96 | + line = RE_COMMENT.split(line)[0] |
87 | 97 | line = line.strip() |
88 | | - if line[-2:] == r'\\': |
89 | | - line = line.strip(r'\\') |
| 98 | + if line.endswith(r'\\'): |
| 99 | + line = line.rstrip(r'\\') |
90 | 100 | else: |
91 | 101 | raise core.InconsistentTableError(r'Lines in LaTeX table have to end with \\') |
92 | 102 | return line |
@@ -314,6 +324,9 @@ class AASTexHeaderSplitter(LatexSplitter): |
314 | 324 |
|
315 | 325 | \tablehead{\colhead{col1} & ... & \colhead{coln}} |
316 | 326 | ''' |
| 327 | + def __call__(self, lines): |
| 328 | + return super(LatexSplitter, self).__call__(lines) |
| 329 | + |
317 | 330 | def process_line(self, line): |
318 | 331 | """extract column names from tablehead |
319 | 332 | """ |
|
0 commit comments