3

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.

5
  • So, do you also want to generate x\to\inft0 in \textstyle rather than the default \scriptstyle mode?
    – Mico
    Dec 22, 2020 at 3:14
  • 1
    I’m open to either option. Don’t have a preference either way.
    – Rain
    Dec 22, 2020 at 5:04
  • 2
    I think this is a really bad idea.
    – Carsten S
    Dec 22, 2020 at 13:32
  • You really need to learn how to write mathematics!
    – John B
    Dec 22, 2020 at 22:41
  • ...Right. Because I don’t like how most people write something and I choose to write it a little differently? So if most people write πr² and I write r²π that means I don’t now how to write mathematics?
    – Rain
    Dec 22, 2020 at 22:50

4 Answers 4

6

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.
\newcommand\mylimA[1]{% first solution idea
   \mathop{\vcenter{\hbox{$\thickmuskip0mu\lim\limits_{\textstyle #1}$}}}}
\newcommand\mylimB[1]{% second solution idea
   \mathop{\vcenter{\hbox{$\lim\limits_{#1}$}}}}
\newcommand\ffg{\frac{f(x)}{g(x)}} % handy shortcut macro

\begin{document}
\begin{gather*}
\mylimA{x\to0} f(x) \qquad \mylimB{x\to0} f(x) \qquad \lim_{x\to0} f(x) \\
\mylimA{x\to0} \ffg \qquad \mylimB{x\to0} \ffg \qquad \lim_{x\to0} \ffg
\end{gather*}
\end{document}
1
  • Thanks! This does exactly what I want. :)
    – Rain
    Dec 22, 2020 at 8:14
6

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}\limits\IfValueT{#1}{_{#1}}
  \end{array}\!
  \mathop{}
}

\begin{document}

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

\end{document}

enter image description here

2
  • Thanks! I hate inline maths that are taller than a single line of normal text. My rule is to use inline maths iff the entire expression can be written in such a way that it's at most as tall as a line of text and at most as wide as the text column AND the expression doesn't require an equation number and isn't one of the main results of whatever I'm writing. So don't worry, I would never use a limit inline. Still prefer the right one in display mode.
    – Rain
    Dec 22, 2020 at 8:18
  • 5
    @Rain Check with some random calculus books and report how many of them use your notation. My bet is on “none”. ;-)
    – egreg
    Dec 22, 2020 at 8:31
4

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}
\def\mylim_#1{\mathop{\begin{array}{@{}c@{}}\text{lim}\\[-1.333ex]
\scriptstyle #1\end{array}}}
\begin{document}
New:
\[ \mylim_{x\to0}f(x)\quad\text{and}\quad \mylim_{x\to0}\frac{f(x)}{x}\]
Conventional:
\[ \lim_{x\to0}f(x)\quad\text{and}\quad \lim_{x\to0}\frac{f(x)}{x}\]
\end{document}

enter image description here

2
  • Thanks! Will test once I get to my computer, but your screenshot looks exactly like what I want.
    – Rain
    Dec 22, 2020 at 5:05
  • Works nicely. However, the hard linebreak spacing (–1.333ex in your example) doesn't work for all font families, font sizes and limits. For example, if I have a limit where the variable approaches something tall (e.g. a fraction), the spacing no longer works. This means that if I have limits where the quantities approached by the variables (or the variables themselves) have different heights I need to use different commands (or set the linebreak spacing as a separate parameter of the operator, which is easy enough but a little annoying).
    – Rain
    Dec 22, 2020 at 8:11
4

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}

\newcommand\vcenterop[2]{%
  \edef\savedstyle{\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.5\argheight}{\usebox{\opbox}}} \mathord{\usebox{\argbox}}
}

\begin{document}

\begin{align*}
  &\textstyle\vcenterop{\lim_{x \to 0}}{f(x)} &\textstyle\vcenterop{\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}

\newcommand\vcenterop[2]{%
  \edef\savedstyle{\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.5\argheight}{\usebox{\opbox}}} \mathord{\usebox{\argbox}}
}

\begin{document}

\begin{align*}
  &\textstyle\vcenterop{\lim_{x \to 0}}{f(x)} &\textstyle\vcenterop{\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

1

You must log in to answer this question.

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