4

Using this code it can be seen that the epsilon symbol and R are vertically misaligned. Is there a way to fix this?

display

MWE:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$ \forall x \in {\rm I\!R} $, $x$
\end{document}
Heiko Oberdiek
  • 271,626
Συλχαν
  • 65
  • 1
  • 5
  • 15
    a) There is no epsilon symbol. b) The symbol "element of" (U+2208) is vertically aligned at the math axis like the minus or plus symbol. c) R is correctly set on the base line, but the horizontal space between "element of" and "R" is too small. d) If the code is not plain TeX, then do not use $$ in LaTeX, see "Why is \[ … \] preferable to $$?". e) The snippet should be extended to a full minimal working example (MWE) to show the fonts that are used. f) Last but not least, welcome to TeX.SX! – Heiko Oberdiek Feb 10 '18 at 02:50
  • Thanks for the answer! How would I go on about writing the following line of tex within [ ... ]? $ \forall x \in & ${I!R}$ $. As you see, we have two pairs of $$ here. – Συλχαν Feb 10 '18 at 03:41
  • 1
  • The minimal working example is provided in the thread now. – Συλχαν Feb 10 '18 at 04:12
  • @HeikoOberdiek There is an epsilon symbol. It just isn't in the OP's example. I mean, you don't produce it with \in but with \epsilon. – cfr Feb 10 '18 at 04:27
  • 1
    @cfr - I'm pretty sure that when Heiko wrote "there is no epsilon symbol", he was referring exclusivley to the OP's screenshot. – Mico Feb 10 '18 at 09:21
  • 1
    @Mico Yes, I know. But the OP might not. – cfr Feb 10 '18 at 16:33
  • The output shown in the picture cannot have been generated by the code you posted; indeed, the subformula {\rm I\!R} gets packaged in an Ord atom, and TeX inserts a thicj space between a Rel atom (like \in) and an Ord atom. – GuM Feb 10 '18 at 23:55
  • 1
    In case this wasn't clear from the other answers / comments, I'm going to write it explicitly: your output looks bad not because of the vertical alignment, but because the space between \in and the R is too small. – Federico Poloni Feb 11 '18 at 09:42
  • @HeikoOberdiek From what I've understood, the "is element of" symbol is a stylized version of epsilon, just like the sum and product symbols are stylized versions of sigma and pi. While I agree that in modern typography there is an important distinction between $\in$ and $\epsilon$ (and $\Sigma$ and $\sum$), the origin does give a reason to call both an epsilon. – Joonas Ilmavirta Feb 11 '18 at 12:27
  • @JoonasIlmavirta Now, the epsilon and "is element of" are quite different entities, the former is used as variable, the latter is a relational operator. The former is put on the baseline, the latter is vertically centered at the math axis with additional horizontal space around the symbol. – Heiko Oberdiek Feb 11 '18 at 15:10
  • @HeikoOberdiek I know they are different entities and I am not challenging that. My comment was of etymological nature: "is element of" comes from epsilon, so it does make some sense to call "is element of" an epsilon. There are many reasons to keep them well separate (especially for typesetting purposes), but I wanted to point out that there is a connection and calling both "epsilon" is not completely unjustified. But still, I wouldn't call them both that. – Joonas Ilmavirta Feb 11 '18 at 15:15
  • @JoonasIlmavirta - I would like to dispute the notion that \in is a stylized version of \epsilon. I was taught (a long time ago...) that the \in symbol derives from the \subset symbol. If A and B are sets, then A\subset B can be read out loud -- slightly sloppily -- either as "A is in B" or as "A is contained in B". The \in symbol evolved from the need to treat the case when A has a single member (x) and, in particular, to avoid any confusion about whether one is talking about a relation between two sets (use: \subset) or between a point and a set (use: \in). – Mico Feb 13 '18 at 14:26

5 Answers5

30

it can be seen that the epsilon symbol and R are vertically misaligned

First off, your screenshot does not show either \epsilon or \varepsilon. Instead, it shows a symbol that's produced in TeX and LaTeX by the macro \in. When read out loud, this symbol is usually pronounced (in English) either as "in" -- hence the name of the macro... -- or as "is element of". Second, in LaTeX, it's generally preferable to write the letter that denotes "the set of real numbers" as \mathbb{R}.

enter image description here

Aside: Writing {\rm I\!R} has been deprecated since about 1994, when LaTeX2e superseded LaTeX2.09. Writing {\rm I\!R} just so happens to still work in some LaTeX document classes -- but not in others. If you care about portability and long-term maintainability of your code, you should no longer be writing \rm, \it, \bf, \sf and \tt; instead, do write (in a math context, obviously) \mathrm, \mathit, \mathbf, \mathsf and \mathtt. If you insist on not using \mathbb{R}, you should write the symbol as \mathrm{I}\!\mathrm{R}, not as {\rm I\!R}.

Back to the issue of how \in should be positioned. In fine typography -- which is, after all, what TeX and LaTeX aspire to achieve -- there are separate rules for typesetting letters (Latin and Greek, both lowercase and uppercase) on the one hand and for typesetting non-letter symbols (including \in, +, \times, \div, \sum, etc) on the other. Consider the following list of letter and non-letter symbols, drawn using the Computer Modern (serif) math family.

enter image description here

Letter symbols are shown on the left (through \Pi): They are all aligned on a common, invisible line called the baseline. (Two additional important lines are the x-height line and the cap-height line.) In contrast, non-letter symbols are not aligned on the baseline. Instead, they are positioned by centering them vertically on a common line that's frequently called the math line or math axis. (What and where is the math axis?, you may ask. It's an imaginary horizontal line located between the baseline and the x-height line. The horizontal portions of +, - ("minus"), and \div are placed on the math axis.) Do note that whereas the Greek uppercase letters \Sigma and \Pi rest on the baseline, the non-letter symbols \sum and \prod do not. It's not just a matter of \sum being taller than \Sigma; a portion of \sum clearly reaches below the baseline, which is -- by design -- not the case for \Sigma.

Some non-letter symbols -- most obviously, - -- never cross the baseline, whereas others -- including \in -- do have portions that reach below the baseline. By the way, did you notice that the very lowest portion of the + symbol reaches even further below the baseline than the lowest portion of \in does? So what? No big deal.

Just how large the symbol \in should be is a choice font designers have to make. In my view, an excellent (typographic) reason for making \in quite large, so that a portion must lie below the (letter) baseline, is precisely to avoid any visual ambiguity over the meaning of the symbol: Readers should never have to puzzle over whether the symbol they are staring at denotes "is element of" or "epsilon". Similarly, an excellent typographic reason for making \sum and \prod considerably larger than \Sigma and \Pi is to avoid any ambiguity over the meaning of the symbol.


The following screenshots illustrate how different font designs affect not only the shapes of various math glyphs, but even where the math axis is placed relative to the baseline and the x-height line. [The line-drawing code, incidentally, is adapted (stolen?!) from Paul Gaborit's answer to the question, Why do all symbols in $x \in X$ have their own baseline? Credit where credit is due!]

Computer Modern (Latin Modern is very similar):

enter image description here

Times and mtpro2 math font package (Times Roman clone):

enter image description here

newtxtext and newtxmath (another Times Roman clone):

enter image description here

newpxtext and newpxmath (Palatino clone):

enter image description here

Obviously, the fonts all have their special features. What's common among all of the math glpyhs, though, is that they're all centered vertically on the respective math axes.


Code to generate the first two screenshots shown above:

\documentclass[border=1pt]{standalone}
\usepackage{amsfonts} % for "\mathbb"
\newcommand{\myR}{\mathrm{I}\!\mathrm{R}}
\begin{document}
$\mathrm{e}e\epsilon\varepsilon{\in}\ \mathbb{R}\myR$

%$a\alpha e\epsilon\varepsilon X\Sigma\Pi{\subset}{\in}{-}{+}{\times}{\div}{\sum}{\prod}{\int}\displaystyle{\sum}{\prod}{\int}$
\end{document}

Code to generate the screenshots with the various horizontal lines:

\documentclass{article}

%% Uncomment as needed:
%\usepackage{times,mtpro2}
%\usepackage{newtxtext,newtxmath}
\usepackage{newpxtext,newpxmath}

\usepackage[margin=0pt,
   paperwidth=3.35cm,paperheight=0.5cm]{geometry}
\usepackage{xcolor,graphicx}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[scaled=0.85]{helvet}

% Draw a line showing a font metric
%  #1 color, #2 vertical position, #3 label
\newcommand{\drawmetric}[3]{%
  \rlap{%
    \color{#1}\rule[#2]{2.9cm}{0.05pt}%
    \raisebox{#2}{\scalebox{0.3}{\tiny\selectfont\sffamily #3}}%
  }%
}
\newcommand\drawallmetrics{%
  \drawmetric{red}{0pt}{baseline}%
  \drawmetric{blue}{1ex}{x-height}%
  \drawmetric{red}{\fontcharht\font`X}{cap-height}%
  \drawmetric{cyan}{\the\fontdimen22\textfont2}{math axis}%
}
\begin{document}

% Draw the metrics and some text
\noindent\rlap{ % 
  $\mathrm{Hx}e\epsilon\varepsilon{\in}{\subset}{\subseteq}{+}{\times}\Sigma{\sum}$}
  \drawallmetrics{}
\end{document}
Mico
  • 506,678
  • @CarLaTeX I follow you, clap clap clap +1. – Sebastiano Feb 10 '18 at 11:04
  • @Συλχαν - You're most welcome! I had quite a bit of fun writing this answer, actually. :-) – Mico Feb 11 '18 at 08:37
  • 2
    to add another consideration, in computer modern (and other fonts designed specifically for math) the vertical center point of parentheses and other delimiters lies on the math axis. since the delimiters must neatly enclose the ascenders and descenders of all alphabetic charactes in the font, this results in a position of the math axis that is not exactly centered at an "obvious" height above the baseline. (kind of a chicken and egg problem.) – barbara beeton Feb 12 '18 at 14:46
  • @barbarabeeton - Thanks for this. I thought briefly about saying something regarding how far above the baseline the math axis should be placed. But as my answer is already long enough as it is, I decided to let this temptation pass me by. Maybe somebody else will ask a question about how math font designers decide where to place the math axis... – Mico Feb 12 '18 at 19:36
7
  • the standard (correct) way of typesetting of your equation is in the first example in mwe below.
  • do you like to invent new rules? for example as is second example in mwe below?

\documentclass{article}
\usepackage{amssymb}

\begin{document}
    \[
\forall x \in \mathbb{R}
    \]
    \[
\forall x \raisebox{1pt}{$\;\in\;$} \mathbb{R}
    \]
\end{document}

enter image description here

as you can see from mwe, there is no standardized way which assume that typesetting on your desired way is good typography. i suggest you to read some introductory text about math typesetting with latex as for example wiki/LaTeX/Mathematics and then wiki/LaTeX/Advanced_Mathematics.

Zarko
  • 296,517
  • How have you determined that the symbol should be raised by exactly 1 point? For my eyes it is 16-17% too high! – yarchik Feb 10 '18 at 22:23
  • 1
    @yarchik, i didn't bother with amount of raising $\in$ symbol (since i consider that this is bad idea; i emphasize this in answer). i only show the possible way, how to do this, if someone persist to do this... so i left this to user of this solution. – Zarko Feb 10 '18 at 22:40
  • Completely agree, see my answer by the way – yarchik Feb 10 '18 at 22:43
  • I loved your and Mico's answers as Mico's explained why not to worry about it and you've provided a solution just in case. Thanks! – Συλχαν Feb 11 '18 at 06:39
4

You can use the amsfonts package to get access to the black-board bold fonts with the \mathbb{} macro:

\documentclass{article}

\usepackage{amsmath,amsfonts}


\begin{document}

You can write
\[
  \forall x \in {\rm I\!R}
\]
or better
\[
  \forall x \in \mathrm{I}\!\mathrm{R}
\]

But the recommended way is
\[
  \forall x \in \mathbb{R}
\]

\end{document}
user94293
  • 4,254
  • 3
    \rm has no place is LaTeX. It has been obsolete since the introduction of LaTeX 2e. Only a few decades ago, for sure, but it is always best to keep up with the cutting edge. I see, for example, that you're already making use of the new \documentclass command. – cfr Feb 10 '18 at 04:26
  • Both are still vertically misaligned as seen in this output: https://i.imgur.com/WpaBvCO.png – Συλχαν Feb 10 '18 at 04:28
3

The following definition of \In creates a variant of \in:

  • It is still vertically centered around the math axis like other symbols =, +, -, ...

  • The symbol is made a little smaller to get it on the base line.

  • The new symbol respect the math styles.

  • Because of the shrinking, the lines are a little thinner.

Example:

\documentclass{article}
\usepackage{graphicx}

\newcommand*{\Real}{\mathrm{I\!R}}

\makeatletter
\newcommand*{\In}{%
  \mathrel{%
    \mathpalette\@In{\in}%
  }%
}
\newcommand*{\@In}[2]{%
  % #1: math style
  % #2: symbol
  \sbox0{$#1#2\m@th$}%
  \ifdim\dp0>\z@
    \raisebox{\dp0}{%
      \resizebox*{!}{\dimexpr\totalheight-2\dp0\relax}{\copy0}%
    }%
  \else
    % nothing to do
    #2%
  \fi
}
\makeatother

\begin{document}
\[
  \forall x \In \Real
\]
\[
  {+}{\In}{-}
\]
\end{document}

Result

And the version for \notin:

\documentclass{article}
\usepackage{graphicx}

\newcommand*{\Real}{\mathrm{I\!R}}

\makeatletter
\newcommand*{\NotIn}{%
  \mathrel{%
    \mathpalette\@NotIn{\notin}%
  }%
}
\newcommand*{\@NotIn}[2]{%
  % #1: math style
  % #2: symbol
  \sbox0{$#1#2\m@th$}%
  \sbox2{$\vcenter{}$}% math axis
  \sbox4{$#1\in$}%
  \ifdim\dp0>\z@
    \raisebox{\dimexpr\ht2}{%
      \resizebox{!}{%
        \dimexpr\height*\numexpr\ht4-\dp4\relax/\numexpr\ht4+\dp4\relax\relax
      }{%
        \raisebox{\dimexpr-\ht2}{\copy0}%
      }%
    }%
  \else
    % nothing to do
    #2%
  \fi
}
\makeatother

\begin{document}
\[
  \forall x \NotIn \Real
\]
\[
  {+}{\NotIn}{-}
\]
\end{document}

Result

Heiko Oberdiek
  • 271,626
1

Just use a different font. I guess you have experience with Microsoft Word where Cambria Math is used for typing equations. Therefore:

\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage[]{amsmath}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Cambria}
\usepackage[math-style=TeX]{unicode-math}
\setmathfont{Cambria Math}
\begin{document}
\bgroup
\everymath{\displaystyle}
$\forall x \in \mathbb{R}$
\egroup
\end{document}

This produces desired result without any adjustments:

enter image description here

yarchik
  • 272
  • interesting solution. however you should say that works with xelatex :-). so far i didn't see this font in math text (+1) – Zarko Feb 10 '18 at 22:52