Why does using \biggl <stuff> \biggl not throw an error?
I'd prefer a syntax à la mathtools
, where you just specify the size with \big
\Big
\bigg
or \Bigg
. In any case you should specify the type of the objects you build, because \textcolor
hides it.
\NewDocumentCommand{\virtualparens}{ O{} m }{%
\mathopen{\textcolor{lightgray}{#1(}}% opening fence
#2% contents
\mathclose{\textcolor{lightgray}{#1)}}% closing fence
}
Here's the full example, with comparisons.
\documentclass[twocolumn]{article}
\usepackage{amsmath}
\usepackage{xcolor}
\NewDocumentCommand{\virtualparens}{ O{} m }{%
\mathopen{\textcolor{lightgray}{#1(}}#2\mathclose{\textcolor{lightgray}{#1)}}%
}
%%% for comparison
\NewDocumentCommand{\wrongvirtualparens}{ O{} m }{% your definition
\textcolor{lightgray}{#1(}#2\textcolor{lightgray}{#1)}%
}
\NewDocumentCommand{\alsowrongvirtualparens}{ O{} m }{% Steven's definition
\textcolor{lightgray}{\csname#1l\endcsname(}#2%
\textcolor{lightgray}{\csname#1r\endcsname)}%
}
%%%
\begin{document}
\begin{gather}
\sin\wrongvirtualparens[\bigg]{-G\frac{m_1 m_2}{r}} \\
\sin\alsowrongvirtualparens[bigg]{-G\frac{m_1 m_2}{r}} \\
\sin\virtualparens[\bigg]{-G\frac{m_1 m_2}{r}} \\
\sin\biggl(-G\frac{m_1 m_2}{r}\biggr)
\end{gather}
\end{document}
Do you see the difference?
You want to use l
version on the left and r
version on the right. I modified your syntax a bit to achieve it. Using two left versions does not throw an error, but it could mess up the natural spacings between surrounding material.
However, there is a drawback to using this paired approach...you can't naturally break up the argument across a linebreak, which one can do if he individually specifies the \biggl(
and \biggr)
. So, you have to weigh the advantages and disadvantages.
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\NewDocumentCommand{\virtualparens}{ O{} m }{%
\textcolor{lightgray}{\csname#1l\endcsname(}#2
\textcolor{lightgray}{\csname#1r\endcsname)}
}%
\begin{document}
\[
\virtualparens[bigg]{-G\frac{m_1 m_2}{r}}
\]
\end{document}
You can keep the decision about parentheses size to \left...\right
primitives:
\def\virtualparens#1#2#3{\mathopen{}\color{lightgray}\left#1
\color{black}#2\color{lightgray}\right#3\color{black}\mathclose{}}
$$
\sin \virtualparens ({-G {m_1 m_2\over r}}) x
$$
compare with:
$$
\sin \Bigl( -G {m_1 m_2\over r} \Bigr) x
$$