Created
February 25, 2019 13:32
-
-
Save comzyh/f4bec21fa293c171eba568b2434d02b5 to your computer and use it in GitHub Desktop.
[Latex] Highlight maximum value in line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
def main(): | |
for line in sys.stdin.readlines(): | |
line = re.sub(r'\\textbf\{(?P<value>(\d+)?\.\d+)\}', lambda g: g.group('value'), line) | |
maxval = 0.0 | |
for v in re.finditer(r'(?P<value>(\d+)?\.\d+)', line): | |
maxval = max(maxval, float(v.group('value'))) | |
def rep_func(group): | |
# print(float(group.group('value')) == maxval) | |
if float(group.group('value')) == maxval: | |
return '\\textbf{{{}}}'.format(group.group('value')) | |
return group.group('value') | |
line = re.sub(r'(?P<value>(\d+)?\.\d+)', rep_func, line) | |
sys.stdout.write(line) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment