Incomplete manual merge here: use t = 'translate(' + str( xoff ) + ',' + str( pitch_radius ) + ')'
here, and you get a perfectly meshing rack below the gear.