Skip to content

Instantly share code, notes, and snippets.

@mp4096
Created February 25, 2016 20:04
Show Gist options
  • Save mp4096/74342a4ff5e63ba2b63e to your computer and use it in GitHub Desktop.
Save mp4096/74342a4ff5e63ba2b63e to your computer and use it in GitHub Desktop.
Rescale TikZ coordinates
import re
def main(filename_in, filename_out):
re_coord_pattern = "\((?P<x>[-.\d]*),(?P<y>[-.\d]*)\)"
re_coord = re.compile(re_coord_pattern)
with open(filename_in, "r") as f_in, open(filename_out, "w") as f_out:
for line in f_in:
line_processed = line.strip()
line_processed = re_coord.sub(prettify_xy, line_processed)
print >> f_out, line_processed
def prettify_xy(m):
x = float(m.group("x"))
y = float(m.group("y"))
x /= +1000
y /= -1000
return "(%+07.4f, %+07.4f)" % (x, y)
# Call main function
main("file_in.tex", "file_out.tex")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment