
자주 사용하는 복잡한 표현식의 별칭이라는 명령이 있는데 새 별칭을 도입하지 않고 이를 무효화하고 싶습니다.
간단한 솔루션은 기본값을 사용하여 세 번째 인수를 도입하지만 작성하기가 지저분합니다. \myCommand[\neq]{arg1}{arg2}
같은 것이 \not\myCommand{arg1}{arg2}
훨씬 더 좋습니다.
예:
\newcommand{\divides}[2]{\ensuremath{#1\mid #2}}
두 가지 답변 모두 감사드립니다. 이제 어디를 살펴봐야 할지 알겠습니다.
답변1
나는 접두사 대신 *-변형을 사용한 구문을 제안합니다 \not
.
\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{xparse}
\NewDocumentCommand{\newrelation}{mmo}{%
% #1 is the command to define
% #2 is the relation to be used
% #3 (optional) is the alternative
\IfNoValueTF{#3}
{\NewDocumentCommand{#1}{smm}{%
\IfBooleanTF{##1}{##2\not#2##3}{##2#2##3}%
}%
}
{\NewDocumentCommand{#1}{smm}{%
\IfBooleanTF{##1}{##2#3##3}{##2#2##3}%
}%
}%
}
\newrelation{\EQ}{=}
\newrelation{\LESS}{<}
\newrelation{\divides}{\mid}[\nmid]
\begin{document}
$\EQ{a}{b}$ and $\EQ*{a}{b}$
$\LESS{a}{b}$ and $\LESS*{a}{b}$
$\divides{a}{b}$ and $\divides*{a}{b}$
\end{document}
말하는 것은 \newrelation{\EQ}{=}
타이핑하는 것과 같다
\NewDocumentCommand{\EQ}{smm}{%
\IfBooleanTF{#1}% true if * is present
{#2\not=#3}%
{#2=#3}%
}
while은 \newrelation{\divides}{\mid}[\nmid]
타이핑하는 것과 같습니다
\NewDocumentCommand{\divides}{smm}{%
\IfBooleanTF{#1}% true if * is present
{#2\nmid#3}%
{#2\mid#3}%
}
예를 들어, \not\in
가 틀렸기 때문에 다음을 수행할 수 있습니다.
\newrelation{\IN}{\in}[\notin]
결과는 적절하게 조판될 것입니다. 마찬가지로, \not\mid
나쁜 결과를 제공하므로 \nmid
선호되어야 합니다.
접두사 사용을 선호하는 경우 다음과 같습니다(동일한 출력).
\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{xparse}
\NewDocumentCommand{\newrelation}{mmo}{%
% #1 is the command to define
% #2 is the relation to be used
% #3 (optional) is the alternative
\IfNoValueTF{#3}
{%
\NewDocumentCommand{#1}{mm}{##1#2##2}%
\expandafter\NewDocumentCommand\csname negate\string#1\endcsname{mm}{##1\not#2##2}%
}%
{%
\NewDocumentCommand{#1}{mm}{##1#2##2}%
\expandafter\NewDocumentCommand\csname negate\string#1\endcsname{mm}{##1#3##2}%
}%
}
\makeatletter
\NewDocumentCommand{\negate}{m}{%
\@ifundefined{negate\string#1}
{\@latex@error{Undefined relation}{}#1}{\@nameuse{negate\string#1}}%
}
\makeatother
\newrelation{\EQ}{=}
\newrelation{\LESS}{<}
\newrelation{\divides}{\mid}[\nmid]
\begin{document}
$\EQ{a}{b}$ and $\negate\EQ{a}{b}$
$\LESS{a}{b}$ and $\negate\LESS{a}{b}$
$\divides{a}{b}$ and $\negate\divides{a}{b}$
\end{document}
답변2
설정 작업이 필요하지만 완료할 수 있습니다. 본질적으로 다양한 기호에 대해 원하는 "A 기호 B"를 수행하는 다양한 매크로를 정의한 다음 \negate
이러한 각 기호를 차례로 부정하는 방법을 알기 위해 정의해야 합니다.
\documentclass{article}
\usepackage{stackengine,xcolor,mathtools}
\def\eqsym{=}
\def\gtsymbol{>}
\let\svmid\mid
\let\svgtsymbol\gtsymbol
\newcommand{\divides}[2]{\ensuremath{#1\mid #2}}
\newcommand{\equals}[2]{\ensuremath{#1\eqsym #2}}
\newcommand\greaterthan[2]{\ensuremath{#1\gtsymbol #2}}
\newcommand\negate[1]{%
\ifx\divides#1\def\mid{\mathrlap{\,/}\svmid}\else%
\ifx\equals#1\let\eqsym\neq\else%
\ifx\greaterthan#1\def\gtsymbol{\mathrlap{\,\,/}\svgtsymbol}\else%
\fi\fi\fi%
#1%
}
\begin{document}
$\divides{1}{2} \quad \negate\divides{1}{2}$
$\equals{1}{2} \quad \negate\equals{1}{2}$
$\greaterthan{1}{2} \quad \negate\greaterthan{1}{2}$
$\divides{1}{2} \quad \equals{1}{2} \quad \greaterthan{1}{2}$
\end{document}
부록:
egreg 정의의 용이성과 내 접근 방식의 구문을 결합하는 한 가지 방법은 추가 정의와 함께 그의 MWE를 사용하는 것입니다.
\def\negate#1{#1*}
그런 식으로,
$\EQ{a}{b}$ and $\negate\EQ{a}{b}$
$\LESS{a}{b}$ and $\negate\LESS{a}{b}$
$\divides{a}{b}$ and $\negate\divides{a}{b}$
그의 MWE와 동일한 결과를 생성합니다.