Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
I should note that I am very much open to using expl3. –  Sean Allred Jul 4 at 19:34

1 Answer 1

up vote 11 down vote accepted

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}
share|improve this answer
    
I'm just not having a good day, today XD Thanks! –  Sean Allred Jul 4 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 4 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 4 at 20:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.