TeX - LaTeX Asked by Mogu on July 13, 2021
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{headcolordefn}{localblue}
colorlet{rulecolordefn}{localblue}
newenvironment{leftbardefn}{%
defFrameCommand{{color{rulecolordefn}vrule width 3pt} hspace{10pt}}%
MakeFramed {advancehsize-width FrameRestore}}%
{endMakeFramed}
declaretheoremstyle[
headfont=sffamilybfseries,%
notefont=sffamilybfseries,%
notebraces={}{},%
headpunct=,%
bodyfont=,%
headformat=color{headcolordefn}NAME~NUMBERhfillNOTEsmallskiplinebreak,%
preheadhook=begin{leftbardefn},
postfoothook=end{leftbardefn},%
]{customDefinition}
declaretheorem[
title=Definition,style=customDefinition, numberwithin=section
]{defn}
colorlet{headcolorthm}{localgreen}
colorlet{rulecolorthm}{localgreen}
newenvironment{leftbarthm}{%
defFrameCommand{{color{rulecolorthm}vrule width 3pt} hspace{10pt}}%
MakeFramed {advancehsize-width FrameRestore}}%
{endMakeFramed}
declaretheoremstyle[
headfont=sffamilybfseries,%
notefont=sffamilybfseries,%
notebraces={}{},%
headpunct=,%
bodyfont=,%
headformat=color{headcolorthm}NAME~NUMBERhfillNOTEsmallskiplinebreak,%
preheadhook=begin{leftbarthm},
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…)?
The following example demonstrates what I suggest in this comment:
thm@custom
.thm@leftbar
.thm@custom
style and thm@leftbar
environment, a theme color thm@theme
is used, instead of specific colors like localblue
and localgreen
.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}{%
defFrameCommand{{color{thm@theme}vrule width 3pt} hspace{10pt}}%
MakeFramed {advancehsize-width FrameRestore}}%
{endMakeFramed}
declaretheoremstyle[
headfont=sffamilybfseries,%
notefont=sffamilybfseries,%
notebraces={}{},%
headpunct=,%
bodyfont=,%
headformat=color{thm@theme}NAME~NUMBERhfillNOTEsmallskiplinebreak,%
preheadhook=begin{thm@leftbar},
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
newcommandthmemph{%
DeclareEmphSequence{itshapecolor{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}
Correct answer by muzimuzhi Z on July 13, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP