# Is it safe to temporarily redefine \and, \or, and \not?

I'm writing lots of logic expressions in LaTeX and I'd much rather write $p \and \not q \or r$ than $p \land \lnot q \lor r$. I was thinking of doing something like this:

\newenvironment{logic}{%
\renewcommand\and\land%
\renewcommand\or\lor%
\renewcommand\not\lnot%
}{}


Then I could simply

\begin{logic}
p \and \not q \or r
\end{logic}


Are the commands \and, \or, and \not built into TeX? Is it safe to temporarily redefine them? If not, can you recommend any alternatives? Thanks!

-
Another option is to use upper case letters for your commands: \AND, \OR, and \NOT. –  Aditya Sep 13 '11 at 0:28
Ew! But yes, I guess that would work. –  jtbandes Sep 13 '11 at 0:29
If all you're after is a faster way to write those symbols you might be better of using an editors features for this, e.g. to use snippets management or autocompletion features. –  N.N. Sep 13 '11 at 7:34
I also want to be able to read the source in the future, after not having look at it for a while. –  jtbandes Sep 13 '11 at 23:50

They are not built into TeX (which is called primitive in TeX). For example, \and is defined by latex as \end {tabular}\hskip 1em \@plus .17fil\begin {tabular}[t]{c}. However \or, unlike \and and \not, is not a macro but a TeX primitive. It is not a good idea to redefine it.

I think you do can overwrite them if you like as long as you enclose them within in a group, or you won't use their original meaning. For example, you are not likely to use \and after \author in most cases.

-
Thanks for the info. Could you describe what they do, or at least refer me to somewhere I could find out? –  jtbandes Sep 13 '11 at 0:28
\and is used within in \author. The standard classes define \maketitle such that before \@author is typeset, a \begin{tabular}... is insert, and after that \end{tabular}, sort of. \not is just a macro for typeset a math char. \or is used in \ifcase, another primitive. For reference of primitives, The TeXbook is the ultimate source. tug.org/utilities/plain/cseq.html is also a good place to find things about that. For other latex or plain tex macros, there is no one-stop place to learn. –  Yan Zhou Sep 13 '11 at 3:44
Slight problem: some documentclasses need their specific definition of \and in the headers. (Journal styles with authors in header, mostly.) –  Ulrich Schwarz Sep 13 '11 at 6:15

The macros \and and \not are predefined in LaTeX, but the former is generally used in the \author{} command to separate authors, while the latter is used (generally) to form the negation of already-existing symbols, as in \not\perp (not orthogonal).

The MWE below uses the \xspace macro to automate good spacing following the redefined commands in non-math mode.

\documentclass{article}
\usepackage{xspace}
\newenvironment{logic}
{\renewcommand{\and}{\ensuremath{\land}\xspace}
\renewcommand{\or}{\ensuremath{\lor}\xspace}
\renewcommand{\not}{\ensuremath{\lnot}}}
{}
\begin{document}
\begin{logic}
$p$ \and \not $q$ \or $r$
\end{logic}
\end{document}

-
You don't need to restore the original meanings of the commands since they get restored automatically when you leave the group where the new meanings are defined. Of course saving them is probably the smart thing to do since you might want to use the original command(s) in your environment for something. PS: It should probably be \renewcommand{\and}{\ensuremath{\land}\xspace} - the two symbols might not be the same in all fonts –  kahen Sep 13 '11 at 2:31
This is wrong under many respects: the spacing in the formula is completely fooled up; and if you happen to use \begin{logic}...\foo...\end{logic}, where \foo is based on the primitive \or, you'll understand why a primitive should never be redefined unless in a very controlled environment. –  egreg May 9 at 23:06