I want to create an environment that receives an argument and an optional argument in such a way that the first argument will be a title and the two optional argument will decide whether the title should be justified to the left or centered plus if the title wants to be added to the ToC.
I have this code with one optional argument (thanks to @egreg), so I like to modify for the case of two optional argument:
\makeatletter
\newenvironment{something}[2][c]
{\begin{\csname #1@somethingtitle\endcsname}
\bfseries #2
\end{\csname #1@somethingtitle\endcsname}}
{\par\addvspace{\topsep}}
\newcommand\l@somethingtitle{flushleft}
\newcommand\c@somethingtitle{center}
\makeatother
Thanks in advance.
I followed the suggestion of Teepeemm by adding the following
\if\detokenize{C}\detokenize{#1}\relax
\addcontentsline{toc}{chapter}{#2}
\fi
\if\detokenize{L}\detokenize{#1}\relax
\addcontentsline{toc}{chapter}{#2}
\fi

\NewDocumentEnvironmentcommand fromxparse. – Bernard Feb 21 '19 at 22:43\@ifnextchar[, if you want to show off. – John Kormylo Feb 21 '19 at 23:01xkeyvalthat can take multiple key-values in the optional argument. – Werner Feb 21 '19 at 23:05\begin{something}[align=center,format=\bfseries]{title}(say) – Werner Feb 21 '19 at 23:41articledocument class is just a selection of macros that set up the document profile. Packages extend it to be able to make all kinds of nifty things, like managing key-value optional argument... – Werner Feb 22 '19 at 00:26