5

The automatic brackets sizing provided by \left ... \right really often produces too large brackets. I want some package that for a given formula finds the right bracket size selected from \big, \Big, \bigg, \Bigg which in situations like the below (left is automatically sized, right is using \big) enter image description here

doesn't choose the smallest option which is larger than the formula but maybe the one that might technically be a bit too small (heuristically sth. like: If the distance from the technically smaller one to the highest point of my formula is smaller than the distance of the larger one to the highest point of my formula, then rather choose the smaller one).

My questions are:

  1. Do you know of any such package
  2. If not, how difficult would you think would programming sth. like this be (for someone who is unexperienced in Tex programming)?
2
  • Are you familiar with the mathtools package (a superset of the amsmath package) and its \DeclarePairedDelimiter macro?
    – Mico
    Commented Jul 13, 2023 at 19:58
  • @Mico I have heard of both but am not familiar with it. Would you be so kind to elaborate?
    – Nicolas
    Commented Jul 13, 2023 at 20:01

2 Answers 2

5

I want some package that for a given formula finds the right bracket size [automatically].

I'm afraid you might as well start looking for the Holy Grail :-) Seriously: When Knuth created TeX, he wasn't able to come up with a routine that, for each and every conceivable formula, would determine the "correct" delimiter size automatically -- and neither has anybody else in the past 40+ years. Deep down, I suspect this is because fine typography is as much an art as it is a craft. Given enough time and resources, craftsmanship may be (largely) automated eventually. In contrast, I doubt that art can ever be automated, likely because art involves personal sensibilities that are highly specific to each individual. A piece of artwork that "speaks" to some persons may leave others entirely cold, right?

The mathtools package provides a macro called \DeclarePairedDelimiter that greatly simplifies creating macros that place delimiters of some shape and size to the left and right of the macro's argument. E.g,.

\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}

creates two macros: \norm*, which sizes the delimiters automatically, and \norm, which takes an optional argument to set the delimiters' desired size. E.g., \norm[\big]{...} sets the double-vertical bars to their \big size.

While I suspect (hope?!) that most of us are willing to agree with the claim that the automatically-sized delimiters are too large for a simple formula such as \hat{f}, I also suspect that it's quite unlikely that there will be any such consensus on whether \norm{\hat{f}} or \norm[\big]{\hat{f}} produces the better outcome.

Importantly, the decision may also depend on whether or not there's a "subscript" term to the norm term. Speaking for myself (who else?!), I may well believe that \norm[\big]{\hat{f}} somehow "looks better" (just "slightly better", really) than \norm{\hat{f}} does (see the second row). Yet I may also believe that \norm{\hat{f}}^{}_{L^1(\mathbf{R}^d)} "looks better" than \norm[\big]{\hat{f}}_{L^1(\mathbf{R}^d)}, possibly because the former expression makes an effort to hand-adjust (see the ^{} particle) the vertical position of the subscript-position term (here: L^1(\mathbf{R}^d)). In the end, the "correct" positioning of the subscript may be more important than the size of the vertical delimiters for the overall aesthetic appeal.

enter image description here

\documentclass{article} % or some other suitable document class
\usepackage{mathtools}  % for '\DeclarePairedDelimiter' macro
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}

\begin{document}
$-\left\Vert \hat{f} \right\Vert_{L^1(\mathbf{R}^d)} % automatic sizing
  \
  \norm*{\hat{f}}_{L^1(\mathbf{R}^d)}
  \
  \norm{\hat{f}}_{L^1(\mathbf{R}^d)}
  \
  \norm[\big]{\hat{f}}_{L^1(\mathbf{R}^d)}
  \
  \norm{\hat{f}}^{}_{L^1(\mathbf{R}^d)}-$

\bigskip

$-\left\Vert \hat{f} \right\Vert % automatic sizing
  \
  \norm*{\hat{f}}
  \
  \norm{\hat{f}}
  \
  \norm[\big]{\hat{f}}-$
\end{document}
12
  • Ah ok, now I see what you mean. Actually I don't need any macros as I'm using a snippet tool (e.g. if I type l1 it automatically expands to \left\| ... \right\|_{...}). Thanks a lot for the answer though! I also agree to what you wrote, but would still like to code some package which somewhat does this automatic sizing based on my personal preferences regarding typography. I just don't have any idea where to start if I wanted to do this (like how to access the current height of my formula usw.)
    – Nicolas
    Commented Jul 13, 2023 at 20:59
  • @Nicolas - I would start using the basic \norm macro -- not \norm*, or \norm[\big] or \norm[\Big] -- everywhere, throughout the entire document. Once you're done with the contents of the paper, you can turn to deciding which \norm terms could benefit from getting their delimiters' sizes increased a bit.
    – Mico
    Commented Jul 13, 2023 at 21:11
  • Interestingly I prefer the spacing of \| \| over \lVert \rVert :)
    – Nicolas
    Commented Jul 13, 2023 at 21:15
  • Do you have any resource recommendation how to get started with Tex programming? It would probably be helpful to look at the source code of the automatic sizing available in latex, but I don't even know where to locate this.
    – Nicolas
    Commented Jul 13, 2023 at 21:17
  • 1
    Of course +1! I will wait a bit with accepting, maybe someone else comes up with an idea how I could realise it ... In theory it seemed so simple :)
    – Nicolas
    Commented Jul 13, 2023 at 22:27
0

In the end I solved my problem by writing a (Julia) script which goes over the typed tex code and replaces the parenthesis in a predefined style. Of course this is an extra step and up until running the script one won't see the correctly sized parenthesis in the rendered pdf, but apart from this it works well.

3
  • 1
    Although this answer solved your problem, it's not particularly helpful to others. Perhaps you could share the script you wrote and show how it's used?
    – Alan Munn
    Commented Dec 5, 2023 at 15:07
  • @AlanMunn Yes, this is exactly my plan. I'm currently working on making it an easy to use application and will then update the answer.
    – Nicolas
    Commented Dec 5, 2023 at 15:40
  • Great! That would be very helpful.
    – Alan Munn
    Commented Dec 5, 2023 at 17:05

You must log in to answer this question.

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