I am considering the notation

\newcommand{\f}[3]{f\left(#1; #2 \lvert #3\right)}


As you can see, the top formula has \vert size as default. I want the latter formula, How do I change my command? I can't use the \left and \right command because there is no left or right in \vert.

Any help is appreciated.

  • I don't think is a dupe. Why? Because it's not just about \middle\vert, but also about properly sizing the delimiters (which \left and \right are not likely to do).
    – Mico
    Commented Jun 18 at 2:18
  • @Mico Although that does have an answer using mathtools (in fact, \DeclarePairedDelimiterX, so you can automate the \Bigm in your answer).
    – Teepeemm
    Commented Jun 18 at 2:45

2 Answers 2


My suggestion is to exploit \DeclarePairedDelimiterX and \NewDocumentCommand in order to automatically get | to grow like the outer parentheses.

We need to distinguish when the argument contains | or not, but it's easy with the preprocessor \SplitArgument{1}{|} which will pass something like x;1 as {x;1}{-NoValue-} and x;1|n as {x;1}{n}`, so the auxiliary function can accordingly branch.




f\args{x;1} \\
f\args[\big]{x;1} \\
f\args[\Big]{x;\frac{1}{n}} \\
f\args*{x;\frac{1}{n}} \\
f\args{x;1 | u} \\
f\args[\Big]{x;1|\frac{1}{n}} \\


enter image description here

What to choose between 6 and 7? This is a tough question. In the particular case, maybe 7 is better. But consider

enter image description here

where I'd probably select 8.

  • You might want to suggest \tfrac inside arguments.
    – Gaussler
    Commented Jun 18 at 20:04
  • @Gaussler Possibly, but it depends on several factors.
    – egreg
    Commented Jun 18 at 20:27

There are two problems with using \vert. First, as you've noticed, it's not sized properly relative to the material around it. Second, there's not enough horizontal whitespace around it.

The first problem can be solved, superficially, by changing \vert to \middle\vert. Fixing the second problem requires inserting \; ("thickspace") on either side of \middle\vert. Entering the full expression can be streamlined, to a degree, by defining a macro \f as follows:

\newcommand\f[3]{f\left(#1;#2 \;\middle\vert\; #3\right)}

However, this isn't the end of the story as far as fine math typesetting is concerned. For one, the \f macro inserts too much whitespace between "f" and the opening tall parenthesis; this is inherent to using \left( (and, later, \right)). In addition, the delimiters are actually needlessly tall.

Going from left to right in the following screenshot, the first formula is what's produced by the OP's code. The next two are 2 ways to use \left(, \middle|, and \right). The fourth formula, which employs a macro called \parens that's defined via a \DeclarePairedDelimiter instruction, fixes the issue of the inordinate amount of whitespace between f and the opening parenthesis; however, by using \bigg as the sizing directive, this solution keeps producing needlessly tall parentheses. The fifth and last formula shows what happens if \parens[\Big]{...} is used. IMNSHO, the delimiters are now sized more appropriately than what's available by using the "automatic" \left/\middle/\right approach.

enter image description here

\usepackage{mathtools} % for '\DeclarePairedDelimiter' macro; load 'amsmath' automatically
\newcommand\f[3]{f\left(#1;#2 \;\middle\vert\; #3\right)}

f\left( x;1 \vert        \frac{1}{n} \right) \quad
f\left( x;1 \;\middle|\; \frac{1}{n} \right) \quad
\f{x}{1}{\frac{1}{n}} \quad
f\parens[\bigg]{ x;1 \biggm\vert \frac{1}{n} } \quad
f\parens[\Big]{  x;1 \Bigm\vert  \frac{1}{n} } 
  • 3
    I think I would also recommend not naming it \f. Short macro names tend to already be taken (but not this one), so it's a better habit to get into to use meaningful names.
    – Teepeemm
    Commented Jun 18 at 2:36
  • 2
    @Teepeemm - I fully agree with you that it's excellent practice to use meaningful variable and macro names, in one's programs and in one's LaTeX documents. However, I'm also willing to give the OP the benefit of the doubt that in the case at hand, \f was chosen for brevity and simplicity rather than for being indicative of the OP's general programming habits. :-)
    – Mico
    Commented Jun 18 at 6:16

Not the answer you're looking for? Browse other questions tagged .