12

Is there a package that would allow me to use other symbols/any symbol apart from the (among others) usual delimiters () [] {} | with \left and \right?

For example, \(\left\int f(x) dx \right.\) would adapt the size of the integral sign to the height of f(x).

3
  • 1
    You have scalerel package to do something similar, but I don't understand why would you want that.
    – Manuel
    Commented Jun 24, 2015 at 18:11
  • 3
    This would be likely to require a font with an “extensible” version of the integral sign (compare with the root sign, which has an extensible version), but I’m afraid such a character would look pretty horrible. I’ve never seen anything similar in print, but maybe you have. Also, maybe you don’t actually want arbitrarily large integral signs, but only up to some maximum.
    – GuM
    Commented Jun 24, 2015 at 19:27
  • 1
    see this and this Commented Jun 24, 2015 at 20:04

2 Answers 2

10

As Manuel indicates, my scalerel package can be used. However, I don't necessarily recommend this approach except in unusual circumstances.

\documentclass{article}
\usepackage{scalerel}
\usepackage{mathtools}
\begin{document}
\def\x{\begin{bmatrix*}1&1\\1&1\end{bmatrix*}}
\[{\scalerel*[2.2ex]{\int}{\x}}_{\!\!\!x=0}^{\infty}\x\,dx\]

\def\x{\begin{bmatrix*}1&1&1\\1&1&1\\1&1&1\end{bmatrix*}}
\[{\scalerel*[2.2ex]{\int}{\x}}_{\!\!\!x=0}^{\infty}\x\,dx\]

\def\x{\begin{bmatrix*}1&1&1&1\\1&1&1&1\\1&1&1&1\\1&1&1&1\end{bmatrix*}}
\[{\scalerel*[2.2ex]{\int}{\x}}_{\!\!\!x=0}^{\infty}\x\,dx\]
\end{document}

enter image description here

Whereas the above use of \scalerel applies a maximum width of 2.2ex to the integral sign, the \stretchrel macro could be used as an alternative, with the optional argument providing the maximum aspect ratio (in %), e.g., \stretchrel[250]{}{}.


ADDENDUM:

By combining the above approach with a more vertically oriented integral sign (Integral Sign $\int...$), one may find a result slightly less offensive to the eye.

\documentclass{article}
\usepackage{scalerel}
\usepackage{mathtools}
\DeclareMathOperator*{\rint}{\ThisStyle{\rotatebox{15}{$\SavedStyle\!\int\!\!\!$}}}
\usepackage{scalerel}
\usepackage{graphicx}
\parskip 1ex

\begin{document}
\def\x{\begin{bmatrix*}1&1\\1&1\end{bmatrix*}}
\[{\scalerel*[4ex]{\rint}{\x}}_{\!x=0}^{\!\infty}\x\,dx\]

\def\x{\begin{bmatrix*}1&1&1\\1&1&1\\1&1&1\end{bmatrix*}}
\[{\scalerel*[4ex]{\rint}{\x}}_{\!\!x=0}^{\!\infty}\x\,dx\]

\def\x{\begin{bmatrix*}1&1&1&1\\1&1&1&1\\1&1&1&1\\1&1&1&1\end{bmatrix*}}
\[{\scalerel*[4ex]{\rint}{\x}}_{\!\!x=0}^{\!\infty}\x\,dx\]
\end{document}

enter image description here

3
18

It occured to me, yesterday, that there does exist (at least) one font which includes glyphs for building a truly extensible integral sign: it is the PostScript Symbol font (psyr), which has such glyphs in positions 243 (octal '363, hexadecimal "F3), 244 (octal '364, hexadecimal "F4) and 245 (octal '365, hexadecimal "F5). Thus an approach along these lines is possible too.

Unfortunately, the .tfm file for the PS Symbol font, psyr.tfm, does not include the necessary information to build the extensible sign from these glyphs (at least, this is the case for the psyr.tfm file included in the distribution to which I can have access right now, a TeXLive 2013—I cannot explain here why I am presently limited to this). However, it’s no big deal to augment the .tfm file to provide the information that is missing. An alternative approach, of course, would be to use a virtual font: this is no big deal too, but for the moment I don’t deem this necessary, as the augmented .tfm file should not hamper the use of the psyr font for other purposes. On the other hand, it is true that psyr.tfm does not define \fontdimen7, and that loading it, as we will do below, can make it impossible to fiddle with the font parameters if the psyr.tfm is loaded again later; so, using a virtual font might prove necessary, but for the moment, I repeat, I’ll leave this to a possible future enhancement.

Having said that, let us proceed with step-by-step instructions on how to get our extensible integral sign in print!


Building the augmented psyr.tfm file

Please note that this process (actually, a slightly more general one, which defines a virtual font) has already been described in this answer.

In order to modify a .tfm file, we need first to convert it to a human-readable form, modify it in this form, and convert the modified file back into .tfm format. The human-readable form is a Property List (.pl) file; you can convert a .tfm file to a .pl file with the tftopl command-line utility and a .pl file back to a .tfm file with—guess what?—the pltotf program.

So, let’s start to construct our modified psyr.tfm file. Move to a directory of your choice and, from the command line, type the command:

tftopl psyr.tfm psyr.pl

This will create the human-readable file psyr.pl in your current directory. Open this file: its first few lines should read

(FAMILY SYMBOL)
(CODINGSCHEME FONTSPECIFIC)
(DESIGNSIZE R 10.0)
(COMMENT DESIGNSIZE IS IN POINTS)
(COMMENT OTHER SIZES ARE MULTIPLES OF DESIGNSIZE)
(CHECKSUM O 16264261360)
(FONTDIMEN
   (SLANT R 0.0)
   (SPACE R 0.25)
   (STRETCH R 0.3)
   (SHRINK R 0.1)
   (XHEIGHT R 0.4)
   (QUAD R 1.0)
   )
(CHARACTER O 40
   (CHARWD R 0.25)
   )

and so on. First of all, since we are going to modify the file, it is a good idea to delete the line that says (CHECKSUM O 16264261360): thus the checksum will be recomputed when we convert the file back to .tfm format.

Next, let’s begin with our patches. Go down to the definition of CHARACTER O 362, that is, to the lines that read

(CHARACTER O 362
   (CHARWD R 0.274)
   (CHARHT R 0.904)
   (CHARDP R 0.104)
   (CHARIC R 0.017)
   )

Modify these lines by adding another line below (CHARIC R 0.017), so that the whole definition of the character '362 (octal) becomes

(CHARACTER O 362
   (CHARWD R 0.274)
   (CHARHT R 0.904)
   (CHARDP R 0.104)
   (CHARIC R 0.017)
   (NEXTLARGER O 363)
   )

(we added the line (NEXTLARGER O 363)). Actually, this step isn’t truly necessary (see below), but I prefer to add redundant information to the font itself. Now move down to the next character, whose original definition is

(CHARACTER O 363
   (CHARWD R 0.686)
   (CHARHT R 0.904)
   (CHARDP R 0.084)
   (CHARIC R 0.029)
   )

Modify it so that it becomes

(CHARACTER O 363
   (CHARWD R 0.686)
   (CHARHT R 0.904)
   (CHARDP R 0.084)
   (CHARIC R 0.029)
   (VARCHAR
      (TOP O 363)
      (BOT O 365)
      (REP O 364)
      )
   )

(five lines have been added). This is the change that tells TeX how to build an extensible integral sign from the glyphs contained in slots 243, 244 and 245 (decimal) of the font; this extensible character is conventionally assigned to slot 243 itself.

That’s all: save the modified psyr.pl file (always, of course, in your current, private directory!) and convert it back to a .tfm file; say

pltotf psyr.pl psyr.tfm

so that the augmented file psyr.tfm is saved in the current directory too. This augmented file should be placed in a position on the file system where it takes precedence over the original psyr.tfm file: one possibility is to place it alongside (that is, in the same directory of) the .tex file you want to compile. Another choice is your local texmf tree, but remember that, if you do so, the modified psyr.tfm file will be used for all your documents that happen to use the symbol font, and this might create problems: I would recommend this choice only if you switched to a solution that employs a virtual font instead.


Defining a new delimiter in TeX

This part of the construction is easy, as NFSS offers you all the necessary tools. You can just mimick the following MWE:

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\makeatletter

\DeclareFontFamily{U}{psy}{\hyphenchar\font \m@ne}
\DeclareFontShape{U}{psy}{m}{n}{<-> psyr }{}
\DeclareSymbolFont{myExtensibleIntegralSign}{U}{psy}{m}{n}
\DeclareMathDelimiter{\extenintsign}{\mathop}
    {myExtensibleIntegralSign}{"F2}
    {myExtensibleIntegralSign}{"F3} % also "{operators}{0}" would work

\makeatother



\begin{document}

Text before.
\[
    \left\extenintsign
        \begin{pmatrix}
            a & b & c & d  \\
            e & f & g & h  \\
            i & j & k & l  \\
            m & n & o & p  \\ 
        \end{pmatrix}
    \right.
    dt
\]
Text after.

\end{document}

Remember that, in order for this to work, the modified psyr.tfm file must be loaded instead of the original one. If everything goes as expected, you will get the following output:

Output of the first code sample

Let us describe briefly what we have done.

  1. The first three lines of code after \makeatletter define a new symbol font called myExtensibleIntegralSign, that points to the psyr font. The family (or, in NFSS terminology, math group) number for this font is allocated automatically by \DeclareSymbolFont; in this particular case, it turns out that myExtensibleIntegralSign corresponds to family 4, but we are not concerned at all with this, since \DeclareMathDelimiter itself “knows” which is the right family number to use.

  2. The \DeclareMathDelimiter declaration defines a new delimiter, called \extenintsign, that can be used after \left or \right in the usual way. Note that, in our setting, the “large” variant of the delimiter ("F3) will never be used, because we included in the .tfm file itself information that leads from the “small” variant ("F2) to the larger one, which is also the extensible one; thus, specifying {operators}{0} as the last two arguments of \DeclareMathDelimiter would work too (note that the operators font corresponds to family 0), but including the pointer to the large, and extensible, variant makes the code more robust, in case the .tfm file lacked this information.

  3. Finally, in the equation we use our brand new \extenintsign delimiter in an ordinary \left/\right construction. Please, tell me—after all this blather—that it looks at least a tiny bit better than Steven’s stretched-out integral sign! (:-)


Adding limits

It remains to add the integration limits to our extensible integral sign. This is not trivial given the following two unfortunate circumstances:

  • TeX records \left and \right delimiters inside math lists as “boundary items”; but a boundary item is not an atom, hence it cannot carry subscripts or superscripts by itself.

  • An Op atom, on the other hand, can correspond to at most two printed symbols, that is, a small variant, used in non-display style, and a large variant, used in display style. TeX offers no provision for taking into account the size of the following subformula (the choice between the two sizes is based uniquely on the current style), and no more for making the size of the Op atom grow with it; just think of the fact that no syntactic provision, either, is made to determine where such a subformula would end.

This means that we must have recourse to some trick, in a way or another. Here is one of the possibilities (it is a complete, compilable example):

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\makeatletter

\DeclareFontFamily{U}{psy}{\hyphenchar\font \m@ne}
\DeclareFontShape{U}{psy}{m}{n}{<-> psyr }{}
\DeclareSymbolFont{myExtensibleIntegralSign}{U}{psy}{m}{n}
\DeclareMathDelimiter{\extenintsign}{\mathop}
    {myExtensibleIntegralSign}{"F2}
    {myExtensibleIntegralSign}{"F3} % also "{operators}{0}" would work

\newcommand*\extenint[3]{\mathpalette\@extenint{{#1}{#2}{#3}}}
\newcommand*\@extenint[2]{\@@extenint#1#2}
\newcommand*\@@extenint[4]{%
    \mathop{\hbox{$#1\left\extenintsign\vphantom{#4}\right.\n@space$}}%
        \ilimits@ % honor amsmath.sty
        \ifx\@empty#2\@empty\else _{\!#2}\fi
        \ifx\@empty#3\@empty\else ^{\,#3}\fi
    #4
}
% We define the following two commands for testing purposes only:
\newcommand*\forcelimits  {\let \ilimits@ \limits  }
\newcommand*\forcenolimits{\let \ilimits@ \nolimits}

\makeatother



\begin{document}

With one row:
\begin{align*}
    \extenint{-\infty}{+\infty}
        {\begin{pmatrix}
            a & b & c & d  \\
        \end{pmatrix}}
    dt
    && \forcelimits
    \extenint{-\infty}{+\infty}
        {\begin{pmatrix}
            a & b & c & d  \\
        \end{pmatrix}}
    dt
\end{align*}

With two rows:
\begin{align*}
    \extenint{-\infty}{+\infty}
        {\begin{pmatrix}
            a & b & c & d  \\
            e & f & g & h  \\
        \end{pmatrix}}
    dt
    && \forcelimits
    \extenint{-\infty}{+\infty}
        {\begin{pmatrix}
            e & f & g & h  \\
            a & b & c & d  \\
        \end{pmatrix}}
    dt
\end{align*}

With four rows:
\begin{align*}
    \extenint{-\infty}{+\infty}
        {\begin{pmatrix}
            a & b & c & d  \\
            e & f & g & h  \\
            i & j & k & l  \\
            m & n & o & p  \\ 
        \end{pmatrix}}
    dt
    && \forcelimits
    \extenint{-\infty}{+\infty}
        {\begin{pmatrix}
            e & f & g & h  \\
            a & b & c & d  \\
            i & j & k & l  \\
            m & n & o & p  \\ 
        \end{pmatrix}}
    dt
\end{align*}

With six rows:
\begin{align*}
    \extenint{-\infty}{+\infty}
        {\begin{pmatrix}
            a & b & c & d  \\
            e & f & g & h  \\
            i & j & k & l  \\
            m & n & o & p  \\ 
            q & r & s & t  \\ 
            u & v & w & x  \\ 
        \end{pmatrix}}
    dt
    && \forcelimits
    \extenint{-\infty}{+\infty}
        {\begin{pmatrix}
            e & f & g & h  \\
            a & b & c & d  \\
            i & j & k & l  \\
            m & n & o & p  \\ 
            q & r & s & t  \\ 
            u & v & w & x  \\ 
        \end{pmatrix}}
    dt
\end{align*}

However, this does not look good:
\begin{align*}
    \extenint{-\infty}{+\infty}{dt}
    && \forcelimits
    \extenint{-\infty}{+\infty}{dt}
\end{align*}
(I mean, at least the left alternative: the right one could still look
acceptable).  Indeed, comparison with the ``normal'' integral
\begin{align*}
    \int_{-\infty}^{+\infty} dt
    && \forcelimits
    \int_{-\infty}^{+\infty} dt
\end{align*}
shows that, in display size, \verb|\extenint| is too small.

\end{document}

Again, the “right” psyr.tfm file must be loaded; if so, the output will look like the following:

Output of the second code sample

As you see, we have defined the \extenint command, which takes three arguments: the lower integration limit, the upper integration limit, and the integrand—or, at least, the part of it to the size of which the integral sign should conform. This command typesets the integral sign in the appropriate size and with the specified limits, as well as the (part of the) integrand itself. Note that, with this construction, it is not possible to add \limits, \nolimits, or \displaylimits to the integral sign; however, since we have loaded the amsmath package, we do honor its definition of \ilimits@ in the code that defines the \extenint command.

Some further remarks are in order:

  1. Appendix G of The TeXbook explains that, when the nucleus of an Op atom consists of a single character (which is the ordinary case), the limits for that atom are both shifted, in opposite directions, by half the amount of the italic correction for the character in question: see Rule 13a for the “\limits case” and Rule 18f for the “\nolimits case”, which coincides with the general rule applied to atoms which have both a subscript and a superscript. This does not happen in our case, because the nucleus of our Op atom is not a single character. We compensate for this by adding \! and \, in front of the subscript and of the superscript, respectively. This simple correction seems to work pretty well both in the \nolimits and in the \limits case, but you might want to fine-tune the amount of kerning.

  2. However, this corrections does not look adequate if the smaller integral sign happens to be chosen, at least in the \nolimits case. This should probably be fixed.

  3. Moreover, the bigger (and extensible) variant of the integral sign is not automatically chosen in display style, once again because the nucleus of the relevant Op atom is not a single character (see Rule 13). This should be corrected too.

Maybe that someone (or even myself) will volunteer to write a well-crafted package that makes this extensible integral sign available, and in which all these issues are addressed.

But for now, I think this more than enough. (:-)

5
  • Very interesting! Why don't you just add the required fontdimen?
    – egreg
    Commented Jul 11, 2015 at 22:29
  • Do you mean, \fontdimen7? Do you know if some package loads the Symbol font and, if so, whether it adds any \fontdimen parameter?
    – GuM
    Commented Jul 11, 2015 at 22:37
  • I don't think there are packages that use psyr. And setting the fontdimen should not be a big concern. However, I'd go for a different name.
    – egreg
    Commented Jul 11, 2015 at 22:38
  • Wow. Very impressive. Commented Jul 11, 2015 at 23:52
  • Wonderfull solution, if you want to add support for optional sub- or superscripts, xparse may come in handy, so someone can write \xint f(x) \d x` or \xint_{D} <whatever> \d x, etc. and that \xint takes everything until \d and measures. It could be messy at code level, but for the user may be simpler.
    – Manuel
    Commented Jul 12, 2015 at 23:32

You must log in to answer this question.

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