Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question
3  
Another option is to use upper case letters for your commands: \AND, \OR, and \NOT. –  Aditya Sep 13 '11 at 0:28
1  
Ew! But yes, I guess that would work. –  jtbandes Sep 13 '11 at 0:29
1  
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
1  
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
add comment

2 Answers

up vote 12 down vote accepted

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.

share|improve this answer
    
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
1  
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
add comment

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}
share|improve this answer
6  
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.