# How can I create a new extensible symbol?

Given an arbitrary thin vertical symbol, can I create a new math delimiter from it (and if so, how)?

Edit: Ideally, I would like to be able to create an extensible symbol, either built out an existing normal symbol, or even made from scratch.

Edit 2: I am pretty sure that what I am after is an explanation of how to create a .tfm file for an extensible symbol (which Werner's answer describes the general structure of, but not how to make one).

For example, let's say I wanted to use the \dagger () or \wr () symbol as a delimiter, and write expressions like

$\left\ldagger \sum_{n=1}^\infty a_n \right\rdagger$


where the symbol scaled appropriately. Would there be any distinction between declaring a symmetric delimiter (like \vert), as opposed to one that has inherently different "left" and "right" versions like [ and ]?

Now, even being unaware of the inner workings of TeX, I imagine that there has to be lots of information in the fonts for how a delimiter is to be scaled in different situations, and if I try to make my own delimiter, this information won't be present. Would I need to get deep into FontForge or equivalent to achieve my custom delimiters, or is there an easier way?

-
I guess that those symbols are not expansible so they aren't good for delimiters. – Sigur Apr 20 '13 at 1:48
Exactly; my question is pretty much asking how to make them expansible, if that's possible. – Zev Chonoles Apr 20 '13 at 1:51
The delimiters like \vert, [, ], (, ), ... are called extensible and are actually constructed out of several pieces, rather than being stretched vertically. Of course, it is always possible to stretch symbols to a given length and make them look like a delimiter. – Werner Apr 20 '13 at 2:02
@Werner: If you could post about how to make stretched pseudo-delimiters, that'd be an acceptable solution, though I am still very interested in learning the "right" way of making a symbol extensible. – Zev Chonoles Apr 20 '13 at 2:06
@HendrikVogt: If you can't add an answer in time and the bounty is automatically awarded, I will repost a bounty to echo @ ZevChonoles' efforts once you do/can... – Werner Apr 30 '13 at 16:20

Scott Pakin's Comprehensive LaTeX Symbol List identifies the structure of extensible delimiters in section 8.2 Resizing symbols (p 100-102):

All variable-sized delimiters are defined (by the corresponding .tfm file) in terms of up to five segments, as illustrated by Figure 1 on page 102. The top, middle, and bottom segments are of a fixed size. The top-middle and middle-bottom segments (which are constrained to be the same character) are repeated as many times as necessary to achieve the desired height.

This is merely informative since I am unfamiliar with the procedure of how to create these things in a .tfm file.

Conveniently, scalerel provides \scaleleftright[<max width>]{<left obj>}{<stuff>}{<right obj>} (and a comparable \stretchleftright) for scaling/stretching both <left obj> and <right obj> to the height of <stuff> (constrained, if required and optional, to a width of <max width>). Here's a quick example:

\documentclass{article}
\usepackage{scalerel}% http://ctan.org/pkg/scalerel
\begin{document}
$\stretchleftright{\dagger}{\displaystyle\sum_{i=1}^n i}{\dagger}$
$\scaleleftright{\dagger}{\displaystyle\sum_{i=1}^n i}{\dagger}$
\end{document}

-
I've heard from one user for whom V1.4 produced unacceptable results vis-s-vis V1.3 (but I don't yet have details as to the specifics). If anyone experiences what they think is faulty behavior with scalerel V1.4, I would appreciate notification. – Steven B. Segletes May 13 '13 at 12:02

OK, you really want to know how to create your own tfm file with new extensible symbols? Then here are some explanations. I only give some toy example, working with the standard Computer Modern fonts. Here's the output I can produce; I don't claim that it's nice or useful:

Here's the LaTeX code:

\documentclass[12pt]{article}
\usepackage{amsmath}
\DeclareFontShape{OMX}{cmex}{m}{n}{<->sfixed*modcmex10}{}
\pdfmapline{+modcmex10 CMEX10 <cmex10.pfb}
\begin{document}
$\begin{pmatrix} 1&0&0&0 \\ 0&1&0&0 \\ 0&0&1&0 \\ 0&0&0&1 \end{pmatrix} + \begin{Vmatrix} 1&0&0&0 \\ 0&1&0&0 \\ 0&0&1&0 \\ 0&0&0&1 \end{Vmatrix}$
\end{document}


In the 3rd and 4th line I tell LaTeX to use the tfm file modcmex10 instead of cmex10, and to use the usual glyphs from cmex10.pfb with the modified tfm file. The amsmath environments pmatrix and Vmatrix internally use \left(...\right) and \left\|...\right\|, so apparently I redefined those extensible delimiters.

How does one do this? The short answer: on a Unix type system you can just run the following script that produces a virtual font modcmex10 consisting of two files modcmex10.tfm and modcmex10.vf that are needed to compile the above LaTeX code. Beware!  This virtual font provides the three extensible delimiters shown above, but it also garbles many other delimiters.

# Create a patch file:
echo '22a23,29
> (MAPFONT D 0
>    (FONTNAME cmex10)
>    )
> (MAPFONT D 1
>    (FONTNAME cmsy10)
>    (FONTAT R 2)
>    )
106c113
<       (REP O 15)
---
>       (REP O 75)
314a322
>       (MID O 74)
324a333
>       (MID O 75)
423a433,437
>    (MAP
>       (SELECTFONT D 0)
>       (MOVELEFT R 0.1)
>       (SETCHAR O 74)
>       )
429,430c443,450
<    (CHARWD R 0.888891)
<    (CHARDP R 1.800018)
---
>    (CHARWD R 0.888892)
>    (CHARHT R 1.41)
>    (CHARDP R 0.41)
>    (MAP
>       (SELECTFONT D 1)
>       (MOVERIGHT R 0.08)
>       (SETCHAR O 172)
>       )' > cmex.diff
# Create modified cmex font:
tftopl \$(kpsewhich cmex10.tfm) > modcmex10.vpl
patch modcmex10.vpl cmex.diff
vptovf modcmex10.vpl
rm cmex.diff
# Remove the following line if you want to study the virtual font:
rm modcmex10.vpl


## How does the virtual font work?

As a basis I used cmex10.pl, the property list of the Computer Modern font containing the extensible symbols. First of all, I added the lines

(MAPFONT D 0
(FONTNAME cmex10)
)
(MAPFONT D 1
(FONTNAME cmsy10)
(FONTAT R 2)
)


This means that both the fonts cmex10 and cmsy10 will be used, and that the latter is scaled by a factor of 2. I take the \ddagger from this double sized cmsy10 and use it as a replacement for the constituents of the extensible \| delimiter. In my vpl file (virtual property list) this implemented in the following lines:

(CHARACTER O 15
(CHARWD R 0.555557)
(CHARDP R 0.600006)
(VARCHAR
(REP O 75)
)
)


This tells us that the character in slot 15 is a variable character that will be constructed from a REPeatable piece that should be taken from slot 75. (The original font uses slot 15 itself. Note that these are octal numbers, so actually it's the 13th and 61st slot!) And what's in slot 75? The answer is found in these lines:

(CHARACTER O 75
(CHARWD R 0.888892)
(CHARHT R 1.41)
(CHARDP R 0.41)
(MAP
(SELECTFONT D 1)
(MOVERIGHT R 0.08)
(SETCHAR O 172)
)
(VARCHAR
(REP O 167)
)
)


It's the character from slot 172 of the font D 1, which above was defined as cmsy10, so it's the double dagger. Moreover, the character is moved to the right a bit. I had to fiddle a bit to find the (relative) height and depth 1.41 and 0.41.

## How does TeX choose the appropriate delimiter size?

Let's have a look at the following lines that are from the original cmex10.pl:

(CHARACTER O 0
(CHARWD R 0.458336)
(CHARHT R 0.039999)
(CHARDP R 1.160013)
(NEXTLARGER O 20)
)


This says (among other things) that the character in slot 0 (an opening parenthesis) has a larger version in slot 20. The chain of larger and larger versions continues via slots 20, 22 and 40 to the largest version of the character in slot 60. And this is what you find in slot 60 of my virtual font:

(CHARACTER O 60
(CHARWD R 0.875003)
(CHARHT R 0.039999)
(CHARDP R 1.760019)
(VARCHAR
(TOP O 60)
(MID O 74)
(BOT O 100)
(REP O 102)
)
)


It's again a variable character, and it consists of four types of pieces: a TOP, a MIDdle and BOTtom part, and inbetween a REPeatable part. I added the middle piece from slot 74, so that you get this crossbreed between a parenthesis and a brace. When TeX sees a \left...\right construct, it goes through this line of larger and larger versions of a delimiter until it finds one that is large enough. In the best case, the last version is extensible!

-
I could tell even more, but not in the near future ... Oh, and here's a link where you can find out more about those (virtual) property lists: tug.org/texlive//devsrc/Master/texmf-dist/doc/generic/knuth/etc/… – Hendrik Vogt May 1 '13 at 19:16

If you need an existing delimiter in some sense similar to expanded \wr, you have e.g. \leftwave and \rightwave from mathdesign package.

-