[Tex/LaTex] Bad vertical alignment with double-line inference rule

vertical alignment

I'm trying to write a bi-directional inference rule with a double horizontal line, using mathpartir. The documentation says I should be able to use \mprset{fraction={===}} as follows:

\documentclass{article}

\usepackage{mathpartir}

\begin{document}
\begin{mathpar}
\mprset{fraction={===}}
\inferrule*
{
}
{
  C \rightarrow C'
}
\and
\inferrule*
{
  C \rightarrow C
}
{
  C \rightarrow C'
}
\and
\inferrule*
{
  C \rightarrow C_{\beta}
}
{
  C \rightarrow C'
}
\end{mathpar}
\end{document}

This does indeed format the rule with a double horizontal line, but it also breaks the vertical alignment, so that, in the last example above, the C \rightarrow C' now overlaps with the double line.

See also here, Frac or inference rule with dotted line, but I would like a solution based on inferrule if possible.

Best Answer

Three parameters to tune:

\eqgap distance between double rule lines;

\overgap separation between the text and the rules; and

\inferrulerule thickness of two rule lines.

This MWE shows it used in math mode, but it works outside of math mode, too. I don't know enough about inference rules to know, but if the math axis is aligned with the "denominator", then this MWE would work.

\documentclass{article}
\usepackage{stackengine}
\def\eqgap{.2ex}
\def\overgap{.4ex}
\def\inferrulerule{.2pt}

\newlength\rulelength
\newlength\toplength
\newlength\bottomlength

\newcommand\myinferrule[2]{%
  \stackMath%
  \setlength\bottomlength{\widthof{$#1$}}%
  \setlength\toplength{\widthof{$#2$}}%
  \ifdim\toplength>\bottomlength%
    \setlength\rulelength{\the\toplength}%
  \else%
    \setlength\rulelength{\the\bottomlength}%
  \fi%
  \mathrel{%
  \stackon[\overgap]{\stackon[\eqgap]{\stackon[\overgap]{#1}%
    {\rule{\the\rulelength}{\inferrulerule}}}%
    {\rule{\the\rulelength}{\inferrulerule}}}{#2}%
  }%
}
\begin{document}
\[
\mathrm{Math~Axis} \myinferrule{C \rightarrow C'}{C \rightarrow C_{\beta}}
\]
\end{document}

enter image description here

If the math axis is supposed to align with the rule, then this MWE would apply:

\documentclass{article}
\usepackage{stackengine}
\def\eqgap{.2ex}
\def\overgap{.4ex}
\def\inferrulerule{.2pt}

\newlength\rulelength
\newlength\toplength
\newlength\bottomlength

\newcommand\myinferrule[2]{%
  \stackMath%
  \setlength\bottomlength{\widthof{$#1$}}%
  \setlength\toplength{\widthof{$#2$}}%
  \ifdim\toplength>\bottomlength%
    \setlength\rulelength{\the\toplength}%
  \else%
    \setlength\rulelength{\the\bottomlength}%
  \fi%
  \mathrel{%
    \stackunder[\overgap]{%
      \stackon[\overgap]{%
        \stackanchor[\eqgap]%
          {\rule{\the\rulelength}{\inferrulerule}}%
        {\rule{\the\rulelength}{\inferrulerule}}%
      }{#2}%
    }{#1}%
  }%
}
\begin{document}
\[
\mathrm{Math~Axis} \myinferrule{C \rightarrow C'}{C \rightarrow C_{\beta}}
\]
\end{document}

enter image description here

With these parameters, the following

\[
\myinferrule{C \rightarrow C'}{C \rightarrow C_{\beta}} ~
\myinferrule{\scriptstyle C \rightarrow C'}{\scriptstyle C \rightarrow C_{\beta}} ~
\myinferrule{\scriptscriptstyle C \rightarrow C'}{\scriptscriptstyle C \rightarrow C_{\beta}}
\]

typesets to different math styles:

enter image description here

If you need to regularly set this to different math styles, I can make it (at the expense of extra coding) so that the style need not be set within the arguments themselves, as it is here. So let me know if that's the case.

Related Question