I have a number of environments that have very similar definitions, one example of which is below.
\newcounter{definition}
\newenvironment{definition}[1][]{%
\refstepcounter{definition}
\global\mdfdefinestyle{definition}{linecolor=grey60, linewidth=3pt, skipabove=2\parskip, skipbelow=0.4\parskip, topline=false, rightline=false, bottomline=false}
\ifstrempty{#1}%
{\begin{mdframed}[style=definition]
{\bfseries{Definition~\thedefinition}\newline}
\relax}
{\begin{mdframed}[style=definition]
{\bfseries{Definition~\thedefinition}} \,(#1)\newline\relax
}}{\end{mdframed}}
\renewcommand\thedefinition{\arabic{chapter}.\arabic{section}.\arabic{definition}}
The other environments are very similar to this but with theorem
in place of each definition
, for example. How might one define a 'skeleton' environment that takes the environment name and correctly defines a new environment to correspond with that (including changing \thedefinition
to \thetheorem
and Definition~
to Theorem~
), but without relying on many other packages (I'm trying to learn how to write all my macros myself so that I don't have to rely too heavily on packages)?
In addition to this, is it a trivial extension to set it up so that I may define \linewidth
and each of the box lines as arguments to this skeleton environment, so that the theorem environment has a larger left line and includes a right line too?
Of course, with only a handful of environments I could just define each of them separately as I have done already, but I would be very interested in seeing how this code would look in case there are a great deal of environments that can be altered globally at once. I am sure that this is a feature in the amsthm
package for their default theorem style, but I don't know where to go to check the code that they implement (if someone could point me in the correct direction for that also, I would be very grateful!).
\global\mdfdefinestyle
can't possibly be doing anything good, shouldn't that style definition just be done once, in the preamble not every time (and definitely never prefixed with\global
)\global
prefix is admittedly just something I had copied from someone else --- I had considered removing it since I was unsure how relevant it is, but it hasn't yielded any errors (yet) so I kept it in. If you don't think it needs to be there, I'll get rid of it though!\mdfdefinestyle{definition}
... so why are you including it in every use of that environment. It should be like the definition you have of\thedefininition
just done once.\global
never makes an error applies to the first non expandable token in the expansion of\mdfdefinestyle
and then does nothing if that isn't a primitive assignment and makes that assignment global if it is. So whatever it does it does by accident:-)