Text subscript within math environment ()

How can I make a subscript of 'p' in fp(x) = ...

I have this code right now, but I think there's a better way:

$f\textsc{$p$}(x)=x^3-x^2+px+1$
• \textsc is nothing to do with subscripts: it selects caps and small caps font. – David Carlisle Nov 26 '14 at 23:03

Subscripts in math mode are initiated using _, as in the following example: \documentclass{article}
\begin{document}
$f_p(x) = x^3 - x^2 + px + 1$
\end{document}

For sub-scripting multiple items, brace them using _{...}. If you want to write text in the subscript, use amsmath's \text for the prevailing text font, or \mathrm for a forced upright font: \documentclass{article}
\usepackage{amsmath}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}
This is a theorem
\begin{align*}
f_{\text{prob}}(x)   &= x^3 - x^2 + px + 1 \\
f_{\mathrm{prob}}(x) &= x^3 - x^2 + px + 1
\end{align*}
\end{theorem}
Some regular text.
\begin{align*}
f_{\text{prob}}(x)   &= x^3 - x^2 + px + 1 \\
f_{\mathrm{prob}}(x) &= x^3 - x^2 + px + 1
\end{align*}
\end{document}
• In this case I would use \mathrm. With \text the font will be the one current outside the formula, which may not be upright. – egreg Nov 26 '14 at 23:08
• I've never known, why \mathrm (or \mathup) instead of \textrm (or \textup)? – Manuel Nov 27 '14 at 1:39
• @Manuel use \mathrm if you want the content set as math and \textrm if you want the content set as text. Compare \mathrm{hello world 1 - 1} and \textrm{hello world 1 - 1} – David Carlisle Nov 27 '14 at 9:32