悠闲数学娱乐论坛(第2版)'s Archiver

kuing 发表于 2017-6-12 02:35

两个符号重叠

转自:[url]http://bbs.ctex.org/forum.php?mod=viewthread&tid=153333[/url] 一个月前弄的,差点忘了存档。

要弄 [attach]11363[/attach] [attach]11364[/attach] 这样的符号

试着写了一个有通用性的重叠命令,缺陷及副作用尚未明确 :D[code]\documentclass{ctexart}
\usepackage{amsmath,amssymb}
\usepackage{mathtools}

%符号重叠命令\fhcd[类型]{符号}{符号}
%类型是最终输出的符号的类型(bin, rel, ord 等,默认 bin),两符号顺序随意
\makeatletter
\newcommand\fhcd[3][bin]{
\csname math#1\endcsname{\mathchoice
{\@fhcd\displaystyle{#2}{#3}}
{\@fhcd\textstyle{#2}{#3}}
{\@fhcd\scriptstyle{#2}{#3}}
{\@fhcd\scriptscriptstyle{#2}{#3}}}}
\newcommand\@fhcd[3]{
\settowidth\@tempdima{$\m@th#1{#2}$}
\settowidth\@tempdimb{$\m@th#1{#3}$}
\ifdim\@tempdimb>\@tempdima\@tempdima\@tempdimb\fi
\kern.5\@tempdima\mathclap{#2}\mathclap{#3}\kern.5\@tempdima}
\makeatother

\begin{document}

这样,第一个可以这样定义
\newcommand\cttdiv{\fhcd\bigtriangledown\cdot}

效果 $A\cttdiv B = A\bigtriangledown B\cdot C$
\[A\cttdiv B + \frac{\frac{A\cttdiv B}{A\cttdiv B}}{A\cttdiv B}\]

第二个直接这样定会有瑕疵
\newcommand\cttcurl{\fhcd\bigtriangledown\times}%
$A\cttcurl B$

突了点儿,只能调整下了,比如
\renewcommand\cttcurl{\fhcd\bigtriangledown
{\text{\raisebox{0.25ex}{\scalebox{0.75}{$\times$}}}}}%
$A\cttcurl B+\frac{A\cttcurl B}2$

还可以搞些其他东西

长的不等价
\let\iff\Longleftrightarrow
\newcommand\niff{\fhcd[rel]/\iff}
$A\niff B\iff C+\frac{A\niff B}{A\iff B}$

斜的不平行
\newcommand\px{\mathrel{/\mkern-5mu/}}%
\newcommand\npx{\fhcd[rel]\px\smallsetminus}%
$AB\px CD\npx EF$

无聊的
\newcommand\asdf{\fhcd[ord]\leftrightarrow\updownarrow}%
\newcommand\aaaa{\fhcd[ord]\nearrow\searrow}%
\newcommand\bbbb{\fhcd[ord]\nwarrow\swarrow}%
\newcommand\cccc{\fhcd[ord]\aaaa\bbbb}%
$\asdf \ \cccc$

\end{document}[/code][attach]11365[/attach]

kuing 发表于 2017-8-24 19:17

[url]https://liam0205.me/2017/06/30/create-overlayed-symbols-by-ooalign/[/url]
(使用 \ooalign 命令创建叠加在一起的记号)
这个帖讲的看起来更高大上一些,暂时还没完全理解……那个什么 \hidewidth ……还有后面那些……有空再研究下

kuing 发表于 2018-10-6 08:37

[b]回复 [url=http://kuing.orzweb.net/redirect.php?goto=findpost&pid=22533&ptid=4689]2#[/url] [i]kuing[/i] [/b]

“\ooalign 中,每一行都复写在上一行之上”
“\hidewidth 定义是 \hskip -1000pt plus 1fill”
照这两点来理解就能解释如下结果:[code]\documentclass{article}
\usepackage{xcolor}
\begin{document}

\newcommand\testoo[1]{\fbox{{%
\ooalign{%
Q\cr
#1\crcr
}}}\par}

\fboxsep=0pt

\newcommand\x{{\color{red}x}}
\newcommand\y{{\color{green}y}}
\renewcommand\o{{\color{blue}o}}
\newcommand\xx{{\color{red}xxxx}}
\newcommand\yy{{\color{green}yyyyyy}}
\newcommand\oo{{\color{blue}ooo}}

\testoo{}
\testoo{\x\hidewidth}
\testoo{\hidewidth\y}
\testoo{\hidewidth\o\hidewidth}
\testoo{\xx\hidewidth}
\testoo{\hidewidth\yy}
\testoo{\hidewidth\oo\hidewidth}
\testoo{\xx\hidewidth\yy}
\testoo{\xx\hidewidth\oo\hidewidth}
\testoo{\hidewidth\oo\hidewidth\yy}
\testoo{\xx\hidewidth\oo\hidewidth\yy}
\end{document} [/code][attach]6668[/attach]

除此之外,如果注意一下细节——深度,似乎 ooalign 的最终深度似乎只取决于最后一行,进而猜测:高度只取决于第一行?测试了一下似乎确实如此:[code]\fbox{{\ooalign{k\cr q\crcr}}} \fbox{{\ooalign{q\cr k\crcr}}}[/code]得出:[attach]6670[/attach]

这样看的话,ooalign 的方法还是存在缺陷嘀……
比如说文中用 {\ooalign{\$\bigcup\$\cr\hidewidth\$\bullet\$\hidewidth\cr}} 构造的 `\bigcup` 与 `\bullet` 重叠的符号,用 \fbox 来框一下就很清楚了:[code]\fbox{$\bullet$}
\fbox{$\bigcup$}
\fbox{{\ooalign{$\bigcup$\cr\hidewidth$\bullet$\hidewidth\cr}}}[/code][attach]6672[/attach]
原因就是后者深度由 \bullet 决定。
虽然多数时候没什么影响,但如果处于某些特殊情况下(例如繁分式),垂直间距或许就会有问题(贴得太近)。

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.