Problem description
I am trying to create an environment that produces boxed paragraphs with different styles.
So I tried to implement some "if"-"elif"-"else" blocks, that will compare the arguments passed to the environment to some given keywords to decide which style will be applied to a paragraph.
Unfortunately, implementing such an idea was far from being as simple as it sounds, since all the methods I tried (here), in order to compare an argument with a string did not give correct results.
MWE
Here is what I have tried (I got my inspiration from here):
\documentclass{article}
\usepackage{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{ifthen}
%#################################
\newtcolorbox{mybox}[2][]{colback=black!5!white,colframe=black!45!white,fonttitle=\bfseries,enhanced,breakable,attach boxed title to top left={yshift*=-\tcboxedtitleheight/2},title={#2}}
%#################################
\makeatletter
\newcommand*\BEGININGcommands{}
\newcommand*\ENDINGcommands{}
\newenvironment{myENV}[1][]
{%
\ifthenelse{\equal{#1}{keyword}}
{
% if '#1' == 'keyword' then apply the 'mybox' style to the selected paragraph
\textcolor{green!35!white}{
\textbf{Seeing this means that:} \fbox{#1} and \fbox{keyword} represent the same string, which means that the content will be formatted by surrounding it with \textbf{mybox}.}\par\vspace{1em}
\def\BEGININGcommands{\begin{mybox}[#1]}
\def\ENDINGcommands{\end{mybox}}
}
{
% else dont apply anything
\textcolor{red!35!white}{\textbf{Seeing this means that:} \fbox{#1} is not the same as \fbox{keyword}, which means that no formating will be applied.}\par\vspace{1em}
\def\BEGININGcommands{}
\def\ENDINGcommands{}
}
\BEGININGcommands
}
{%
\ENDINGcommands%
}
\makeatother
%#################################
\begin{document}
\begin{myENV}{keywordA}
This paragraph \textbf{should be formatted} as the \textbf{keywordA} is \textbf{specified}.
\end{myENV}
\par\vspace{2em}\noindent\rule{\textwidth}{1pt}\vspace{2em}
\begin{myENV}{keywordB}
This paragraph \textbf{should not be formatted} as the \textbf{keywordA} is \textbf{not specified}.
\end{myENV}
\end{document}




\newenvironment{myENV}[1][]definedmyENVwith an optional argument so\begin{myENV}[keyword]not\begin{myENV}{keyword}` – David Carlisle Nov 10 '22 at 00:55\def\BEGININGcommands{\begin{myENV}[#1]}is programming an infinite loop if#1iskeyword– David Carlisle Nov 10 '22 at 00:58myENVformat its contents depending on what you supply as the first argument? That doesn't seem to be the case in the example code, since the argument (keyword) is not used really. – Werner Nov 10 '22 at 01:22\def\BEGININGcommands{\begin{myENV}[#1]}will produce an infinite loop of tests, I rather intended to write\def\BEGININGcommands{\begin{mybox}[#1]}– Mycroft_47 Nov 10 '22 at 13:23tcolorboxthat I calledmybox– Mycroft_47 Nov 10 '22 at 13:33