7

Oh look, a real question!

In trying to actually complete something, I came across the following limitation of this lambda macro creator: it apparently does not work in the use case it was intended for. It's certainly a problem with expansion control, but I don't know where to really start.

\documentclass{article}

% (David Carlisle / @Manuel)'s much simpler version
\newcommand\LambdaFunction[2][0]{%
  \let\tmp\relax
  \newcommand\tmp[#1]{#2}\tmp}

\usepackage{empheq}

\begin{document}
\begin{empheq}[
  box={\LambdaFunction{%
      \colorbox
      {myblue}%
      {\hspace{1em}#1\hspace{1em}}%
    }%
  }
  ]{align*}
  a   &= b   \\
  a^2 &= b^2
\end{empheq}
\end{document}
Sean Allred
  • 27,421

1 Answers1

11

You missed out the color package:-) also my version defaulted to [0] rather than [1] so I had to add [1]. Then you need to double # just because.

\documentclass{article}

\usepackage{color}

% (David Carlisle / @Manuel)'s much simpler version
\newcommand\LambdaFunction[2][0]{%
  \let\tmp\relax
  \newcommand\tmp[#1]{#2}\tmp}

\usepackage{empheq}

\begin{document}
\begin{empheq}[
  box={\LambdaFunction[1]{%
      \colorbox
      {blue}%
      {\hspace{1em}##1\hspace{1em}}%
    }%
  }
  ]{align*}
  a   &= b   \\
  a^2 &= b^2
\end{empheq}
\end{document}
David Carlisle
  • 757,742
  • I'm just not having a good day, today XD Thanks! – Sean Allred Jul 04 '14 at 19:54
  • However, having a [0] by default doesn't make any sense, since the idea is that it has arguments. If you don't need arguments you could just put the code without worrying about this \LamdaFunction. – Manuel Jul 04 '14 at 20:09
  • @Manuel yes true I just did it for consistency with every other latex command definition but you can change [0] to [1] but actually I'd just make it mandatory. – David Carlisle Jul 04 '14 at 20:15