Math & ScienceOverride \not

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
arobase
Posts: 33
Joined: Sat Apr 14, 2012 7:46 pm

Override \not

Post by arobase »

Is there a way to selectively override \not? For example,
I'd like to define \not\mycmd as

Code: Select all

\text{not}\mycmd

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Override \not

Post by cgnieder »

I'm not sure what you're after exactly. It is no problem at all to redefine a command:

Code: Select all

\documentclass{article}
\newcommand*\mycmd{foobar}
\renewcommand*\not{not}
\begin{document}
\not\mycmd
\end{document}
Since you saying you'd like \not to be \text{not} I'm guessing you want something like a math operator?

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\newcommand*\mycmd{baz}
\let\not\relax
\DeclareMathOperator\not{\text{not}}
\begin{document}
\[\not\mycmd\]
\end{document}
Regards
site moderator & package author
arobase
Posts: 33
Joined: Sat Apr 14, 2012 7:46 pm

Override \not

Post by arobase »

Thanks, I should have been more clear about 'selectively override'. I don't want to change the default behavior of \not, only in combination with \mycmd. In hindsight, it's not a big requirement for me.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Override \not

Post by cgnieder »

That's possible:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\newcommand*\mycmd{blub}
\makeatletter
\let\orig@not\not
\DeclareMathOperator\spec@not{\text{not}}
\renewcommand*\not{\@ifnextchar\mycmd{\spec@not}{\orig@not}}
\makeatother
\begin{document}
\[\not\mycmd ~ \not A\]
\end{document}
Regards
site moderator & package author
arobase
Posts: 33
Joined: Sat Apr 14, 2012 7:46 pm

Re: Override \not

Post by arobase »

Worthwhile, thanks.
Post Reply