3

I want to define a restriction operator \restrict{f}{X} which is capable of resizing in the style of mathtools's \DeclarePairedDelimiter options. For example:

  • \restrict*{f}{X} should resize automatically
  • \restrict[\Big]{f}{X} should provide a large vertical bar regardless of what f is
  • &c.

The MWE I currently have throws an error:

\documentclass{article}
\usepackage{mathtools}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}

\DeclarePairedDelimiterXPP{\restrict}[2]{}{}\rvert {\IfNoValueTF{#2}{}{_{#2}}} {#1}

\begin{document} \begin{equation} \restrict{f}{X} = \restrict*{\frac{f}{1}}{X} \end{equation} \end{document}

When running this, I get an appropriate output, but the error:

Missing delimiter (. inserted).

This makes sense, since the left delimiter I provided was the empty token {}. However, if I replace it with {.}, then for the nonstarred \restrict, a period is introduced in the typesetting which I do not wish for.

Is there a way to communicate to \DeclarePairedDelimiter that I want an empty delimiter, or must I go the route of error-surpressing?

Phrohlych
  • 205

1 Answers1

2

Don't use \DeclarePairedDelimiter.

\documentclass{article}
\usepackage{mathtools}
\usepackage{mleftright}

\NewDocumentCommand{\restrict}{sO{}mm}{% \IfBooleanTF{#1}{% star \mleft.\kern-\nulldelimiterspace #3 \mright|% }{% no star #3#2|% }% % the subscript _{#4}% }

\begin{document} \begin{equation} \restrict{f}{X} = \restrict*{\frac{f}{1}}{X} = \restrict[\Big]{f}{X} \end{equation} \end{document}

enter image description here

egreg
  • 1,121,712
  • Wouldn’t #3\mathclose#2| or #3\mathclose{#2|} perhaps be better, or at least more correct? Then the spacing would behave the same way as in the auto-scaled case (where you use \mright rather than \right). – Gaussler May 05 '23 at 08:56
  • I see no discernible difference between the three options #3#2, #3\mathclose#2, and #3\mathclose{#2|}. Does this affect how it displays in different situations (like subscripts)? – Phrohlych May 05 '23 at 19:37