如何正确地将 mathpartir 中的 \inference* 规则居中

如何正确地将 mathpartir 中的 \inference* 规则居中

继续http://tex.stackexchange.com/a/656192那么,如何将带有名称或附加条件的推理规则集中\[…\]在较窄的列中呢?例如,

\documentclass[twocolumn]{article}
\pagestyle{empty}
\usepackage{mathpartir}
\begin{document}
\noindent A sentence introducing the first rule, which has a name and protrudes to the left:
\[%\quad\ \,\qquad%%% Ad-hoc, manually added space would mitigate the problem.
  \inferrule*[Left=RULE\_NAME,Right=.]%
  {\mathrm{an\ extensive\ list\ of\ antecedences}}%
  {\mathrm{an\ extensive\ consequent}}
\]%
\noindent A long, extensive, lengthy, and boring text explaining the first rule in detail.\par

\noindent A sentence introducing the second rule, which has a side condition and protrudes to the right:
\[
  \inferrule*[Right=a\ side\ condition.]%
  {\mathrm{an\ extensive\ list\ of\ antecedences}}%
  {\mathrm{an\ extensive\ consequent}}
  %\qquad\qquad\qquad\qquad%%% Ad-hoc, manually added space would mitigate the problem.
\]%
\noindent A long, extensive, lengthy, and boring text explaining the second rule in detail.

\noindent A sentence introducing the third rule, which has both a name and a side condition and is not centered:
\[
  \inferrule*[Left=RULE,Right=formula.]%
  {\mathrm{an\ extensive\ list\ of\ antecedences}}%
  {\mathrm{an\ extensive\ consequent}}
  %%% Here, some unknown amount of space should be added so that the rule is really centered.
\]%
\noindent A long, extensive, lengthy, and boring text explaining the third rule in detail.
\end{document}

latex或编译后产生的pdflatex输出中,名称和条件的推理规则不居中:

输出

有时它们甚至会伸出到边缘,尽管如果整个规则连同名称和附加条件都居中的话会有空间。

有什么方法可以使规则居中,包括其左侧和右侧的内容?

PS. 事实证明,Leftand的这种语义Right是经过设计的,正如 mathpartir 文档中所述。这不是一个错误。

答案1

推论居中,但不考虑侧面材料。

您也可以使用LEFTRIGHT来代替,但是您需要明确地表明该材料处于文本模式。

\documentclass[twocolumn]{article}
\usepackage{mathpartir}

\makeatletter
% fix a long standing bug
\define@key {mprset}{style}[1]{\def\TirNameStyle{#1}}
\makeatother

\begin{document}

\noindent A sentence introducing the first rule, which has a name and protrudes to the left:
\[
  \inferrule*[Left=RULE\_NAME,Right=.]
  {\textrm{an extensive list of antecedences}}
  {\textrm{an extensive consequent}}
\]
A long, extensive, lengthy, and boring text explaining the first rule in detail.
\[
  \inferrule*[LEFT=\textrm{RULE\_NAME },Right=.]
  {\textrm{an extensive list of antecedences}}
  {\textrm{an extensive consequent}}
\]
A sentence introducing the third rule, which has both a name and a side 
condition and is not centered:
\[
  \inferrule*[LEFT=\textrm{RULE },RIGHT=\textrm{ formula.}]
  {\textrm{an extensive list of antecedences}}
  {\textrm{an extensive consequent}}
  %%% Here, some unknown amount of space should be added so that the rule is really centered.
\]
A long, extensive, lengthy, and boring text explaining the third rule in detail.

\end{document}

在此处输入图片描述

不同的方法可能是定义新的键Left*和,Right*它们的作用与Left和相同,Right但不适用于零宽度框。

\documentclass[twocolumn]{article}
\usepackage{mathpartir}

\makeatletter
% fix a long standing bug
\define@key {mprset}{style}[1]{\def\TirNameStyle{#1}}
% define new keys Right* and Left*
\define@key {mpr}{Left*}{\hbox{$\LeftTirName {#1}\;$}}
\define@key {mpr}{Right*}
  {\setbox \mpr@right \hbox {\unhbox \mpr@right $\;\RightTirName {#1}$}}
\makeatother

\begin{document}

\noindent A sentence introducing the first rule, which has a name and protrudes to the left:
\[
  \inferrule*[Left=RULE\_NAME,Right=.]
  {\textrm{an extensive list of antecedences}}
  {\textrm{an extensive consequent}}
\]
A long, extensive, lengthy, and boring text explaining the first rule in detail.
\[
  \inferrule*[Left*=RULE\_NAME,Right=.]
  {\textrm{an extensive list of antecedences}}
  {\textrm{an extensive consequent}}
\]
A sentence introducing the third rule, which has both a name and a side 
condition and is not centered:
\[
  \inferrule*[Left*=RULE,Right*=formula.]
  {\textrm{an extensive list of antecedences}}
  {\textrm{an extensive consequent}}
  %%% Here, some unknown amount of space should be added so that the rule is really centered.
\]
A long, extensive, lengthy, and boring text explaining the third rule in detail.

\end{document}

在此处输入图片描述

答案2

不是错误:Left表示“将标签在规则的左边[…]但就像标签一样宽度为零。” 类似地Right

至于手头的最小示例,left并且right可以完成工作(但仅限于最小示例):

\documentclass[twocolumn]{article}
\pagestyle{empty}
\usepackage{mathpartir}
\begin{document}
\noindent A sentence introducing the first rule, which has a name and protrudes to the left:
\[
  \inferrule*[left=RULE\_NAME,right=.]%
  {\mathrm{an\ extensive\ list\ of\ antecedences}}%
  {\mathrm{an\ extensive\ consequent}}
\]%
\noindent A long, extensive, lengthy, and boring text explaining the first rule in detail.\par

\noindent A sentence introducing the second rule, which has a side condition and protrudes to the right:
\[
  \inferrule*[right=a\ side\ condition.]%
  {\mathrm{an\ extensive\ list\ of\ antecedences}}%
  {\mathrm{an\ extensive\ consequent}}
  %\qquad\qquad\qquad\qquad%%% Ad-hoc, manually added space would mitigate the problem.
\]%
\noindent A long, extensive, lengthy, and boring text explaining the second rule in detail.

\noindent A sentence introducing the third rule, which has both a name and a side condition and is not centered:
\[
  \inferrule*[left=RULE,right=formula.]%
  {\mathrm{an\ extensive\ list\ of\ antecedences}}%
  {\mathrm{an\ extensive\ consequent}}
  %%% Here, some unknown amount of space should be added so that the rule is really centered.
\]%
\noindent A long, extensive, lengthy, and boring text explaining the third rule in detail.
\end{document}

输出

但请注意,左侧的文本是正常大小(如 OP 中所示),而右侧的文本是小写大写(如 OP 中所示)。不确定这是否是故意的。

相关内容