# multiline in subscript

what is the correct way to write the following?

\begin{align}
&\prod_{\substack{p \leq x \\  $p$ ~{}odd }} p
\end{align}


Any help would be appreciated .Thanks in advance.

• please always post a test document not a fragment but remove the $ you are already in math mode – David Carlisle May 28 at 19:13 • note you can mark up the code block by highlighting and using the {} button (I did it for you this time) – David Carlisle May 28 at 19:14 • Something like \prod_{\substack{p \leq x \\ p \text{ odd} }} should do. – user194703 May 28 at 19:15 • @Schrödinger'scat remarkably similar to my answer:-) – David Carlisle May 28 at 19:18 • @DavidCarlisle It is odd, isn't it? ;-) – user194703 May 28 at 19:24 ## 2 Answers you are in math mode so you don't want $ around p, conversely you want to get out of math for odd

\documentclass{article}

\usepackage{amsmath}

\begin{document}

$\prod_{\substack{p \leq x \\ p \textrm{ odd}}}$
\end{document}

• many Thanks,sir. – math is fun May 28 at 19:23
• I wasn't complaining (and did not plan to write an answer anyway). This was more like a plan B if the question gets closed so that the OP has something that works. (But since we are chatting: will \textrm be a good choice if the OP has \renewcommand*\familydefault{\sfdefault} in the document?) – user194703 May 28 at 19:45
• @Schrödinger'scat I wondered about that. If the "$p$ is odd" is just a sentence in english that;s positioned in the math it should pick up the surrounding text font (I'd claim) but if it's a defined term, the identifier of a particular subset of the natural numbers, then it's a math identifier and should be in a fixed \mathrm{odd} if it's a bit of both, hard to choose... – David Carlisle May 28 at 19:49
• So your answer is wrong and you need \documentclass{article} \usepackage{amsmath} \usepackage{dsfont} \begin{document} $\prod_{\substack{p \leq x \\ p \in\mathds{Z}\setminus2\mathds{Z}}}$ \end{document}? ;-) – user194703 May 28 at 19:55
• @Schrödinger'scat my answers are never wrong, you must be confusing me with egreg – David Carlisle May 28 at 19:57

The best answer for sure is that of very nice user @David Carlisle. I would just like to add the ability to create a specific macro that generates the same result. Obviously it is more uncomfortable than the usual command \substack: just I have put an idea.

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools}
\usepackage{amssymb}
\newcommand{\produ}[2]{\underset{\underset{\scriptstyle #2}{p\leq x}}{#1}}

\begin{document}
$\produ{\prod}{p \text{ odd }}$
\end{document}