import re, sys
lines = sys.stdin.readlines()
width = height = 0
# First pass: compute |width| and |height|.
for line in lines:
m = re.match(r'\\page (\d*) \[([0-9.]*) ([0-9.]*) ([0-9.]*) ([0-9.]*)\](.*)', line, re.DOTALL)
if m:
page, xmin, ymin, xmax, ymax, rest = m.groups()
width = max(width, float(xmax) - float(xmin))
height = max(height, float(ymax) - float(ymin))
# Second pass: change bounding boxes to have width |width| and height |height|.
for line in lines:
m = re.match(r'\\page (\d*) \[([0-9.]*) ([0-9.]*) ([0-9.]*) ([0-9.]*)\](.*)', line, re.DOTALL)
if m:
page, xmin, ymin, xmax, ymax, rest = m.groups()
xmin = float(xmin)
ymin = float(ymin)
xmax = float(xmax)
ymax = float(ymax)
# We want |xmin| and |xmax| such that their difference is |width|
addx = (width - (xmax - xmin)) / 2.0
xmin -= addx
xmax += addx
# We want |ymin| and |ymax| such that their difference is |height|
addy = (height - (ymax - ymin)) / 2.0
ymin -= addy
ymax += addy
sys.stdout.write(r'\page %s [%s %s %s %s]%s' % (page, xmin, ymin, xmax, ymax, rest))
else:
sys.stdout.write(line)