Child pages
  • Commands based on variable size delimiters
Skip to end of metadata
Go to start of metadata

OK, check this.

\usepackage{amsmath} % you probably already include this.

    \begingroup % \sizel and \sizer are local:
        \expandafter\let\expandafter\sizel\csname ##1l\endcsname
        \expandafter\let\expandafter\sizer\csname ##1r\endcsname

This makes a macro \newvarcmd which you can use to create one-argument macros:

\newvarcmd{\abs}{\sizel\lvert #2\sizer\rvert}   % you have to use #2 for the argument. you will see why.
\newvarcmd{\norm}{\sizel\lVert #2\sizer\rVert}

If you write \abs{x}, you will just get \lvert x \rvert, which is how you'd typeset the absolute value of x. But if x is bigger, you can use an optional argument and write \abs[big]{x}, say, and you will get \bigl\lvert x \bigr\rvert, which is just what you'd want to write... You can use this with any of the amslatex sizes. And if you're not sure how big the thing to typeset is going to be, you can write \abs[var]{x}, which will give you \left\lvert x \right\rvert. Demo:

  \abs{x} \qquad
  \abs{o^{h^{d^{e^{a^{r}}}}}} \qquad  % default-size \abs will be too small!
  \abs[big]{o^k} \qquad
  \norm[Big]{\frac{c}{d}} \qquad
  \abs[var]{\int_0^\infty t^{z-1} e^{-t} \, \mathrm{d} t}

This looks like this:

This is super-cute and I think it is my favourite thing I've written.

  • No labels