2

Is it possible to create an environment with required arguments that would represent some changes in the environment using only xparse package without environ?

To be more specific I'd like to make an environment for an integral substitution that would receive a required argument: line, brace or wave. Or at least l, b, w if it's not possible with words.

\begin{subs}{MY ARGUMENT}
...
\end{subs}

Here are the examples how it should work:

1․ uses | at both sides

\begin{equation}
\int =
\begin{subs}{l}
...
\end{subs}
\end{equation}

line

2․ uses [ and ]

\begin{equation}
\int =
\begin{subs}{b}
...
\end{subs}
\end{equation}

brace

3․ uses \lwavy and \rwavy

\begin{equation}
\int =
\begin{subs}{w}
...
\end{subs}
\end{equation}

wave

Also it would be really nice if it used wavy lines when you don't specify anything

\begin{subs}
...
\end{subs}

Just for reference that's how it's hardcoded right now:

\;\left \lwavy \:\begin{aligned}
{
...
}
\end{aligned}\;\right \rwavy \;

P.S never mind that random stuff on screenshots, it's just for the demonstration.

1 Answer 1

2

You can do it without absorbing the contents.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

% from https://tex.stackexchange.com/a/347545/4427
\DeclareFontFamily{OMX}{MnSymbolE}{}
\DeclareFontShape{OMX}{MnSymbolE}{m}{n}{
    <-6>  MnSymbolE5
   <6-7>  MnSymbolE6
   <7-8>  MnSymbolE7
   <8-9>  MnSymbolE8
   <9-10> MnSymbolE9
  <10-12> MnSymbolE10
  <12->   MnSymbolE12}{}
\DeclareFontShape{OMX}{MnSymbolE}{b}{n}{
    <-6>  MnSymbolE-Bold5
   <6-7>  MnSymbolE-Bold6
   <7-8>  MnSymbolE-Bold7
   <8-9>  MnSymbolE-Bold8
   <9-10> MnSymbolE-Bold9
  <10-12> MnSymbolE-Bold10
  <12->   MnSymbolE-Bold12}{}

\DeclareSymbolFont{mnlargesymbols}{OMX}{MnSymbolE}{m}{n}
\SetSymbolFont{largesymbols}{bold}{OMX}{MnSymbolE}{b}{n}

\DeclareMathDelimiter{\lwavy}{\mathopen}{mnlargesymbols}{'136}{mnlargesymbols}{'136}
\DeclareMathDelimiter{\rwavy}{\mathclose}{mnlargesymbols}{'136}{mnlargesymbols}{'136}

\ExplSyntaxOn
\NewDocumentEnvironment{subs}{O{wave}}
 {
  \left
  \str_case:nn { #1 }
   {
    {line}{|}
    {brack}{[}
    {wave}{\lwavy}
   }
  \begin{aligned}
 }
 {
  \end{aligned}
  \right
  \str_case:nn { #1 }
   {
    {line}{|}
    {brack}{]}
    {wave}{\rwavy}
   }
 }
\ExplSyntaxOff

\begin{document}

\[
\int=\begin{subs}
& y=5+x && dt=dx \\
& dy=dx && \text{I love unicorns} \\
& \text{My text here} && z=\sqrt{y-5x^2}
\end{subs}
\]

\[
\int=\begin{subs}[line]
& y=5+x && dt=dx \\
& dy=dx && \text{I love unicorns} \\
& \text{My text here} && z=\sqrt{y-5x^2}
\end{subs}
\]

\end{document}

enter image description here

2
  • Thank you so much! Exactly what I wanted. The only thing -- I replaced O with G to have this argument in curly brackets.
    – antshar
    Apr 19, 2020 at 18:03
  • @antshar Don’t. Optional arguments go in brackets. You gain nothing by twisting the syntax.
    – egreg
    Apr 19, 2020 at 18:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .