Numbering examples independently

newtheoremnumbering

I created a theorem command defining example sections, definitions, etc. the same way like so

\newtheorem{example}[thm]{\protect\examplename}

Of course, the numbering of this is consistent with the numbering of every other theorem command. For example, currently I would have something like this for the first section of the paper

Definition 1.

Definition 2.

Example 3.

But what I want is for the examples to be numbered independently by its section number and subsection (or even just by its section. As long as the numbering starts over from 1), like this

Definition 1.

Definition 2.

Example 1.1

Best Answer

Assuming you're using amsthm or compatible package (for some reason you didn't say), you can do this—

For Example 1.1 (by section number):

\newtheorem{example}{\protect\examplename}[section]

or for Example 1.1.1 (by subsection number):

\newtheorem{example}{\protect\examplename}[subsection]

Definitely don't add [thm] in the middle if you don't want the numbering to be shared with theorems. That's what that does.