Improve build script for amsmath