variable sized harpoon delimiter

I would like to have a variable sized delimiter version of the ams symbols \downharpoonleft, \downharpoonright and \upharpoonleft, \upharpoonright respectively, such that they work with \left and \right. Is there any package that provides something like that?

-
if you can give sample contexts of what you'd like to have delimited, i may be able to concoct something. –  barbara beeton Aug 13 '12 at 20:06
1. simple variable names and 2. matrices, however other things might come. –  IARI Aug 14 '12 at 7:25
Have you tried using tikz? The path decorations allow for all kind of "arrow-like" symbols in various lengths. –  Jonathan Aug 14 '12 at 18:41
I use tikz a lot, however, I was hoping that there is some predefined way to do it. I could achieve what I want with tikz directly, but I would not know, how to make some generic variable-sized delimiters that work with \left and \right (which is what I want). –  IARI Aug 14 '12 at 21:04

Recipe for supporting \left and \right

\left and \right are supported by properties of TFM files. The symbol can be given in different sizes and build a list of characters with ascending sizes in the TFM file. The last entry in the list is an extensible character. The latter is shortly explained the documentation of tftopl, § 14:

14. Extensible characters are specified by an extensible_recipe, which consists of four bytes called top, mid, bot, and rep (in this order). These bytes are the character codes of individual pieces used to build up a large symbol. If top, mid, or bot are zero, they are not present in the built-up result. For example, an extensible vertical line is like an extensible bracket, except that the top and bottom pieces are missing.

The recipe for creating support for \left and \right:

1. Some real font (Type 1, …) is necessary that contains the characters and especially the pieces that are needed to build an extensible character. The programs t1disasm and t1asm might help in this task by learning from existing fonts.

2. The TFM file is created with the right data structures that references the font of the previous step. The programs tftopl and pltotf help in converting TFM files to a readable format and converting back. The documentation of tftopl also contains the description of the TFM file format with its data structures.

3. Definition of the new math font and its symbols in TeX/LaTeX.

This recipe is intended for the more experienced who has enough time (hours if not days).

Poor man's solution via \resizebox

In the following I have hacked a example file that uses \resizebox of package graphics (or graphicx). The disadvantage is that also the line width is proportionately scaled, but this is too much for large sizes.

The hack tries to take into account:

• Delimiters are centered at the math axis.
• Support for the automatically resizing in subscripts, … (via \mathpalette).
• The bounding box for the harpoons have horizontal white space of the other side of the hook. For larger sizes it is scaled too much. Therefore the white space is first stripped and then reinserted as thin space for non-script styles and as half thin space in script styles.

The example file:

\documentclass{article}
\usepackage{amssymb}
\usepackage{graphics}

\makeatletter
\newcommand*{\scaleddelims}[3]{%
\ensuremath{%
\mathpalette{\@scaleddelims{#1}{#2}}{#3}%
}%
}
\newcommand*{\@scaleddelims}[4]{%
% #1: left delimiter
% #2: right delimiter
% #3: \displaystyle, \textstyle, ...
% #4: inner formula
\begingroup
#3%
\sbox0{$\m@th#3\vphantom{A}#4$}%
\setbox2\vbox{\hbox{$\m@th#3#1$}\kern\z@}%
\setbox4\vbox{\hbox{$\m@th#3#2$}\kern\z@}%
\setbox6\hbox{$#3\vcenter{}$}%
\ifx\downharpoonleft#1\relax
\let\DelimLeft=L%
\else\ifx\upharpoonleft#1%
\let\DelimLeft=L%
\else\ifx\downharpoonright#1%
\let\DelimLeft=R%
\else\ifx\upharpoonright#1%
\let\DelimLeft=R%
\fi\fi\fi\fi
\ifx\downharpoonleft#2\relax
\let\DelimRight=L%
\else\ifx\upharpoonleft#2\relax
\let\DelimRight=L%
\else\ifx\downharpoonright#2\relax
\let\DelimRight=R%
\else\ifx\upharpoonright#2\relax
\let\DelimRight=R%
\fi\fi\fi\fi
\ifx\DelimLeft L%
\wd2=.6\wd2
\fi
\ifx\DelimRight L%
\wd4=.6\wd4
\fi
\ifx\DelimLeft R%
\sbox2{\kern-.4\wd2\box2}%
\fi
\ifx\DelimRight R%
\sbox4{\kern-.4\wd4\box4}%
\fi
\dimen0=\ht0 %
\dimen2=\dp0 %
\ifdim\dimen2>\dimen0 %
\dimen0=\dimen2 %
\else
\dimen0=\dimen0 %
\fi
\dimen2=\ht6 %
\dimen0=2\dimen0 %
\def\DelimCorr{%
\mskip.5\thinmuskip
\nonscript\mskip.5\thinmuskip
}%
\mathopen{%
\ifx\DelimLeft R\DelimCorr\fi
\raisebox{\dimen2}{\resizebox{!}{\dimen0}{\box2}}%
\ifx\DelimLeft L\DelimCorr\fi
}%
\begingroup
#3#4%
\endgroup
\mathclose{%
\ifx\DelimRight R\DelimCorr\fi
\raisebox{\dimen2}{\resizebox{!}{\dimen0}{\box4}}%
\ifx\DelimRight L\DelimCorr\fi
}%
\endgroup
}
\makeatother

\begin{document}

$x + \scaleddelims{\downharpoonleft}{\downharpoonright}{\frac{4x}{x^2+3}} + \scaleddelims\downharpoonleft\downharpoonright{\frac\cdot{\frac XY}} + \scaleddelims\downharpoonleft\downharpoonright{\frac{\frac XY}\cdot}$

\bigskip
$x + \left\rfloor \frac{4x}{x^2+3} \right\lfloor + \left\rfloor \frac\cdot{\frac XY} \right\lfloor + \left\rfloor \frac{\frac XY}\cdot \right\lfloor$

\bigskip
$\mathopen{\downharpoonleft} x \mathclose{\downharpoonright} = \scaleddelims{\downharpoonleft}{\downharpoonright}{x} = \rfloor x \lfloor \qquad \scaleddelims\downharpoonleft\downharpoonright{}$

\bigskip
$y \scaleddelims\downharpoonright\downharpoonleft{\frac ab} z ^{\scaleddelims\downharpoonleft\downharpoonright{c}}$

\end{document}


-
Thanks, however I'am new to this and haven't done any of it before. I'll try reading into it, any tutorial recommendation? –  IARI Aug 15 '12 at 9:34
I would like to use this to define a restriction operator, like \newcommand{\rest}[2]\scaleddelims{\upharpoonright}{\vphantom{.}}{\vphantom{#1}‌​#2}, but LaTeX tells me that either I'm missing a dollar sign or a \begin{document}. What should I do? –  jdc Jul 7 at 21:56
@jdc: A formal correct definition would be \newcommand{\rest}[2]{\scaleddelims{\upharpoonright}{\vphantom{.}}{\vphantom{#1‌​}#2}}. But I have no idea, what \rest is supposed to do. –  Heiko Oberdiek Jul 7 at 22:20
Wow, that was a dumb error. I somehow couldn't figure out the braces were missing. Also, I realize I wanted to put a #1 before \scaleddelims. The goal was to denote the restriction of a function to a subdomain with a properly tall restriction sign. Thanks! –  jdc Jul 8 at 2:42
Another question, since I've got your attention: you seem to be saying \upharpoonright is already extensible, but I seem to get errors when putting, e.g., \big or \left before it. What else should I be doing? –  jdc Jul 8 at 2:47