Define macro for \Big, \bigg etc

delimitersmacros

Is it possible to make macro behave as if it was written directly?

\documentclass{article}
\usepackage{amsmath}

\newcommand{\veca}{|_{\vec{a}}}

\begin{document}

\[
\frac{f(\vec{x})}{g(\vec{x})}\bigg\veca \qquad \frac{f(\vec{x})}{g(\vec{x})}\bigg|_{\vec{a}}
\]

\end{document}

enter image description here

Best Answer

The default definition of \Big and friends sets the delimiter as a left delimiter, so having a subscript on it ends up being the first element in the delimited list and therefore does not get placed relative to the delimiter. This can be avoided by defining \Big and friends in the opposite way: Make the delimiter a right delimiter, such that the subscript becomes a subscript of the whole delimited list.

While this fixes the placement, it can have side effects on how the subscript is placed (mostly \nulldelimiterskip is zero and the style is always scriptstyle) but for most usecases this shouldn't matter.

Given that amsmath defines \big based on \bBigg@ it's enough to change the definition of that macro:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\renewcommand \bBigg@[2]{%
  {\@mathmeasure\z@{\nulldelimiterspace\z@}%
     {\left.\vcenter to#1\big@size{}\right#2}%
   \box\z@}}
\makeatother

\newcommand{\veca}{|_{\vec{a}}}

\begin{document}

\[
\frac{f(\vec{x})}{g(\vec{x})}\bigg\veca \qquad \frac{f(\vec{x})}{g(\vec{x})}\bigg|_{\vec{a}}
\]

\end{document}

enter image description here