Skip to content

Instantly share code, notes, and snippets.

@comzyh
Created February 25, 2019 13:32
Show Gist options
  • Save comzyh/f4bec21fa293c171eba568b2434d02b5 to your computer and use it in GitHub Desktop.
Save comzyh/f4bec21fa293c171eba568b2434d02b5 to your computer and use it in GitHub Desktop.
[Latex] Highlight maximum value in line
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