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.

I'd like to have an easy way to declare an operator that brackets its argument with a particular delimiter. As an example I'd like to be able to write


to mean the same as


FYI I know how to do


but I thought I once saw a package that provided some command like


sort of a combination of \DeclarePairedDelimiter and \DeclareMathOperator and I think it also defined a starred version of the operator that didn't take any argument and didn't produce the delimiters.

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

I don't remember of any such package. Your \Pr command maybe obtained by


With this definition, \Pr would behave exactly as if it was defined with \DeclarePairedDelimiter; that is, the *-form would use \left and \right.

If you want to always use \left and \right, you might follow Werner's suggestion, or go the hard way:


(requires amsmath, of course). Note: \renewcommand{\Pr}{...} is necessary, because \Pr is already defined in LaTeX.

share|improve this answer
add comment

Here is a way to define your own operator with an optional bracketing:

\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{xparse}% http://ctan.org/pkg/xparse
\DeclareDocumentCommand{\Pr}{s m}{% \Pr[*]{..}
  \IfBooleanTF{#1}% Condition on *
    {#2}% Print only the argument in starred * version
    {\left[#2\right]}% Print bracketed argument [ ] in unstarred version

This is $\Pr{2}$, and here is

Operator with starred version that brackets/doesn't bracket argument

The above code defines the macro \Pr{..} (actually redefines \Pr, since it is provided by amsmath), but also provides a starred * version. The unstarred version, as requested, prints its argument in extensible brackets, while the starred * version removes these brackets.

The xparse package provides an easy interface to specify starred versions of commands and environments. The xifthen package provides conditional support.

share|improve this answer
add comment

Your Answer


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.