我想定义一个“ \bigplus
”运算符,它是一个大+
符号,它会根据环境改变大小并有限制,就像\bigcup
works 一样。我读过关于定义“ \bigtimes
” (我怎样才能得到一个大十字来表示广义笛卡尔积?)但答案对我没有帮助,因为在包中mathabx
没有“ \bigplus
”命令,并且包更改了许多符号。我发现包mathtools
,其中有命令\bigtimes
,但也没有“ \bigplus
”。我在其源代码中找到了命令
\def\MH_bigtimes_scaler:N #1{%
\vcenter{\hbox{#1$\m@th\mkern-2mu\times\mkern-2mu$}}}
\def\MH_bigtimes_inner: {
\mathchoice{\MH_bigtimes_scaler:N \huge} % display style
{\MH_bigtimes_scaler:N \LARGE} % text style
{\MH_bigtimes_scaler:N {}} % script style
{\MH_bigtimes_scaler:N \footnotesize} % script script style
}
\def\MH_csym_bigtimes: {\mathop{\MH_bigtimes_inner:}\displaylimits}
\AtBeginDocument{
\providecommand\bigtimes{\MH_csym_bigtimes:}
}
并尝试复制它,在必要时将其更改\times
为+
或plus
,然后将其粘贴到我的序言中,但它不起作用。如果我将它复制到代码本身下,它就可以工作,但显然我不想更改代码。我正在寻找一种方法来从我已经拥有的符号(例如)中定义一般的运算符命令,+
因为这对我有很大帮助。
答案1
人们可以很容易地使“大加号”的大小与以下相同\sum
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\makeatletter
\newcommand{\bigplus}{%
\DOTSB\mathop{\mathpalette\mattos@bigplus\relax}\slimits@
}
\newcommand\mattos@bigplus[2]{%
\vcenter{\hbox{%
\sbox\z@{$#1\sum$}%
\resizebox{!}{0.9\dimexpr\ht\z@+\dp\z@}{\raisebox{\depth}{$\m@th#1+$}}%
}}%
\vphantom{\sum}%
}
\makeatother
\begin{document}
\begin{center}% test bounding box
\setlength{\fboxsep}{0pt}
\fbox{$\displaystyle\sum$} \fbox{$\displaystyle\bigplus$}
\end{center}
\[
\sum_{i=1}^m\bigplus_{j=1}^n\dots\bigplus_{k=1}^p x_{ijk}
\]
\begin{center}% to test text style
$\sum_{i=1}^m\bigplus_{j=1}^n\dots\bigplus_{k=1}^p x_{ijk}$
\end{center}
\LARGE % test for sizes
\[
\sum_{i=1}^m\bigplus_{j=1}^n\dots\bigplus_{k=1}^p x_{ijk}
\]
\begin{center}% to test text style
$\sum_{i=1}^m\bigplus_{j=1}^n\dots\bigplus_{k=1}^p x_{ijk}$
\end{center}
\end{document}
答案2
我的答案如下:大运营商是如何定义的?. 提供了两个完全独立的宏(\foo
和\barr
),取决于是否希望\displaystyle
版本变大或保持与 相同的大小\textstyle
。
\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator*{\foo}{\scalerel*{+}{\sum}}
\DeclareMathOperator*{\barr}{\scalerel*{+}{\textstyle\sum}}
\usepackage{scalerel}
\begin{document}
\[
\foo_{i=3}^{6}(f^2(i))
\]
This is inline: \(\foo_{i=3}^{6}(f^2(i)) \)
\[
\barr_{i=3}^{6}(f^2(i))
\]
This is inline: \(\barr_{i=3}^{6}(f^2(i)) \)
\end{document}
答案3
如果不采取适当的初步措施,您无法将 LaTeX3 代码复制到序言中。下面我将展示如何通过 LaTeX2e 代码实现相同的想法。此解决方案还支持amsmath
与点和 [ no
]sumlimits
选项相关的标准行为:
% 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}
\makeatletter
\newcommand*\@bigplus[1]{\vcenter{\hbox{#1$\m@th +$}}}
\newcommand*\bigplus{%
\DOTSB % omit this line if you are not using the amsmath package
\mathop{%
\mathchoice
{\@bigplus \huge}%
{\@bigplus \LARGE}%
{\@bigplus {}}%
{\@bigplus \footnotesize}%
}%
\slimits@ % omit this line if you are not using the amsmath package
}
\makeatother
\begin{document}
In-line: \( \bigplus_{i=3}^{6} f^2(i) \).
Displayed: \[ \bigplus_{i=3}^{6} f^2(i) \]
Behavior with dots:
\[
\bigplus_{i_{1}=0}^{n_{1}}\dots\bigplus_{i_{k}=0}^{n_{k}}
f(i_{1},\dots,i_{k})
\]
\end{document}
这是输出:
添加
正如@egreg指出的那样他的评论,上述答案(然而,它只是模仿了该mathtools
包的功能\bigtimes
)是有缺陷的。正确的解决方案是使用mathabx
包,与问题中所述相反,它确实提供了\bigplus
“大运算符”。此解决方案使用专门为此目的设计的字体绘制的字符,因此不依赖于graphics
/graphicx
包提供的扩展;特别是,它也适用于 DVI 输出(就这一点而言)。
如果您不喜欢该mathabx
软件包对数学符号所做的更改,您可以随时自行加载适当的字体并仅定义您感兴趣的命令。以下示例定义了\bigplus
以及\bigtimes
。请允许我发表几点评论:
amsmath
如果加载了该包,代码将支持有关点和“限制”的包的功能;与
mathabx
软件包本身的做法相反,mathx
字体系列的定义方式是为了利用当今发行版中安装的较小字体大小。
后一种设计可以改善小于 10 点的尺寸的输出,使其看起来比使用graphics
缩放的解决方案更好。
以下是代码:
% 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} % comment out to see changes
\DeclareFontFamily{U}{mathx}{\hyphenchar\font45}
\DeclareFontShape{U}{mathx}{m}{n}{
<5> <6> <7> <8> <9> <10> gen * mathx
<10.95> mathx10
<12> <14.4> <17.28> <20.74> <24.88> mathx12
}{}
\DeclareFontSubstitution{U}{mathx}{m}{n}
\DeclareSymbolFont{mathx}{U}{mathx}{m}{n}
\DeclareMathSymbol{\bigplus} {\mathop}{mathx}{"90}
\DeclareMathSymbol{\bigtimes}{\mathop}{mathx}{"91}
\makeatletter
\@ifpackageloaded{amsmath}{%
\@ifundefined{coprod@}{}{
\typeout{*** Applying amsmath patches to \protect\bigplus\space
and \protect\bigtimes. ***}
\global\let\bigplus@\bigplus
\gdef\bigplus{\DOTSB\bigplus@\slimits@}
\global\let\bigtimes@\bigtimes
\gdef\bigtimes{\DOTSB\bigtimes@\slimits@}
}
}{}
\makeatother
\begin{document}
In-line: \( \bigplus_{i=3}^{6} f^2(i) \).
Displayed: \[ \bigplus_{i=3}^{6} f^2(i) \]
Behavior with dots:
\[
\bigplus_{i_{1}=0}^{n_{1}}\dots\bigplus_{i_{k}=0}^{n_{k}}
f(i_{1},\dots,i_{k})
\]
In-line: \( \bigtimes_{i=3}^{6} f^2(i) \).
Displayed: \[ \bigtimes_{i=3}^{6} f^2(i) \]
Behavior with dots:
\[
\bigtimes_{i_{1}=0}^{n_{1}}\dots\bigtimes_{i_{k}=0}^{n_{k}}
f(i_{1},\dots,i_{k})
\]
Now it works in footnotes too.\footnote{As this example shows.
In-line: \( \bigplus_{i=0}^{n} f(i) \), \( \bigtimes_{i=0}^{n} f(i) \).
Displayed: \[ \bigplus_{i=0}^{n} f(i) \ne \bigtimes_{i=0}^{n} f(i) \]
That's good!}
\LARGE
\verb|\LARGE| text.
In-line: \( \bigtimes_{i=3}^{6} f^2(i) \).
Displayed: \[ \bigtimes_{i=3}^{6} f^2(i) \]
Behavior with dots:
\[
\bigtimes_{i_{1}=0}^{n_{1}}\dots\bigtimes_{i_{k}=0}^{n_{k}}
f(i_{1},\dots,i_{k})
\]
\end{document}
它的输出如下: