$n\equiv 1\pmod{4}$間のスペースを減らす方法

$n\equiv 1\pmod{4}$間のスペースを減らす方法

次のコードを実行したところ、関数の使用時に次の巨大なスペースが発生しました\pmod。論文では奇妙に見えます。スペースを削減する方法を提案してもらえますか?

\begin{eqnarray*}
    MSC(C_n^2) &=& \begin{cases}
           1, & \text{if $n$ is odd and d is even ($n\equiv 1\pmod{4}$)},\\
           2, & \mbox{if n is even and d is even ($n\equiv 0\pmod {4}$)},\\
           3, & \mbox{if n is odd and d is odd ($n\equiv 3\pmod {4}$)},\\
           3, & \mbox{if n is even and d is odd ($n\equiv 2\pmod {4}$)}.
           \end{cases}
\end{eqnarray*}

ここに画像の説明を入力してください

答え1

続く合同問題で先頭スペースなしで mod を書く以下に定義するとおりに使用します\Mod

ここに画像の説明を入力してください

\documentclass{article}

\usepackage{amsmath}
\newcommand{\Mod}[1]{\ (\mathrm{mod}\ #1)}

\begin{document}

\begin{align*}
  MSC(C_n^2) &= 
    \begin{cases}
      1, & \text{if $n$ is odd and $d$ is even ($n \equiv 1 \Mod{4}$)},  \\
      2, & \text{if $n$ is even and $d$ is even ($n \equiv 0 \Mod{4}$)}, \\
      3, & \text{if $n$ is odd and $d$ is odd ($n \equiv 3 \Mod{4}$)},   \\
      3, & \text{if $n$ is even and $d$ is odd ($n \equiv 2 \Mod{4}$)}.
    \end{cases}
\end{align*}

\end{document}

答え2

斜体フォントから判断すると、表示は定理ステートメント内にあります。

括弧や共通部分の繰り返しは避けます。

\documentclass{article}
\usepackage{amsmath}

\newtheorem{theorem}{Theorem}
\DeclareMathOperator{\MSC}{MSC}

\begin{document}

\begin{theorem}
Blah, blah
\begin{equation*}
\MSC(C_n^2)=
\begin{cases}
  1, & \text{if $n$ is odd and $d$ is even, i.e., $n\equiv 1$},\\
  2, & \text{if $n$ is even and $d$ is even, i.e., $n\equiv 0$},\\
  3, & \text{if $n$ is odd and $d$ is odd, i.e., $n\equiv 3$},\\
  3, & \text{if $n$ is even and $d$ is odd, i.e., $n\equiv 2$},
\end{cases}
\end{equation*}
where congruences are modulo~$4$.
\end{theorem}

\end{document}

いくつかの注意点:

  1. 「MSC」は直立し、オペレーターとして扱われるべきです。
  2. 斜体フォントの場合でも、数式変数は数式モードで入力する必要があります。
  3. eqnarrayが利用可能な場合は使用しないでくださいamsmath(ドキュメントに本格的な数学が含まれている場合は常にロードする必要があります)。
  4. equation*この場合はアライメントがないため、適切な環境を使用してください。

ここに画像の説明を入力してください

答え3

LaTeXカーネルは、\pmod

\def\pmod#1{%
  \allowbreak\mkern18mu({\operator@font mod}\,\,#1)}

ltmath.dtxコードの39~40行目を参照)プレーンTeXでは、次のように記述されている。

\def\pmod#1{\allowbreak\mkern18mu({\rm mod}\,\,#1)}

(見るTeXbook について、361ページ)のどちらの場合も、「mod」の前のスペースは1emの幅です。164ページの用例TeXbook についておよび演習 18.4 の答えは、Knuth がその量のスペースをインライン数式でも使用することを意図していたことを示しています。それにもかかわらず、パッケージはamsmath上記の定義を修正して、数式が「表示されない」ときにはより狭いスペースが使用されるようにします。

\newcommand{\pod}[1]{\allowbreak
  \if@display\mkern18mu\else\mkern8mu\fi(#1)}
\renewcommand{\pmod}[1]{\pod{{\operator@font mod}\mkern6mu#1}}

(参照この答え合同問題で先頭スペースなしで mod を書くすでにリンクされている質問受け入れられた答え(この質問に対する回答は、こちらです。)ご覧の通り、スイッチを介して「表示されていない」状態が検出されます\if@display

この疑問について考えてみると、これはパッケージのバグ、あるいは設計上の欠陥なのではないかと考え始めました。おそらく、よりよいアイデアは、現在の数式スタイルに合わせてスペースの量を変えることであり、これは「大きな演算子」記号が数式の表示と非表示の間でサイズ (およびある程度は形状) を変えるの\sumと似たようなやり方です。この動作は、次のコードに示すコマンド (パッケージによって定義) の\intパッチで簡単に実現できます。\podamsmath

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

% \usepackage{amsmath} % Required for what follows; but...
\usepackage{mathtools} % ... "mathtools" automatically loads "amsmath".

\makeatletter

\renewcommand*\pod[1]{%
  \allowbreak
  \mathchoice
    {\mkern 18mu}%
    {\mkern  8mu}%
    {\mkern  8mu}%
    {\mkern  8mu}%
  (#1)%
}

\makeatother

\newtheorem{thm}{Theorem}



\begin{document}

In-line: \( 5\equiv 1 \pmod 4 \).  In display:
\[ 5\equiv 1 \pmod 4 \]
Non-display inside display:
\[
    f(x) =
        \begin{cases}
            4 & \mbox{if $x\equiv 0 \pmod 4$,} \\
            x\bmod 4 & \mbox{otherwise.}
        \end{cases}
\]
The same thing, but with \texttt{cases*} (requires \textsf{mathtools}):
\[
    f(x) =
        \begin{cases*}
            4 & if $x\equiv 0 \pmod 4$, \\
            x\bmod 4 & otherwise.
        \end{cases*}
\]

\begin{thm}
    All over again.
    In-line: \( 5\equiv 1 \pmod 4 \).  In display:
    \[ 5\equiv 1 \pmod 4 \]
    Non-display inside display:
    \[
        f(x) =
            \begin{cases}
                4 & \mbox{if $x\equiv 0 \pmod 4$,} \\
                x\bmod 4 & \mbox{otherwise.}
            \end{cases}
    \]
    With \texttt{cases*}:
    \[
        f(x) =
            \begin{cases*}
                4 & if $x\equiv 0 \pmod 4$, \\
                x\bmod 4 & otherwise.
            \end{cases*}
    \]
\end{thm}

Nonetheless, inside an alignment, say
\begin{align*}
    2 &\equiv 9 \pmod 7 \\
    4 &\equiv 1 \pmod 3 \mbox{,}
\end{align*}
the output agrees with that of a displayed equation:
\[
    5\equiv 1 \pmod 4 \mbox{.}
\]

\end{document}

上記のコードによって生成される出力は次のとおりです。

コードの出力

この変更は、質問で求められているものを達成するためのエレガントで一貫した方法である可能性があります。 コマンドも\mod使用されている場合は、同様に変更する必要があります。 もちろん、これらの機能を使用する既存のドキュメントをすべて混乱させることなく、パッケージのコードにこれらの変更を導入することはできませんmasmath...


追加: この問題についてさらに検討を続けると、コマンドを上付き/下付き文字で使用するのも意味があるのではないかと思いました\pmod(以下の例を参照)。この場合、左括弧の前のスペースをさらに狭くする必要があるようです。

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

% \usepackage{amsmath} % Required for what follows; but...
\usepackage{mathtools} % ... "mathtools" automatically loads "amsmath".

\makeatletter

\renewcommand*\pod[1]{%
  \allowbreak
  \mathchoice
    {\mkern 18mu}%
    {\mkern  8mu}%
    {\mkern  6mu}% "6mu" matches the space *after* the word "mod"
    {\mkern  6mu}%
  (#1)%
}

\makeatother

\newtheorem{thm}{Theorem}



\begin{document}

In-line: \( 5\equiv 1 \pmod{4} \).  In display:
\[ 5\equiv 1 \pmod{4} \]
Non-display inside display:
\[
    f(x) =
        \begin{cases}
            4 & \mbox{if $x\equiv 0 \pmod{4}$,} \\
            x\bmod 4 & \mbox{otherwise.}
        \end{cases}
\]
The same thing, but with \texttt{cases*} (requires \textsf{mathtools}):
\[
    f(x) =
        \begin{cases*}
            4 & if $x\equiv 0 \pmod{4}$, \\
            x\bmod 4 & otherwise.
        \end{cases*}
\]

\begin{thm}
    All over again.
    In-line: \( 5\equiv 1 \pmod{4} \).  In display:
    \[ 5\equiv 1 \pmod{4} \]
    Non-display inside display:
    \[
        f(x) =
            \begin{cases}
                4 & \mbox{if $x\equiv 0 \pmod{4}$,} \\
                x\bmod 4 & \mbox{otherwise.}
            \end{cases}
    \]
    With \texttt{cases*}:
    \[
        f(x) =
            \begin{cases*}
                4 & if $x\equiv 0 \pmod{4}$, \\
                x\bmod 4 & otherwise.
            \end{cases*}
    \]
\end{thm}

Nonetheless, inside an alignment, say
\begin{align*}
    2 &\equiv 9 \pmod{7} \\
    4 &\equiv 1 \pmod{3} \mbox{,}
\end{align*}
the output agrees with that of a displayed equation:
\[
    5\equiv 1 \pmod{4} \mbox{.}
\]

In super\slash subscripts:
\[
    \int_{0}^{3\pi} \sin x\,dx
        = -\cos x \biggr|_{0}^{3\pi}
        = -\cos x \biggr|_{x\equiv 0 \pmod{2\pi}}^{x\equiv 3\pi \pmod{2\pi}}
        = -\cos x \biggr|_{0}^{\pi}
        = 1-(-1) = 2
\]

\end{document}

この2番目のケースの出力は

2番目のコードサンプルの出力

答え4

括弧内で使用するのは\pmod、特に外側の括弧 (テキスト) が斜体の場合は見栄えがよくないので、\bmod代わりに を使用することを提案します。提案する方法は 2 つあります。cases eqparbox`cases*の環境を使用してmathtools (simpler syntax), and with a standard,and係数条件を揃えます。

\documentclass{article}

\usepackage{mathtools}
\usepackage{eqparbox}

\begin{document}

\begin{align*}
  MSC(C_n^2) &=
    \begin{cases}
       1, &  \eqparbox{CN}{if $n$ is odd and $d$ is even} (n \equiv 1 \bmod{4}), \\
       2, &  \eqparbox{CN}{if $n$ is even and $d$ is even\enspace} (n \equiv 0 \bmod{4}), \\
       3, &  \eqparbox{CN}{ if $n$ is odd and $d$ is odd}  (n \equiv 3 \bmod{4}), \\
       3, & \eqparbox{CN}{ if $n$ is even and $d$ is odd } (n \equiv 2 \bmod{4}).
  \end{cases}
\end{align*}

\begin{align*}
  MSC(C_n^2) &=
    \begin{cases*}
      1, & if $n$ is odd and $d$ is even ($n \equiv 1 \bmod{4}$), \\
      2, & if $n$ is even and $d$ is even ($n \equiv 0 \bmod{4}$), \\
      3, & if $n$ is odd and $d$ is odd ($n \equiv 3 \bmod{4}$), \\
      3, & if $n$ is even and $d$ is odd ($n \equiv 2 \bmod{4}$).
    \end{cases*}
\end{align*}

\end{document} 

ここに画像の説明を入力してください

関連情報