Theory and practice in optical pH sensing