1

I am interested in creating a new paired delimiter using tikzpictures I defined. There has to be something easy I'm missing, but hours of searching has proved fruitless. Here is what I have so far:

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}

\def\pewl{\hspace{.075cm} \begin{tikzpicture}[scale=1, baseline=1mm, line width=.23mm] \draw (0mm,3.25mm) -- (0mm,1mm); \draw (0mm,3.25mm) arc (180:90:.8mm); \draw (0mm,1mm) arc (180:270:.8mm); \end{tikzpicture} }

\def\pewr{\hspace{-.01cm} \begin{tikzpicture}[scale=1, baseline=1mm, line width=.23mm] \draw (0mm,3.25mm) -- (0mm,1mm); \draw (0mm,3.25mm) arc (0:90:.8mm); \draw (0mm,1mm) arc (0:-90:.8mm); \end{tikzpicture} } \DeclarePairedDelimiter{\pew}{\pewl}{\pewr}

\begin{document}

$$ \pewl M\pewr \pewl g\pewr \pewl f\pewr \pew{M} \pew{g} \pew{\sum} $$

\end{document}

which begets:

Failed new tikzpicture delimiters.

and an error saying:

Missing delimiter (. inserted).

I'm on Overleaf, if that's relevant somehow. Any help would be much appreciated!

2 Answers2

2

The short answer is:

Don't use \DeclarePairedDelimiter with objects that are not scalable delimiters

Your code actually runs into two different sorts of problem.

  1. If you used \pew{M}, you should see an error about a missing {.

    This is a cryptic error, and results from how \DeclarePairedDelimiter treats the unstarred version with no optional argument. In this case, the code essentially just expands to \mathopen\pewl M\mathclose\pewr. Why this breaks I don't really know, but is a case where \mathopen#1 and \mathopen{#1} behave differently. This is a problem because \mathopen is a TeX primitive that expects what follows to expand to either a single character or to a group. As you defined it, \pewl is neither.

    This could be "solved" if you just declare your \pewl and \pewr appropriately as objects of mathopen/close types to start with. E.g., you can just define \pewl as \mathopen{\hspace{0.075cm}...}. You should do this anyway independently of the rest of this answer since if you are creating delimiters, they should be typeset following rules of typesetting delimiters, and not that of ordinary math atoms.

  2. If you used \pew[\big]{M} or \pew*{M}, you see the error about missing delimiter and the insertion of .

    Somewhere (after a lot of expansions) TeX will encounter something that looks like \left\pewl. But this would only be meaningful if \pewl is a scalable delimiter. As \pewl is not such a thing (being a scalable delimiter is a quality of particular symbols defined in the font), \left complains.

Solution:

  1. As mentioned above, define \pewl and \pewr as \mathopen and \mathclose atoms.
  2. Instead of using \DeclarePairedDelimiter, just use \newcommand to define \pew.
Willie Wong
  • 24,733
  • 8
  • 74
  • 106
1

You seem to want an auto-scaling paired delimiter out of the tikz drawing you made. This can be done by

  1. Making the height and depth of the parentheses adjustable
  2. Measuring the content by saving it to a box.
\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}

\makeatletter % inserted extra 1mu before and after the symbol, can be adjusted. % this is in addition to the spacing inserted by mathopen and mathclose \newcommand@pewl[2]{\ensuremath{\mathopen{\mkern1mu\relax% \begin{tikzpicture}[scale=1, baseline=1mm, line width=.23mm] \draw (0mm,1mm+#1) -- (0mm,1mm-#2); \draw (0mm,1mm+#1) arc (180:90:.8mm); \draw (0mm,1mm-#2) arc (180:270:.8mm); \end{tikzpicture}} }}

\newcommand@pewr[2]{\ensuremath{\mathclose{% \begin{tikzpicture}[scale=1, baseline=1mm, line width=.23mm] \draw (0mm,1mm+#1) -- (0mm,1mm-#2); \draw (0mm,1mm+#1) arc (0:90:.8mm); \draw (0mm,1mm-#2) arc (0:-90:.8mm); \end{tikzpicture}\mkern1mu\relax} }}

\newsavebox{\pew@inner} \newlength\pew@ht \newlength\pew@dp \newcommand\pew[1]{% \text{\savebox{\pew@inner}{$#1$}% \pew@ht=\ht\pew@inner\relax% \pew@dp=\dp\pew@inner\relax% \ifdim\pew@ht<1.5ex\relax% Set a minimum height of 1.5ex \global\pew@ht=1.5ex\relax \fi @pewl{\pew@ht}{\pew@dp}\usebox{\pew@inner}@pewr{\pew@ht}{\pew@dp}}} \makeatother

\begin{document}

[ \pew{M} \pew{g} \pew{k} \pew{\frac12} \pew{\frac{1}{1 + \frac{1}{1+ \frac12}}} ]

\end{document}

enter image description here

Willie Wong
  • 24,733
  • 8
  • 74
  • 106