Superscripts and Subscripts with more than 1 letter

I`m trying to input the following formula in latex: So far I came up with:

$Pr(Classe_i | Objeto) * Pr(Objeto) * IOU^{truth \_pred}= Pr(Classe_i)* IOU^{truth} \_{pred}$

But truth and pred end up side by side and not on a stack. How can I fix it?

• What is this supposed to represent? – Werner Mar 21 '18 at 21:11
• You should definitely be writing _, not \_, to create subscripts in math mode. – Mico Mar 22 '18 at 0:52

Write

\mathrm{IOU}^{\mathrm{truth}}_{\mathrm{pred}}

The \mathrm makes the letters upright.

• It did work! is there also some trick to make it all be outputed in a single line? – vfbsilva Mar 21 '18 at 21:14
• If you want to have it inline but not broken over lines, you can put it in a box to accomplish that (just search on this site to find an example for this). Since this equation is rather long, I would recommend typesetting it in display mode (e.g. with $and$ around it instead of $and$. However I would recommend you read a beginner's guide to LaTeX and typesetting math in it to learn the basics. – schtandard Mar 21 '18 at 21:36
• You'll have issues when using spaces together with \mathrm. – Werner Mar 21 '18 at 22:31
• @Werner, depending on what you want to achieve, those "issues" can be regarded a feature. In indices I usually still want math spacing rules to apply, even when I want to use an upright font to indicate that the index denotes a word (like i for initial) rather than a variable (that may be called i), thus \mathrm is almost always the right choice for me. You are of course right that one should be aware that this command does not switch to text mode. – schtandard Mar 21 '18 at 23:31

If what you're typing is text in math mode, use \textup - it ensures its contents is dislpayed as upright text, even if the prevailing font is not upright, like italics (the case within some theorem environments). For a super-/sub-script, use ^ and _; this will ensure placement high/low to the right of an object: \documentclass{article}

\usepackage{mathtools}

\DeclarePairedDelimiter{\Probability}{(}{)}
\newcommand{\Prob}{\Pr\Probability}

\begin{document}

$\Prob{\textup{Class}_i \mid \textup{Object}} \times \Prob{\text{Object}} \times \textup{IOU}^{\textup{truth}}_{\textup{pred}} = \Prob{\textup{Class}_i} \times \textup{IOU}^{\textup{truth}}_{\textup{pred}}$

\end{document}
• Never a good advise to use \text in this context. If the op uses this in an italic context the output would be italic, which is obviously not correct here. Sadly there is a lot of users who do not know when to use \text and when not to. I would probably have used \textup or even \textnormal. Yes this solution works in this case, but does not in all cases – daleif Mar 21 '18 at 21:38
• @daleif: Oh my, I'm switching that to \textup, from now on... – Werner Mar 21 '18 at 22:28
• This is a clear case for \mathrm. – egreg Mar 22 '18 at 7:31