Barred indices equation

How to make the below equations with bars being precisely above selected indices and not crossing other unbarred indices?

  $$\frac{1}{\alpha'}\int_\Sigma d^2x[g_{\mu\nu}\partial\phi^\mu\bar{\partial}\phi^\nu + ig_{i\bar{j}}\eta^\bar{j}(D_z\rho^i_{\bar{z}} + D_\bar{z}\rho^i_z) + i\theta_i(D_\bar{z}\rho^i_z - D_z\rho^i_\bar{z}) + R_{i\bar{i}j\bar{j}}\rho^i_z\rho^j_\bar{z}\eta^\bar{i}\theta_kg^{k\bar{j}}]$$


• As said before: please don't post just code fragments. Always make a MWE Commented Oct 31, 2023 at 16:31
• The code you post raises errors but doesn't produce the output you show. Anyway, you've discovered that omitting braces leads to errors: you've got a lot of things like \eta^\bar{j} which should be \eta^{\bar{j}}. Commented Oct 31, 2023 at 16:32

Never disregard errors raised during the LaTeX run.

Subscripts and superscripts should always be braced. In some cases (a single letter or digit) the braces can be omitted, but

\eta^\bar{j}


is definitely a syntax error, because TeX will take just \bar as the superscript.

You should also split such a long expression and make the brackets a little more prominent.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{multline}
\frac{1}{\alpha'}\int_{\Sigma} d^{2}x\,\bigl[
g_{\mu\nu}\partial\phi^{\mu}\bar{\partial}\phi^{\nu}
+ ig_{i\bar{j}}\eta^{\bar{j}}(D_z\rho^{i}_{\bar{z}} + D_{\bar{z}}\rho^{i}_{z})
\\
+ i\theta_{i}(D_{\bar{z}}\rho^{i}_{z} - D_z\rho^{i}_{\bar{z}})
+ R_{i\bar{i}j\bar{j}}\rho^{i}_{z}\rho^{j}_{\bar{z}}\eta^{\bar{i}}\theta_kg^{k\bar{j}}
\bigr]
\end{multline}

\end{document}