I don't think you should force users of your package to have the numbering of definitions independent on theorems and friends.
There is no reason why an author should be forced to a style such as
Lemma 1
Theorem 1
Theorem 2
Definition 1
Lemma 2
Theorem 3
(maybe with section prefix, but that's irrelevant) instead of the more common and friendly
Lemma 1
Theorem 2
Theorem 3
Definition 4
Lemma 5
Theorem 6
(again with a possible prefix). I hate reading such a cross reference as
see chapter II, part II, paragraph VI
or
chapter V, part III, paragraph II, 2, theorem 2
These are from an actual book, which uses “part” instead of section, “paragraph” for subsection and doesn't name subsubsections. There is no clue whatsoever in the page headers about how to find the referenced theorem.
In your proposed “empty” style, the reader will have no clue as to whether Lemma 2 precedes or follows Theorem 1.
Anyway, if you insist on it (maybe because of strict faculty regulations), the trick is to define your own facility.
\DeclareOption{empty}{\let\package@thmprefix=F}
\DeclareOption{section}{\let\package@thmprefix=T\def\package@thmlevel{section}}
\DeclareOption{chapter}{\let\package@thmprefix=T\def\package@thmlevel{chapter}}
\DeclareOption{empty}{\let\package@thmprefix=F}
\DeclareOption{section}{\let\package@thmprefix=T\def\package@thmlevel{section}}
\DeclareOption{chapter}{\let\package@thmprefix=T\def\package@thmlevel{chapter}}
\ExecuteOptions{empty}
\ProcessOptions\relax
\RequirePackage{amsthm}
\def\package@newtheorem#1#2{%
\if\package@thmprefix F%
\newtheorem{#1}{#2}%
\else
\newtheorem{#1}{#2}[\package@thmlevel]
\fi
}
\package@newtheorem{lemma}{Lemma}
\package@newtheorem{theorem}{Theorem}
\theoremstyle{definition}
\package@newtheorem{definition}{Definition}
Here's the test file
\documentclass{book}
\usepackage{package}
%\usepackage[section]{package}
%\usepackage[chapter]{package}
\begin{document}
\chapter{Title}
\section{Title}
\begin{lemma}
Text
\end{lemma}
\begin{theorem}
Text
\end{theorem}
\begin{theorem}
Text
\end{theorem}
\section{Title}
\begin{definition}
Text
\end{definition}
\begin{lemma}
Text
\end{lemma}
\begin{theorem}
Text
\end{theorem}
\end{document}
Output with the empty option (default)

Output with the section option

Output with the chapter option

amsthmpackage acceptssectionorchapterin\counter." That's somewhat misleading, as any valid counter variable can be used for "\counter. Do please clarify what you mean by "trying to set an optional counter in the\newtheoremcommand based on some input given to a .sty file". E.g., why does it have to be a .sty file? – Mico May 01 '22 at 23:30sectionandemptythat sets\newtheorem{definition}{Definition}[section]or\newtheorem{definition}{Definition}depending on the chosen input in the main document using it. The point is that I have a bunch of\newtheorem{definition}{Definition}in an.styfile that I'm writing, so I wouldn't like to use a bunch of if's. I would like, then to known whether there's some valid counter in theamsthmpackage such that "\newtheorem{definition}{Definition}["valid counter"]=\newtheorem{definition}{Definition}". – user40276 May 02 '22 at 01:46\newtheorem{definition}{Definition}[]seems to have the same effect of\newtheorem{definition}{Definition}. Still, I don't know how to define a new command\countersuch that\newtheorem{definition}{Definition}[\counter]has the same effect of\newtheorem{definition}{Definition}[]. So I would like to define something like "let\counterbe the empty command". – user40276 May 02 '22 at 01:51\newcounter{xthm}and then\newtheorem{xdefn}{Definition}[xthm]and assign an appropriate value to thexthmcounter. (May work, maybe not, but seems worth trying, since it's known that theequationcounter can be used in this way.) – barbara beeton May 02 '22 at 03:07xthmto something empty? If I just define\newcounter{xthm}and set\newtheorem{definition}{Definition}[xthm]inside the sty file, I get "Definition 0.1 "from\begin{definition}inside the main tex document, whereas I would like "Definition 1" instead. Any ideas? – user40276 May 02 '22 at 04:13xthmcounter really have to be "empty" (or "undefined")? Would it suffice for the value of this counter to be equal to0in order for the typeset representation of thedefinitioncounter to be "1" instead of "0.1"? Please advise. – Mico May 02 '22 at 04:33\setcounter{xthm}{0}in the sty file? If so, in the main tex filebegin{definition}appears later as "Definition 0.1". The 0 in 0.1 fromxthm. I want to erase that. – user40276 May 02 '22 at 05:05