9

I want to define a command that prints the = sign with its lower line touching the baseline, that is directly sitting on the baseline, any suggestion?

Red
  • 10,181

2 Answers2

11

You could lower a character, or you could use rules:

enter image description here

\documentclass{article}
\setlength\textwidth{4cm}
\begin{document}

aaa\hrulefill
$=$\hrulefill
$\mathrel{\raisebox{-.3ex}{$=$}}$\hrulefill
$\mathrel{\vbox{\hrule width .5em height .5pt\vskip .3ex \hrule height .5pt}}$\hrulefill
aaa\hrulefill


\end{document}
David Carlisle
  • 757,742
  • Thanks! Just a question, how do you know the exact quantity for lowering the equal sign to the baseline (the .3ex)? It is just try and error or there is a better way? – Red Aug 23 '13 at 23:50
  • 1
    @Red trial and error:-) TeX only has the height and width metrics of a box for the character (any character) so it has no idea where the black pixels are. with the rule version you could measure the width of an = and use that instead of .5em baseline is automatic, but you still have to guess the vskip. – David Carlisle Aug 23 '13 at 23:53
10

The math axis is the symmetry axis for the two lines of the equal sign. If the height of the symbol is known and correct, then we know, the top of the higher line and the bottom of the lower line. The line thickness is not known. But we can calculate the shift amount, needed to move the symbol down to the base line:

\documentclass{article}

\makeatletter
\@ifdefinable{\baselineeq}{%
  \DeclareRobustCommand*{\baselineeq}{%
    \ensuremath{% allow invoking \baselineeq in text mode
      \mathrel{%
        % \mathpalette is a LaTeX wrapper for `\mathchoice`.
        % \baseline@eq will get the math style as first argument.
        % the second argument is unused.
        \mathpalette\baseline@eq{}%
      }%
    }%  
  }
  \newcommand*{\baseline@eq}[2]{%
    % #1: math style,
    %     one of\displaystyle, \textstyle, \scriptstyle, \scriptscriptstyle
    % #2: unused
    %
    % * \vcenter centers stuff vertically around the math axis. By putting
    %   an empty `\vcenter{}` in a box, we get the height of the math axis
    %   as height of the box.
    % * Box register 0 is a local scratch register;
    %   we are inside the groups of \mathrel and \mathpalette.
    \sbox0{$#1\vcenter{}$}%
    % * \height inside \raisebox: height of the unraised box
    %   containing the equal sign.
    % * \ht0: height of box 0, thus height of math axis.
    % * Then the netto height of the equal sign is 2*(\height-\ht0).
    %   In \raisebox we lower the equal sign right below the base line
    %   and raise by the netto height.
    % * \m@th resets \mathsurround to 0pt (avoids additional
    %   surrounding space if \mathsurround is set).
    \raisebox{\dimexpr\height-2\ht0\relax}{$\m@th#1=$}%
  }%
}

\begin{document}

\parbox{20mm}{\hrulefill\baselineeq\hrulefill}

$\_\baselineeq\_^{\_\baselineeq\_^{\_\baselineeq\_}}$

\end{document}

Result

Remarks:

  • The symbol macro \baselineeq can be used both in text or math mode.
  • In math mode the symbol is a relational symbol as the equal sign, but this can be changed by replacing \mathrel.
  • \mathpalette is used to get the current math style, which becomes the first argument of \baseline@eq.
Heiko Oberdiek
  • 271,626