In equation environment, we can add color and background color to symbols

  • color: \$Y = {\color{red}{5}}x\$
  • background color: \$Y = \colorbox{red}{5}x\$

Note: Adding color needs the outermost pair of curly brackets, but adding background color doesn’t need.