# Microtypography on equations

Is there a way to make all three lines of math in the code below take up the same amount of length by use of font expansion? I know too little about microtype to even see if it could offer a solution. I don't care too much about the exact math environment that'll be used in the end (gather is not too bad a solution if I can't get expansion working).

Bonus if the solution works with lualatex, and especially the \usefonttheme{professionalfonts} of beamer.

Alas, changing variable and function names is not an option (basically, only the square braces may change if that can help).

Alternatively, one could try to tweak the spacings manually, but except by trial and error using \hspaces, would there be an intelligent way of doing that (say, aligning the absolute values on top of each other, and the total length of each line being the same?)

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsfonts}

\begin{document}

\begin{align*}
\lim_{y\to\infty}\sup_{x\in\mathbb{R}} \left\vert y^{5/2-\varepsilon}\left[\vphantom{A^2}u(x,y)-u_{\mathrm{as}}(x,y)\right]\right\vert & = 0 \\
\lim_{y\to\infty}\sup_{x\in\mathbb{R}} \left\vert y^{5/2-\varepsilon}\left[\vphantom{A^2}v(x,y)-v_{\mathrm{as}}(x,y)\right]\right\vert & = 0 \\
\lim_{y\to\infty}\sup_{x\in\mathbb{R}} \left\vert y^{9/2-\varepsilon}\left[\vphantom{A^2}\omega(x,y)-\omega_{\mathrm{as}}(x,y)\right]\right\vert & = 0
\end{align*}

\end{document}


Present output:

-
Should I perhaps change the question title? Looking at the answers, I'm wondering if it is misleading. – Christoph B. May 1 '13 at 12:37
Christoph: Steven and Andrew's solutions are furthest away from the technique you wanted to apply (they change space but not the width of characters), but are the probably the best solutions to the actual problem you presented (see meta.tex.stackexchange.com/questions/2449/…). I think it's usually best not to change the content of questions, since the answers exist already, but if you can influence the kind of answer you get by changing the question title, that is OK. – Charles Stewart May 1 '13 at 13:02
@Charles Stewart: Ok, I really would love to see a font expansion solution, but I now understand thanks to your answer that that's really complicated. So the question remains, but I'm perfectly happy to upvote all solutions so far. – Christoph B. May 1 '13 at 13:49
I don't think you really want a font expansion solution. That would make the letters on each line have slightly different proportions, and by design they would be directly aligned vertically...so those differences would be apparent to the casual eye. It could end up looking really bad. Expanding whitespace is better because we skip over it. – Ryan Reich May 1 '13 at 13:55
Good point @RyanReich! – Christoph B. May 1 '13 at 15:14

Each of the left hand sides has some glue, so you can put them in boxes and stretch them to the same size:

\documentclass{article}

\usepackage{mathtools}
\usepackage{amsfonts}

\makeatletter
\newcommand{\mydmath}[1]{$$\m@th\displaystyle #1$$}
\makeatother
\newcommand{\mydmathtowd}[2]{\hbox to #1{\mydmath{#2}}}
\newsavebox\mytmpbox

\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}

\begin{document}

\abs[\Big]{y^{9/2-\varepsilon}\bigl[\omega(x,y)-\omega_{\mathrm{as}}(x,y)\bigl]}}}
\begin{align*}
\abs[\Big]{y^{5/2-\varepsilon}\bigl[\vphantom{A^2}u(x,y)-u_{\mathrm{as}}(x,y)\bigr]}}
& = 0 \\
\abs[\Big]{y^{5/2-\varepsilon}\bigl[\vphantom{A^2}v(x,y)-v_{\mathrm{as}}(x,y)\bigr]}}
& = 0 \\
\usebox\mytmpbox & = 0
\end{align*}

\end{document}


This code boxes up the last left-hand side, which is the longest, and uses the width of that box for the other two. I have added helper macros for much of this.

Other unrelated changes

• \adjustlimits to get the heights of the limits under lim and sup to harmonize
• introduction of \abs for the vertical lines
• fixed sized delimiters instead of \left/\right

ADDED All the above works in beamer and with lualatex

\documentclass{beamer}

\usetheme{Warsaw}

\usepackage{mathtools}
\usepackage{amsfonts}

\makeatletter
\newcommand{\mydmath}[1]{$$\m@th\displaystyle #1$$}
\makeatother
\newcommand{\mydmathtowd}[2]{\hbox to #1{\mydmath{#2}}}
\newsavebox\mytmpbox

\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}

\begin{document}

\begin{frame}
\abs[\Big]{y^{9/2-\varepsilon}\bigl[\omega(x,y)-\omega_{\mathrm{as}}(x,y)\bigl]}}}
\begin{align*}
\abs[\Big]{y^{5/2-\varepsilon}\bigl[\vphantom{A^2}u(x,y)-u_{\mathrm{as}}(x,y)\bigr]}}
& = 0 \\
\abs[\Big]{y^{5/2-\varepsilon}\bigl[\vphantom{A^2}v(x,y)-v_{\mathrm{as}}(x,y)\bigr]}}
& = 0 \\
\usebox\mytmpbox & = 0
\end{align*}
\end{frame}

\end{document}

-
Your use of the glue is indeed, for now, the nearest solution given the limits detailed by @Charles Andrew. It's very clever! – Christoph B. May 1 '13 at 13:51
Response to the edit: yes, I actually already used your solution in my beamer presentation compiled with lualatex. So you're in for the bounty as soon as I can give it out! – Christoph B. May 6 '13 at 11:19

I know this is not what you asked for (an XY problem) and really ad hoc, but it's how I would solve the problem. You can adjust the spacing by making the different characters appear to have the same width. For instance \phantom{\omega}\mathrlap{u} creates a u that takes up as much space as an \omega. (Though the u is aligned to the right of this box.) So I would try something like:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}

\newcommand{\sizeof}[2]{\phantom{#1}\mathllap{#2}}
\begin{document}

\begin{align*}
\lim_{y\to\infty}\sup_{x\in\mathbb{R}} \left\vert y^{5/2-\varepsilon}\left[\vphantom{A^2}\sizeof{\omega}{u}(x,y)-\sizeof{\omega}{u}_{\mathrm{as}}(x,y)\right]\right\vert & = 0 \\
\lim_{y\to\infty}\sup_{x\in\mathbb{R}} \left\vert y^{5/2-\varepsilon}\left[\vphantom{A^2}\sizeof{\omega}{v}(x,y)-\sizeof{\omega}{v}_{\mathrm{as}}(x,y)\right]\right\vert & = 0 \\
\lim_{y\to\infty}\sup_{x\in\mathbb{R}} \left\vert y^{9/2-\varepsilon}\left[\vphantom{A^2}\omega(x,y)-\omega_{\mathrm{as}}(x,y)\right]\right\vert & = 0
\end{align*}

\end{document}


(\mathrlap is provided by the mathtools package.) This looks closer to having all lines the same length, and most readers will not notice that you've inserted some space between the open bracket and u or v. You could further tweak by adjusting the exponents of y.

-

I suggest using IEEEeqnarray environment from the IEEEtrantools package. For each column you choose type l and put an alignment mark right after the symbol that causes misalignment (u, v and omega in this case). You can learn more tricks like this here.

Here is the code:

\documentclass{article}

\usepackage{IEEEtrantools}

\usepackage{amsmath}
\usepackage{amsfonts}

\begin{document}

\begin{IEEEeqnarray*}{lll}
\lim_{y\to\infty} \sup_{x\in\mathbb{R}} \Big\vert y^{5/2-\varepsilon} \big[u&(x,y) - u_{\mathrm{as}}&(x,y) \big]\Big\vert = 0 \\
\lim_{y\to\infty} \sup_{x\in\mathbb{R}} \Big\vert y^{5/2-\varepsilon} \big[v&(x,y) - v_{\mathrm{as}}&(x,y) \big]\Big\vert = 0 \\
\lim_{y\to\infty} \sup_{x\in\mathbb{R}} \Big\vert y^{9/2-\varepsilon} \big[\omega&(x,y) - \omega_{\mathrm{as}}&(x,y) \big]\Big\vert = 0
\end{IEEEeqnarray*}

\end{document}


Here is the output:

Note. Instead of using \vphantom, you can just manually specify the size of your brackets with commands like \big, \Big, etc.

-

The problem that font expansion exists to solve is reducing the badness of certain line breaks at word boundaries so that you can reduce the amount of hyphenation. This isn't the problem you face here - you want to stretch fonts to solve a quite different problem, namely to stretch part of a formula to get glyphs to line up. So essentially what you need is to manually control font expansion.

I think this is essentially impossible with regular Pdftex: font expansion basically happens behind the scenes and cannot be tampered with. I don't know if it can be done with Xetex, but I would guess the situation is the same.

Luatex offers more possibilities to interface with Tex's internal processes. The Luatex guide says (in its documentation of tex.linebreak, Luatex's interface to the line breaking algorithm):

You cannot inﬂuence font expansion other than via pdfadjustspacing, because the settings for that take place elsewhere

which suggests that you cannot do anything before the layout is done. Luatex does allow you to revisit what it has set, though, and it may be the case that you can go back and change the line expansion properties of glyphs and space afterwards. This sounds like hard work.

But you can do this via external programs. For instance, you could invoke Metapost with the parts of the formula as Tex labels, and Metapost will be able to calculate what stretching is required and apply the needed geometric transformation to the formula. It seems likely to me that you can do this with PGF as well.

-

I set up a stencil for the equation to be repeated. Above is the original, below with the stencil. [EDITED for better justification]

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsfonts}

\newsavebox{\parm}
\newcommand\parmbox[2]{\savebox{\parm}[#1]{\hfill$#2$}\usebox{\parm}}
\newcommand\eqstencil[2]{%
\lim_{y\to\infty}\sup_{x\in\mathbb{R}} \left\vert
y^{\parmbox{.17in}{\scriptstyle#1}-\varepsilon}
\left[\vphantom{A^2}\parmbox{.1in}{#2}(x,y)-
\parmbox{.1in}{#2}_{\mathrm{as}}(x,y)\right]\right\vert
& = 0}

\begin{document}

\begin{align*}
\lim_{y\to\infty}\sup_{x\in\mathbb{R}} \left\vert y^{5/2-\varepsilon}\left[\vphantom{A^2}u(x,y)-u_{\mathrm{as}}(x,y)\right]\right\vert & = 0 \\
\lim_{y\to\infty}\sup_{x\in\mathbb{R}} \left\vert y^{5/2-\varepsilon}\left[\vphantom{A^2}v(x,y)-v_{\mathrm{as}}(x,y)\right]\right\vert & = 0 \\
\lim_{y\to\infty}\sup_{x\in\mathbb{R}} \left\vert y^{9/2-\varepsilon}\left[\vphantom{A^2}\omega(x,y)-\omega_{\mathrm{as}}(x,y)\right]\right\vert & = 0
\end{align*}

\begin{align*}
\eqstencil{5/2}{u}\\
\eqstencil{5/2}{v}\\
\eqstencil{9/2}{\omega}\\
\end{align*}
\end{document}


-

Just for variety, the following centers u and v in the space.

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}

\newlength{\len}
\settowidth{\len}{$\omega$}
\newcommand{\cu}{\makebox[\len][c]{$u$}}
\newcommand{\cv}{\makebox[\len][c]{$v$}}

\begin{document}

\begin{align*}
\lim_{y\to\infty}\sup_{x\in\mathbb{R}} \left\vert y^{5/2-\varepsilon}\left[\vphantom{A^2}\cu(x,y)-\cu_{\mathrm{as}}(x,y)\right]\right\vert & = 0 \\
\lim_{y\to\infty}\sup_{x\in\mathbb{R}} \left\vert y^{5/2-\varepsilon}\left[\vphantom{A^2}\cv(x,y)-\cv_{\mathrm{as}}(x,y)\right]\right\vert & = 0 \\
\lim_{y\to\infty}\sup_{x\in\mathbb{R}} \left\vert y^{9/2-\varepsilon}\left[\vphantom{A^2}\omega(x,y)-\omega_{\mathrm{as}}(x,y)\right]\right\vert & = 0
\end{align*}

\end{document}


-