# Text formatting relative to environment (theorems)

I've gotten the code below from another post and, I'm not sure whether or not this is possible but, I would like to define an alternate \myemph command whose effect would depend on the theorem environment in which it is embedded.

\documentclass[a4paper]{article}
\usepackage{amsthm,eso-pic,thmtools,framed}
\usepackage{lipsum}

\definecolor{localblue}{RGB}{55, 115, 180}
\definecolor{localgreen}{RGB}{80, 140, 30}

\newcommand{\myemph}[1]{\emph{\textcolor{localblue}{#1}}}
\newcommand{\miemph}[1]{\emph{\textcolor{localgreen}{#1}}}

\colorlet{rulecolordefn}{localblue}
\newenvironment{leftbardefn}{%
\def\FrameCommand{{\color{rulecolordefn}\vrule width 3pt} \hspace{10pt}}%
{\endMakeFramed}
\declaretheoremstyle[
notefont=\sffamily\bfseries,%
notebraces={}{},%
bodyfont=,%
postfoothook=\end{leftbardefn},%
]{customDefinition}
\declaretheorem[
title=Definition,style=customDefinition, numberwithin=section
]{defn}

\colorlet{rulecolorthm}{localgreen}
\newenvironment{leftbarthm}{%
\def\FrameCommand{{\color{rulecolorthm}\vrule width 3pt} \hspace{10pt}}%
{\endMakeFramed}
\declaretheoremstyle[
notefont=\sffamily\bfseries,%
notebraces={}{},%
bodyfont=,%
postfoothook=\end{leftbarthm},%
]{customTheorem}
\declaretheorem[
title=Theorem,style=customTheorem, numberwithin=section, sibling=defn
]{thrm}

\begin{document}
\lipsum[2]

\begin{defn}[object]
Such-and-such is said to be an \myemph{object} when so-and-so is verified.
\end{defn}
\lipsum[2]
\begin{thrm}[of the day]
If such-and-such \miemph{conditions} are met, then we're happy.
\end{thrm}
\lipsum[2]

\end{document}


I've got a series of different 'theorem' styles with specific colors, and I would for my command to color the text relative to the one defined in the style, e.g. I'd like it to render

with the previous code. Is there anyway to accomplish this without too many headaches?

EDIT: as required in the comments, I modified the example to provide a more detailed one. It renders:

So my question really is: is there a way to merge the \myemph and \miemph commands into one (there are of course more environments than those two: propositions, corollaries...)?

• Not very clear to me. Should the theorem note (‘object’) be placed in the right margin? – Bernard Jun 11 at 18:56
• No, that is not what I want to modify (in part because some theorems have names, and in French this might render "Théorème 1.4: de la valeur intermédiaire" for instance, which was what I meant to do - and I'd like to keep the consistency arcoss the various styles); I was refering to the 'object' in italics in the body of the text rather - the word that I would like to be emphasized within the text itself. Plus I mean to have the entirety of the entry to the right of the sidebar. – Mogu Jun 11 at 20:23
• You may stick to a fixed color name in \myemph, but let that color to different theme colors in theorem styles, by using \colorlet from xcolor package. An example containing two or more such theorem styles would be helpful. – muzimuzhi Z Jun 12 at 15:47

The following example demonstrates what I suggest in this comment:

• All theorem-like environments shares a single theorem style, called thm@custom.
• This theorem style makes use of an environment thm@leftbar.
• In the thm@custom style and thm@leftbar environment, a theme color thm@theme is used, instead of specific colors like localblue and localgreen.
• At the begin of each kind of theorem-like environments, the color thm@theme is let to the corresponding specific color. This is done by \AtBeginEnvironment.

Moreover, \DeclareEmphSequence is used to configure the style of \emph, so you can directly use \emph in theorem-like envs and get the text in desired theme color.

\documentclass[a4paper]{article}
\usepackage{amsthm,eso-pic,thmtools,framed}
\usepackage{lipsum}

\definecolor{localblue}{RGB}{55, 115, 180}
\definecolor{localgreen}{RGB}{80, 140, 30}

\newenvironment{thm@leftbar}{%
\def\FrameCommand{{\color{thm@theme}\vrule width 3pt} \hspace{10pt}}%
{\endMakeFramed}
\declaretheoremstyle[
notefont=\sffamily\bfseries,%
notebraces={}{},%
bodyfont=,%
postfoothook=\end{thm@leftbar},%
]{thm@custom}
\declaretheorem[
title=Definition,style=thm@custom, numberwithin=section
]{defn}
\declaretheorem[
title=Theorem,style=thm@custom, numberwithin=section, sibling=defn
]{thrm}

% since latex2e 2020-10-01
% for older latex2e, load etoolbox package
\AtBeginEnvironment{defn}{\colorlet{thm@theme}{localblue}\thmemph}
\AtBeginEnvironment{thrm}{\colorlet{thm@theme}{localgreen}\thmemph}

% since latex2e 2020-02-02
\newcommand\thmemph{%
\DeclareEmphSequence{\itshape\color{thm@theme}}}

\begin{document}
\lipsum[2]

\begin{defn}[object]
Such-and-such is said to be an \emph{object} when so-and-so is verified.
\end{defn}
\lipsum[2]
\begin{thrm}[of the day]
If such-and-such \emph{conditions} are met, then we're happy.
\end{thrm}
\lipsum[2]

test \verb|\emph| \emph{outside thm-like envs}
\end{document}


• Yes, okay your question flew right above my head. But even if didn't, I would have been nowhere near producing anything like this.Thanks, that works very nicely! – Mogu Jun 13 at 16:51