In this answer, I was provided with the following code that solves my original problem.
\ExplSyntaxOn
\NewDocumentEnvironment{withalignment}{m}
{
\begin{\vincent_alignment:n { #1 }}
}
{
\end{\vincent_alignment:n { #1 }}
}
\cs_new:Nn \vincent_alignment:n
{
\str_case:nn { #1 }
{
{c}{center}
{center}{center}
{l}{flushleft}
{left}{flushleft}
{r}{flushright}
{right}{flushright}
}
}
\ExplSyntaxOff
that can be used this way:
\begin{withalignment}{left}
\lipsum[1][1-4]
\end{withalignment}
\begin{withalignment}{center}
\lipsum[1][1-4]
\end{withalignment}
The problem, however is when I provide the alignment through a macro/command:
\newcommand{\myalignment}{center}
\begin{withalignment}{\myalignment}
\lipsum[1][1-4]
\end{withalignment}
It does not seem to work. How to fully expand the argument before processing it so that it works?
\str_case:en
, or generate a e-variant for\vincent_alignment:n
.str_case:nn
withstr_case:en
.