TransWikia.com

How can I adjust the vertical positioning of lim so the argument is aligned with the whole limit stack rather than just the word "lim"?

TeX - LaTeX Asked on February 25, 2021

Consider the following image:

enter image description here

The top row is how I write limits and what I want LaTeX to do. Notice how the stack formed by "lim" on top and "x->0" on the bottom is aligned with the argument (f(x) or f(x)/g(x) in this case).

The bottom row is what LaTeX does. Note that only the word "lim" is algned with the argument; the "x->0" bit is treated as a sort of subscript.

I get that this hapens because lim, sum, prod and int are treated in the same way (the argument of the operation is aligned with the operation’s symbol and the sub- and superscripts are not taken into account for this alignment), but I’d like to change this.

I guess it’s just what I’m used to. Sums, products and integrals usually have either stuff above and below the symbol or no stuff at all. The only common exceptions to this (at least in my field) are when you only write the index of a sum (because the lower and upper bounds are evident) or when you write the symbol of a region of integration below the integral symbol (because that’s easier than writing the integration limits explicitly or you don’t know the integration limits), and in those cases it’s expected for the space under the operator’s symbol to contain text and the space over it to be empty, so it doesn’t look ugly to me. Conversely, limits never have text above the "lim" symbol, only below it, so the asymmetry looks strange to me.

Is there a simple way to change this behaviour globally? I don’t want to use stackrel or similar every time I want to write a limit.

Thanks.

4 Answers

Here are two solutions that employ the vcenter and hbox primitives to raise the lim_{...} expression so that it's centered vertically on the math axis. The first solution typesets the argument in textstyle, whereas the second uses the standard scriptstyle for the argument. The following screenshot also shows the output of lim. (For what my opinion is worth, I like the output of lim best.)

enter image description here

documentclass{article}
usepackage{amsmath} % for 'gather*' env.
newcommandmylimA[1]{% first solution idea
   mathop{vcenter{hbox{$thickmuskip0mulimlimits_{textstyle #1}$}}}}
newcommandmylimB[1]{% second solution idea
   mathop{vcenter{hbox{$limlimits_{#1}$}}}}
newcommandffg{frac{f(x)}{g(x)}} % handy shortcut macro

begin{document}
begin{gather*}
mylimA{xto0} f(x) qquad mylimB{xto0} f(x) qquad lim_{xto0} f(x) \
mylimA{xto0} ffg qquad mylimB{xto0} ffg qquad lim_{xto0} ffg
end{gather*}
end{document}

Correct answer by Mico on February 25, 2021

I don't think I have seen this anywhere else.

usepackage{amsmath}
%usepackage{xparse}

NewDocumentCommand{blim}{e{_}}{%
  mathop{}!
  begin{array}{@{}c@{}}% just for vertical centering
  operatorname*{lim}limitsIfValueT{#1}{_{#1}}
  end{array}!
  mathop{}
}

begin{document}

I'm fearing you want this just to get $blim_{xto0}f(x)$ inline. Please,
don't. Here's display mode:
[
a+lim_{xto0}f(x)qquad a+blim_{xto0}f(x)
]
and with a fraction
[
a+lim_{xto0}frac{f(x)}{g(x)}qquad a+blim_{xto0}frac{f(x)}{g(x)}
]
Left is the standard, right the bad one.

end{document}

enter image description here

Answered by egreg on February 25, 2021

Here’s a solution, which raises or lowers the median of any operator to the median of its argument.

documentclass{article}
usepackage{amsmath}
usepackage{settobox}
usepackage[noactivechars]{mathstyle}

newsavebox{opbox}
newsavebox{argbox}
newlength{opheight}
newlength{opdepth}
newlength{argheight}
newlength{argdepth}

newcommandvcenterop[2]{%
  edefsavedstyle{currentmathstyle}
  savebox{opbox}{(savedstyle #1)}
  savebox{argbox}{(savedstyle #2)}
  settoboxheight{opheight}{opbox}
  settoboxdepth{opdepth}{opbox}
  settoboxheight{argheight}{argbox}
  settoboxdepth{argdepth}{argbox}
  addtolength{argheight}{-opheight}
  addtolength{argheight}{-argdepth}
  addtolength{argheight}{opdepth}
  mathop{raisebox{0.5argheight}{usebox{opbox}}} mathord{usebox{argbox}}
}

begin{document}

begin{align*}
  &textstylevcenterop{lim_{x to 0}}{f(x)} &textstylevcenterop{lim_{x to 0}}{frac{f(x)}{g(x)}} \
  &vcenterop{lim_{x to 0}}{f(x)} &vcenterop{lim_{x to 0}}{frac{f(x)}{g(x)}} \
  &lim_{x to 0} f(x)              &lim_{x to 0} frac{f(x)}{g(x)} \
  &vcenterop{log_2}{f(x)^2}       &vcenterop{log_2}{frac{f(x)^2}{g(x)^2}} \
  &log_2 f(x)^2      &log_2 frac{f(x)^2}{g(x)^2}
end{align*}

end{document}

Sample layout

It would also be possible to raise or lower the argument rather than the operator, or to center both on the math axis as Mico does for lim.

By Sebastiano’s Request

Here’s what it looks like with some handwritten fonts.

documentclass{article}
usepackage{unicode-math}
usepackage{settobox}
usepackage[noactivechars]{mathstyle}

defaultfontfeatures{ Ligatures=TeX, Scale=MatchLowercase }
% Tillana is a free font by the Indian Type Foundry, available at:
% https://github.com/itfoundry/tillana/
% VAG Handwritten is a free font by VAG Design, available at:
% https://www.fontsquirrel.com/fonts/VAG-HandWritten
setmainfont{VAG-HandWritten.otf}
setmathfont{GFS Neohellenic Math}
setmathfont[range={"03C0, "2013-"2014, "2018-"201A, "201C-"201E, "2021-"2022,
                    "2026, "2030, "2039-"203A, "2044, "20AC, "20BA, "20BD,
                    "2113, "2122, "2126, "212E, "2202, "2206, "220F, "2211,
                    "2212, "2215, "221A, "221E, "222B, "2246, "2260, "2264,
                    "2265, "25CA}
            ]{Tillana-Regular.otf}
setmathfont[range=bfup/{Latin,latin,num}
            ]{Tillana-Semibold.otf}
setmathfont[range={"00-"FF,
                    up/{Latin,latin,Greek,greek},
                    increment}
            ]{VAG-HandWritten.otf}
setmathfont[range=up/num
            ]{Tillana-Regular.otf}

newsavebox{opbox}
newsavebox{argbox}
newlength{opheight}
newlength{opdepth}
newlength{argheight}
newlength{argdepth}

newcommandvcenterop[2]{%
  edefsavedstyle{currentmathstyle}
  savebox{opbox}{(savedstyle #1)}
  savebox{argbox}{(savedstyle #2)}
  settoboxheight{opheight}{opbox}
  settoboxdepth{opdepth}{opbox}
  settoboxheight{argheight}{argbox}
  settoboxdepth{argdepth}{argbox}
  addtolength{argheight}{-opheight}
  addtolength{argheight}{-argdepth}
  addtolength{argheight}{opdepth}
  mathop{raisebox{0.5argheight}{usebox{opbox}}} mathord{usebox{argbox}}
}

begin{document}

begin{align*}
  &textstylevcenterop{lim_{x to 0}}{f(x)} &textstylevcenterop{lim_{x to 0}}{frac{f(x)}{g(x)}} \
  &vcenterop{lim_{x to 0}}{f(x)} &vcenterop{lim_{x to 0}}{frac{f(x)}{g(x)}} \
  &lim_{x to 0} f(x)              &lim_{x to 0} frac{f(x)}{g(x)} \
  &vcenterop{log_2}{f(x)^2}       &vcenterop{log_2}{frac{f(x)^2}{g(x)^2}} \
  &log_2 f(x)^2      &log_2 frac{f(x)^2}{g(x)^2}
end{align*}

end{document}

Tillana/VAG sample

Answered by Davislor on February 25, 2021

I am not sure if this is a good idea, here is something along these lines. Notice that mylim is not as robust as a normal lim, so you really need to add _<something>.

documentclass{article}
usepackage{amsmath}
defmylim_#1{mathop{begin{array}{@{}c@{}}text{lim}\[-1.333ex]
scriptstyle #1end{array}}}
begin{document}
New:
[ mylim_{xto0}f(x)quadtext{and}quad mylim_{xto0}frac{f(x)}{x}]
Conventional:
[ lim_{xto0}f(x)quadtext{and}quad lim_{xto0}frac{f(x)}{x}]
end{document}

enter image description here

Answered by user231225 on February 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP