![如何向命令添加新参数来控制缩放?](https://linux22.com/image/417422/%E5%A6%82%E4%BD%95%E5%90%91%E5%91%BD%E4%BB%A4%E6%B7%BB%E5%8A%A0%E6%96%B0%E5%8F%82%E6%95%B0%E6%9D%A5%E6%8E%A7%E5%88%B6%E7%BC%A9%E6%94%BE%EF%BC%9F.png)
以下代码稍作修改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}