6

Can I introduce new delimiter symbols to use with \left and \right? For example I would like to do

\begin{equation}
\left\harpoonleft something \right\harpoonright
\end{equation}

I would then like the size of the symbols to be dependent on the size of something between the symbols.

How would I do such a thing?

4
  • 1
    I think you can redefine \left and \right but I'm not sure if it is a good idea... this and this answer might help you.
    – Pouya
    Jun 9, 2014 at 13:17
  • 5
    A symbol can go after \left or \right only if scalable versions of the symbol are available as part of the font.
    – egreg
    Jun 9, 2014 at 13:20
  • 2
    The mathtools \DeclarePairedDelimiter is probably easiest. One could do it from scratch using graphics \resizebox. Jun 9, 2014 at 14:13
  • @JohnKormylo that wont do any resizing when whats between the delimiters is large. But that's probably because of what egreg said. Jun 9, 2014 at 14:58

3 Answers 3

8

I mean that the qeustion mentions the harpoons, no arrows. Because there is no harpoon part in common math symbols and the \resizebox creates the harpoon marks deformed, I suggest another solution: to draw the harpoon parts as PDF code using \pdfliteral. The rest is simply \vrule.

\documentclass{article}

\def\leftharpoonpart  {\pdfliteral{q 0 0 m 0 -2.1 -1.2 -2.8 -1.5 -3 c 1 j .4 w S Q}}
\def\rightharpoonpart {\pdfliteral{q 0 0 m 0 -2.1  1.2 -2.8  1.5 -3 c 1 j .4 w S Q}}

\def\encloseharpoons#1{\setbox0=\hbox{$\displaystyle{#1}$}%
   \mathop{\,\vrule height\ht0 depth\dp0
   \kern-.2pt \raise\ht0\vbox to0pt{\vss\leftharpoonpart\kern.1pt}%
   \copy0
   \raise\ht0\vbox to0pt{\vss\rightharpoonpart\kern.1pt}\kern-.2pt\vrule\,}%
   \nolimits
}
\begin{document}

$$a \cdot \encloseharpoons{\int_a^b} + \encloseharpoons{1\over2}^2$$

\end{document}

Of course, no special packages are needed. The result is

harpoon

And the detail:

harpoon detail

You have to use pdflatex or lualatex. When xelatex is used you need to add the definition:

\def\pdfliteral#1{\special{pdf:literal #1}}
2

If you want to use Tikz to create your delimeters:

\documentclass{article}
\usepackage{tikz}

\newcommand{\leftdelim}[2]% #1 = height, #2 = depth
{\tikz[baseline]{\draw[color=red,arrows={-latex}](0,-#2)--(0,#1);}}

\newcommand{\rightdelim}[2]% #1 = height, #2 = depth
{\tikz[baseline]{\draw[color=red,arrows={latex-}](0,-#2)--(0,#1);}}

\newlength{\MyHeight}
\newlength{\MyDepth}
\newsavebox{\MyBox}

\newcommand{\mydelim}[1]% #1 = text to be enclosed
{\savebox{\MyBox}{$\displaystyle #1$}% get size of box
\settoheight{\MyHeight}{\usebox{\MyBox}}%
\settodepth{\MyDepth}{\usebox{\MyBox}}%
\leftdelim{\MyHeight}{\MyDepth}%
\,\usebox{\MyBox}\,%
\rightdelim{\MyHeight}{\MyDepth}}

\begin{document}
\[
\mydelim{\frac{x+a}{x+b}}
\]
\end{document}

delimiters

If you do NOT want to use tikz:

\documentclass{article}
\usepackage{graphics}

\newlength{\MyHeight}
\newlength{\MyDepth}
\newlength{\MyDiff}
\newsavebox{\MyBox}

\newcommand{\mydelim}[1]% #1 = text to be enclosed
{\savebox{\MyBox}{$\displaystyle #1$}% get size of box
\settoheight{\MyHeight}{\usebox{\MyBox}}%
\settodepth{\MyDepth}{\usebox{\MyBox}}%
\addtolength{\MyHeight}{\MyDepth}%
\settodepth{\MyDiff}{$\uparrow$}
\addtolength{\MyDiff}{-\MyDepth}
\raisebox{\MyDiff}{\resizebox{\width}{\MyHeight}{$\uparrow$}}%
\,\usebox{\MyBox}\,%
\raisebox{\MyDiff}{\resizebox{\width}{\MyHeight}{$\downarrow$}}}

\begin{document}
\[
\mydelim{\frac{x+a}{x+b}}
\]
\end{document}

resize

4
  • Erh, \uparrow and \downarrow already qualify as delimiters so no need for tikz or scaling in that case.
    – daleif
    Jun 10, 2014 at 8:31
  • I didn't realize that harpoon referred to a specific shape. I used arrows because they were easy. Jun 10, 2014 at 13:37
  • I notice that this answer hard codes the math style (which I post a patch in a separate answer below). I think it's a minor change, so you can edit this answer and I'll delete my answer.
    – user202729
    Feb 2, 2023 at 15:17
  • Or you can accept you own answer. I don't need the points. Feb 2, 2023 at 17:57
1

This is an improvement over John Kormylo's answer -- it works, but has a small quirk: it hard codes the math style.

What does this mean? Consider for example, with that definition:

\[ \mydelim{\frac{x+a}{x+b}} \]

$ \mydelim{\frac{x+a}{x+b}} + \frac{x+a}{x+b} $

the second formula is too large, compared to the one outside the custom delimiter.

output

One way to fix it is to manually add the \textstyle command:

$ \mydelim{\textstyle \frac{x+a}{x+b}} \frac{x+a}{x+b} $

(in this case you don't need the \displaystyle at all)

Another way is to modify the command definition as follows:

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}  % ← note the added package

\newcommand{\leftdelim}[2]% #1 = height, #2 = depth
{\tikz[baseline]{\draw[color=red,arrows={-latex}](0,-#2)--(0,#1);}}

\newcommand{\rightdelim}[2]% #1 = height, #2 = depth
{\tikz[baseline]{\draw[color=red,arrows={latex-}](0,-#2)--(0,#1);}}

\newlength{\MyHeight}
\newlength{\MyDepth}
\newsavebox{\MyBox}

\newcommand{\mydelim}[1]% #1 = text to be enclosed
{\text{\savebox{\MyBox}{$#1$}% get size of box
\settoheight{\MyHeight}{\usebox{\MyBox}}%
\settodepth{\MyDepth}{\usebox{\MyBox}}%
\leftdelim{\MyHeight}{\MyDepth}%
\,\usebox{\MyBox}\,%
\rightdelim{\MyHeight}{\MyDepth}}}

\begin{document}
\[ \mydelim{\frac{x+a}{x+b}} \]

$ \mydelim{\frac{x+a}{x+b}} + \frac{x+a}{x+b} $
\end{document}

which gives the desired result.

fixed output

An explanation of the \text command may be found at rotating - Rotated math with correct font size - TeX - LaTeX Stack Exchange.

You must log in to answer this question.

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