如何向命令添加新参数来控制缩放?

如何向命令添加新参数来控制缩放?

以下代码稍作修改https://tex.stackexchange.com/a/552769/13492,允许创建新符号\bigplus,,\bigtimes\bigbox

但是,它对用于确定生成的符号的水平收缩的缩放因子进行了硬编码\scalefactor,首先按顺序应用\my@makebig,然后应用于通过应用于基本形式、和 而\my@big创建的图片。\my@draw\my@plus\my@times\my@box

硬编码\scalefactor由 控制\ifnarrow

问题:

如何修改代码以便使用新的附加参数来指定缩放因子直接且分别地针对每个单独的符号(以及我可能选择创建的其他类似符号)。

理想情况下,这个新参数是可选的,默认为1

我只是不知道该如何修改哪些命令才能实现这一点。

澄清:

命令\myplus\mytimes\mybox应分别保留参数。相反,应将新参数 — 添加到\my@big\mymakebig和/或\my@draw(无论出于何种目的需要)。然后使用新的可选参数一次在序言中,分别针对每个\big...命令。换句话说,要在序言中允许这样的内容:

\DeclareRobustCommand{\bigtimes}{\DOTSB\my@big[0.8]\my@times}    
\DeclareRobustCommand{\bigplus}{\DOTSB\my@big\my@plus}

然后在文档正文中我仍然使用,例如:

$\bigplus_{i\in I} X_i  = \bigtimes_{i\in J} Y_i$ 

现在的代码:

\documentclass[fleqn]{article}
\usepackage{amsmath,pict2e,graphicx}
\usepackage{iftex}

\ifTUTeX
  \usepackage{unicode-math}
  \setmainfont{TeX Gyre Termes}[Scale=1.0]
  \setmathfont{TeX Gyre Termes Math}
\else
  \usepackage{newtxtext,newtxmath}
\fi

\newif\ifnarrow
\narrowfalse
\makeatletter
\newcommand{\my@big}[1]{%
  \mathop{\vphantom{\sum}\mathpalette\my@makebig{#1}}\slimits@%
}
\AtBeginDocument{%
  \DeclareRobustCommand{\bigplus}{\narrowfalse\DOTSB\my@big\my@plus}%
  \DeclareRobustCommand{\bigtimes}{\narrowtrue\DOTSB\my@big\my@times}%
  \DeclareRobustCommand{\bigbox}{\narrowfalse\DOTSB\my@big\my@box}%
}
\newcommand{\my@makebig}[2]{%
  \ifnarrow
    \def\scalefactor{0.8}%
  \else
    \def\scalefactor{1}%
  \fi%
  \vcenter{%
    \sbox\z@{$\m@th#1\sum$}%
    \setlength{\unitlength}{0.9\dimexpr\ht\z@+\dp\z@}%
    \hbox{\kern0.1\wd\z@\scalebox{\scalefactor}[1]{\my@draw{#1}{#2}}\kern0.1\wd\z@}%
  }%
}
\newcommand{\my@draw}[2]{%
  \begin{picture}(1,1)
    \linethickness{%
      \ifx#1\displaystyle 1.15\fontdimen8\textfont3\else
      \ifx#1\textstyle 1.05\fontdimen8\textfont3\else
      \ifx#1\scriptstyle1\fontdimen8\scriptfont3\else
      1\fontdimen8\scriptscriptfont3\fi\fi\fi
    }%
    #2
  \end{picture}%
}

\newcommand{\my@plus}{%
  \roundcap
  \Line(0.5,0)(0.5,1)
  \Line(0,0.5)(1,0.5)
}
\newcommand{\my@times}{%
  \roundcap
  \Line(0,0)(1,1)
  \Line(0,1)(1,0)
}
\newcommand{\my@box}{%
  \roundcap
  \Line(0,0)(1,0)
  \Line(1,0)(1,1)
  \Line(1,1)(0,1)
  \Line(0,1)(0,0)
}
\makeatother

\begin{document}

In-line $
\bigplus_{i\in I} X_i  = \bigtimes_{i\in J} Y_i = \bigbox_{i\in I} X_{i} = \bigcap_{i\in I} Z_{i} 
=  \bigcup_{n\in I} Z_{i}  = \sum_{i \in I} H_{i}
$. Display:
\[
\bigplus_{i\in I} X_i = \bigtimes_{i\in J} Y_i = \bigbox_{i\in I} X_{i}= \bigcap_{i\in I} Z_i 
=  \bigcup_{n\in I} Z_{i} = \sum_{i \in I} H_{i}
\]

In-line $
\bigplus_{i=0}^{\infty} X_i  = \bigtimes_{i=0}^{\infty} Y_i = \bigbox_{i=0}^{\infty} X_{i} 
= \bigcap_{i=0}^{\infty} Z_{i} =  \bigcup_{n=0}^{\infty} Z_{i} = \sum_{i =0}^{\infty} H_{i}
$. Display:
\[
\bigplus_{i=0}^{\infty} X_i = \bigtimes_{i=0}^{\infty} Y_i = \bigbox_{i=0}^{\infty} X_{i} 
= \bigcap_{i=0}^{\infty} Z_i =  \bigcup_{n=0}^{\infty} Z_{i} = \sum_{i=0}^{\infty} H_{i}
\]
\end{document}

输出:这就是xelatex产生的结果;的输出pdflatex是类似的。

大操作符号

有关的: 这个问题源于我最初的问题制作大加号和大乘号符号答案https://tex.stackexchange.com/a/552557/13492對它來說。

答案1

根据评论已修改。

\documentclass[fleqn]{article}
\usepackage{amsmath,pict2e,graphicx}
\usepackage{iftex}

\ifTUTeX
  \usepackage{unicode-math}
  \setmainfont{TeX Gyre Termes}[Scale=1.0]
  \setmathfont{TeX Gyre Termes Math}
\else
  \usepackage{newtxtext,newtxmath}
\fi

\makeatletter
\newcommand{\my@big}[2][1]{%
  \mathop{\vphantom{\sum}\def\scalefactor{#1}\mathpalette\my@makebig{#2}}\slimits@%
}
\AtBeginDocument{%
  \DeclareRobustCommand{\bigplus}{\DOTSB\my@big[.5]\my@plus}%
  \DeclareRobustCommand{\bigtimes}{\DOTSB\my@big[.75]\my@times}%
  \DeclareRobustCommand{\bigbox}{\DOTSB\my@big\my@box}%
}
\newcommand{\my@makebig}[2]{%
  \vcenter{%
    \sbox\z@{$\m@th#1\sum$}%
    \setlength{\unitlength}{0.9\dimexpr\ht\z@+\dp\z@}%
    \hbox{\kern0.1\wd\z@\scalebox{\scalefactor}[1]{\my@draw{#1}{#2}}\kern0.1\wd\z@}%
  }%
}
\newcommand{\my@draw}[2]{%
  \begin{picture}(1,1)
    \linethickness{%
      \ifx#1\displaystyle 1.15\fontdimen8\textfont3\else
      \ifx#1\textstyle 1.05\fontdimen8\textfont3\else
      \ifx#1\scriptstyle1\fontdimen8\scriptfont3\else
      1\fontdimen8\scriptscriptfont3\fi\fi\fi
    }%
    #2
  \end{picture}%
}

\newcommand{\my@plus}{%
  \roundcap
  \Line(0.5,0)(0.5,1)
  \Line(0,0.5)(1,0.5)
}
\newcommand{\my@times}{%
  \roundcap
  \Line(0,0)(1,1)
  \Line(0,1)(1,0)
}
\newcommand{\my@box}{%
  \roundcap
  \Line(0,0)(1,0)
  \Line(1,0)(1,1)
  \Line(1,1)(0,1)
  \Line(0,1)(0,0)
}
\makeatother

\begin{document}

In-line $
\bigplus_{i\in I} X_i  = \bigtimes_{i\in J} Y_i = \bigbox_{i\in I} X_{i} = \bigcap_{i\in I} Z_{i} 
=  \bigcup_{n\in I} Z_{i}  = \sum_{i \in I} H_{i}
$. Display:
\[
\bigplus_{i\in I} X_i = \bigtimes_{i\in J} Y_i = \bigbox_{i\in I} X_{i}= \bigcap_{i\in I} Z_i 
=  \bigcup_{n\in I} Z_{i} = \sum_{i \in I} H_{i}
\]

In-line $
\bigplus_{i=0}^{\infty} X_i  = \bigtimes_{i=0}^{\infty} Y_i = \bigbox_{i=0}^{\infty} X_{i} 
= \bigcap_{i=0}^{\infty} Z_{i} =  \bigcup_{n=0}^{\infty} Z_{i} = \sum_{i =0}^{\infty} H_{i}
$. Display:
\[
\bigplus_{i=0}^{\infty} X_i = \bigtimes_{i=0}^{\infty} Y_i = \bigbox_{i=0}^{\infty} X_{i} 
= \bigcap_{i=0}^{\infty} Z_i =  \bigcup_{n=0}^{\infty} Z_{i} = \sum_{i=0}^{\infty} H_{i}
\]
\end{document}

在此处输入图片描述

相关内容