7

I am using https://www.codecogs.com/latex/eqneditor.php

And added my latex as follows:

 \begin{equation}
 SSIM(x,y)=\frac{{\left ( 2 \mu_x\mu_y+ C_1 \right )+ \left (2 \sigma _x_y+C_2\right)}} 
{\left(\mu_x^2+\mu_y^2+C_1)(\sigma_x^2+\sigma_y^2+C_2\right)}
  \label{eq:SSMI}
\end{equation}

I expected the following formula but instead of I got the error:!Double subscript. ...y+C_1\right)+ ...

enter image description here

2 Answers2

9

Double subscripts are not allowed by TeX, you should replace \sigma_x_y by \sigma_{xy}.

Also, it is preferable to use a specific operator name for such a function.

Edit: And as David Carlisle pointed out, the \left and \right commands are of no use here. It can only add unwanted additional spacing.

You can try something like this:

\documentclass[12pt]{article}
%
\usepackage{mathtools}
\DeclareMathOperator{\SSIM}{SSIM}
\begin{document}
\begin{equation}
  \SSIM(x,y) = \frac{(2\mu_x\mu_y + C_1) + (2 \sigma _{xy} + C_2)} 
    {(\mu_x^2 + \mu_y^2+C_1) (\sigma_x^2 + \sigma_y^2+C_2)}
  \label{eq:SSMI}
\end{equation}
\end{document}

enter image description here

Franck Pastor
  • 18,756
3

To achieve the desired output, simply replace \sigma _x_y by \sigma _{xy}.

leandriis
  • 62,593
  • Please make your answer self-contained, see minimal working example (MWE). – Henri Menke Dec 09 '17 at 21:40
  • I am thankfull to all. I try to rewrite with \DeclareMathOperator it didnt work :( What is the purpose of using it? For example after declared the formula may I call it just writing SSMI etc? – user8151324 Dec 09 '17 at 22:01
  • Errors: Can be used only in preamble.... undefined control sequence declaremath and SSIM – user8151324 Dec 09 '17 at 22:09
  • @user8151324 You have to load the amsmath package or its extension mathtools, as I did, to use the DeclareMathOperator command. It is a typographical convention that math operators should be typesetted in roman type, like the main text, hence this command. See the amsmath documentation for more information. – Franck Pastor Dec 09 '17 at 22:12
  • I have all: \usepackage{float} \usepackage{amsmath} \usepackage{mathtools} \usepackage{caption} \usepackage{subcaption} \usepackage{placeins} \usepackage{epstopdf} \usepackage{multirow} – user8151324 Dec 09 '17 at 22:13
  • Loading amsmath should be enough for this. Since my piece of code works perfectly with either amsmath or mathtools loaded in the preamble, it seems that your problem comes from somewhere else. Maybe you should start by trying to reduce the number of packages to the strict minimum. – Franck Pastor Dec 09 '17 at 22:18