3

environment:

\documentclass{beamer}

There is an idea that create a new CS, for example \modela like this:

\modela{enumerate}{#2}

would expand as follow:

\begin{frame}
     \begin{enumerate}
          #2
        \end{enumerate}
\end{frame}

while

\modela{description}{#2}

can be expanded as:

\begin{frame}
     \begin{description}
          #2
        \end{description}
\end{frame}

Any approach to fulfill this command by conditional command instead of the \if command sequence, because of not only two options? Thanks very mcuh!

4
  • Instead of "There is an idea that create a new CS", I assume you mean "I would like to create a new command".
    – Teepeemm
    Commented May 25, 2017 at 17:46
  • \newcommand{\modela}[2]{\begin{frame} \begin{#1}#2\end{#1} \end{frame} } ? Welcome to TeX.SE!
    – Zarko
    Commented May 25, 2017 at 17:47
  • @Zarko Far too simple ;)
    – TeXnician
    Commented May 25, 2017 at 17:48
  • @TeXnician, I prefere simple ... but i didn't test if suggestion not work :)
    – Zarko
    Commented May 25, 2017 at 17:50

2 Answers 2

1

Here's a simple version with kind of control over the input (it will only allow some specific environments instead of passing the environment name directly). You can add more cases (see interface3.pdf, page 39).

beamer doc

\documentclass{beamer}
\usepackage{expl3,xparse}

\ExplSyntaxOn
\tl_new:N \c_enum_tl
\tl_set:Nn \c_enum_tl {enumerate}
\tl_new:N \c_desc_tl
\tl_set:Nn \c_desc_tl {description}
\tl_new:N \l__hezilun_tmp_tl

\NewDocumentCommand{\modela}{m m}{
    \begin{frame}
    \tl_set:Nn \l__hezilun_tmp_tl {#1}
    \tl_case:Nn \l__hezilun_tmp_tl {
        \c_enum_tl {\begin{enumerate}#2\end{enumerate}}
        \c_desc_tl {\begin{description}#2\end{description}}
    }
    \end{frame}
}
\ExplSyntaxOff

\begin{document}
    \modela{enumerate}{
        \item Test
        \item Test
    }
    \modela{description}{
        \item[T] est
        \item[Test] Quack
    }
\end{document}

Update: If you want to have an error branch, just use

\tl_case:NnF \l__hezilun_tmp_tl {
    \c_enum_tl {\begin{enumerate}#2\end{enumerate}}
    \c_desc_tl {\begin{description}#2\end{description}}
}{Environment not allowed}
2

As mentioned in my comment (content of document is stolen from TeXnician answer):

\documentclass{beamer}
\newcommand{\modela}[2]{\begin{frame} \begin{#1}#2\end{#1} \end{frame} } 

\begin{document}
    \modela{enumerate}{
        \item Test
        \item Test
    }
    \modela{description}{
        \item[T] est
        \item[Test] Quack
    }
\end{document}

enter image description here

5
  • And a \modela{frame}{} or \modela{document}{} breaks it :(
    – TeXnician
    Commented May 25, 2017 at 18:18
  • :(, well this hasn't been asked ... (at least I din't understand question on this way). but you solve all this cases in your answer, or not? :)
    – Zarko
    Commented May 25, 2017 at 18:24
  • Yeah, I do, but the user has to take the trouble and manually define all cases. I think both answer have their drawbacks and for the responsible user your solution seems kind of easier.
    – TeXnician
    Commented May 25, 2017 at 18:28
  • 1
    to be honest, I don't like such "inventions". On long therm they make only troubles ... (when you forget, what this mean, where is defined etc). Far better is use standard, well documented LaTeX code for which, if it become necessary can ask here what is going wrong (if this happens).
    – Zarko
    Commented May 25, 2017 at 18:38
  • although as a TeXer I would prefer use as basic as it can, it is a handy way for others who don't understand Tex and co-edit with the same beamer. In fact, a simplified command environments would be linked to willing acceptance for new users.
    – Hezilun
    Commented May 25, 2017 at 23:54

You must log in to answer this question.

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