在數學公式的邊緣(開始/結束)處消失的空間

在數學公式的邊緣(開始/結束)處消失的空間

有沒有辦法產生一個在數學公式的開頭或結尾消失的空格?

主意:對於公式最終的情況,展望未來或採用強制性參數的東西可能是一個開始。我記得那些強制參數在數學公式末尾終止的命令將被提供空參數。

一些實際例子:


實施例1

唯一性量詞(「恰好存在一個」)通常寫為「∃!」。

出於視覺考慮,我希望以下變數遠離感嘆號,以便更清楚地顯示“∃!”被視為單一標記(此處的“標記”是指程式語言中的解析)。我可以定義類似 的東西,但如果符號單獨使用,則保留 的\newcommand*{\existsunique}{\exists!\mskip1.5mu\relax}空間:1.5mu

\documentclass{article}
\usepackage{amsmath} % better spacing behavior for \colon
\usepackage{dsfont}

\newcommand*{\existsunique}{\exists!\mskip1.5mu\relax}


\begin{document}

% spacing (1.5mu) as desired
\(\forall x \in \mathds{R}^{+}_{0} \colon
  \existsunique y \in \mathds{R}^{+}_{0} \colon
  y^2 = x\)

% spacing (0mu) too tight
\(\forall x \in \mathds{R}^{+}_{0} \colon
  \exists! y \in \mathds{R}^{+}_{0} \colon
  y^2 = x\)

% spacing (1.5mu) superfluous
The quantifier \(\existsunique\) means ``there is exactly one''.

% spacing (0mu) as desired
The quantifier \(\exists!\) means ``there is exactly one''.

\end{document}

有空格和沒有空格的唯一性量詞

這裡,每對的第一行在1.5mu唯一性量詞「∃!」之後有額外的間距,而每對的第二行則沒有。對於第一對,增加的間距是根據需要的;對於第二對,看起來不太好。

在這個例子中,我想要一個1.5mu在公式末尾消失的空格:同一個巨集應該會產生上面的第 1 行和第 4 行。也許對「∃!」有一種不同的方法,但這可以作為我上面的一般問題的實際例子。


實施例2

適用於 Heiko Oberdiek 的中長箭

  • \Implies(長度之間\Rightarrow\implies長度)
  • \Impliedby(長度之間\Leftarrow\impliedby長度)
  • \Iff(長度之間\Leftrightarrow\iff長度)

此處定義,雙方都希望上下文刪除空格。

答案1

這個修改後的答案源自於看到egreg的答案\mathop、\operatorname 和 \DeclareMathOperator 有什麼不同?,他提到了這個結構:\newcommand{\diff}{\mathop{}\!d}

在上面OP的問題中,Werner和egreg使用\mathbin和提出了建議\mathop,但OP回答說“我也考慮過\mathop,但我想要更窄的間距。”

因此,採取類似於 的策略\diff,我想出了這個:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{dsfont}
\usepackage[usestackEOL]{stackengine}
\def\stackalignment{l}
\def\showall{~\fbox{\Longstack{
\text{\detokenize\expandafter{\existsunique}}\\
A \colon  \existsunique y \\
\fboxsep0pt\fbox{$\existsunique$}\\
A \colon  {\existsunique} y
}~}\par}
\begin{document}
\savestack{\Header}{\Longstack{Definition:\\within math:\\boxed:\\brace-isolated:}}
\stackMath
\Header\def\existsunique{\exists!}\showall
\Header\def\existsunique{\exists!\mathop{}\!}\showall
\Header\def\existsunique{\mathop{}\!\exists!\mathop{}\!}\showall
\end{document}

在此輸入影像描述

雖然實際的\!緊排可能與 OP 的口味不同,但也許該方法可以適應他選擇的緊排。


原始方法:

該解決方案可能(或可能不會)為您提供適合您的應用程式的東西。我介紹一下宏\mymathop{op-name}{op-definition}{pre-kern}{post-kern}

它的作用是查看新的“mymathop”後面的標記,在您的情況下,是 \existsunique.如果後面是$, \), 或\egroup,它會自己印出「op 定義」;否則,它會添加關於“op-definition”的前後緊縮(作為旁注,使用\@ifnextchar將會吞掉“mymathop”和下一個標記之間的任何中間空格)。

\egroup捕獲允許人們透過將其括在大括號中來強制\mymathop抑制前/後\kern,即使在公式中間也是如此

下面的 MWE 將其顯示在一個公式中,用兩種分隔符號樣式將其單獨裝箱,然後在一個公式內,用自己的一組大括號將其隔離。

\documentclass{article}
\usepackage{amsmath}
\usepackage{dsfont}
\makeatletter
\def\mymathop#1#2#3#4{%
  \def#1{\@ifnextchar${#2}{\@ifnextchar\){#2}{\@ifnextchar\egroup{#2}{\kern#3#2\kern#4}}}}
}
\makeatother
\mymathop{\existsunique}{\exists!}{0pt}{3pt}
\begin{document}
\(\forall x \in \mathds{R}^{+}_{0} \colon
  \existsunique y \in \mathds{R}^{+}_{0} \colon
  y^2 = x\)

\fboxsep0pt\fbox{$\existsunique $} \fbox{\(\existsunique \)}

\(\forall x \in \mathds{R}^{+}_{0} \colon
  {\existsunique} y \in \mathds{R}^{+}_{0} \colon
  y^2 = x\)
\end{document}

在此輸入影像描述

答案2

我認為

\newcommand*{\existsunique}{\thinmuskip=1.5mu\mathop{\exists!}\relax}

做你想做的事。

我認為更好的解決方案是

    \makeatletter
     \newcommand*{\existsuniquenew}{\@ifnextchar{\)}{\@end}{%
       \@ifnextchar{$}{\@end}{\not@end}}}
     \def\@end{\exists!\relax}%
     \def\not@end{\exists!\mskip1.5mu\relax}
    \makeatother

相關內容