[comp.text.tex] Gripe about _ and ^

jeffrey@cs.chalmers.se (Alan Jeffrey) (02/24/91)

Why oh why oh why do ^ and _ in TeX not take their arguments in the 
`standard' way?  For example, if you say
 
   \def\nil{[]}
   $a_\nil$
 
you get `a ]' and not `a  '.
          [             []
 
In this case we're OK, because \nil should be an ord, so we can just say 
 
   \def\nil{{[]}}
 
instead, and we're all right.  But if we want to define a bin, rel, op, 
or whatever, we're in real trouble, for example
 
   \def\may{\mathrel{\it may}}
   $a_\may$
 
produces the error message
 
   ! Missing { inserted.
   <to be read again>
                      \mathrel
   \may ->\mathrel
                   {\it may}
   <*> $a_\may
              $
 
because TeX interprets this as $a_\mathrel{\it may}$, and `obviously' 
a_\mathrel is rubbish.  As far as I can see, the only options are
 
   a) either type _\foo or _{\foo} depending on what the definition of 
      \foo is, which rather spoils the point of logical markup, or
   b) consistently type _{\foo}, which is a right pain, or
   c) redefine _ and ^.
 
Has anyone any better suggestions?
 
Cheers,
 
Alan.
Alan Jeffrey         Tel: +46 31 72 10 98         jeffrey@cs.chalmers.se
Department of Computer Sciences, Chalmers University, Gothenburg, Sweden

stucki@math.fu-berlin.de (C. v. Stuckrad) (02/26/91)

jeffrey@cs.chalmers.se (Alan Jeffrey) writes:

> ...
>   a) either type _\foo or _{\foo} depending on what the definition of 
>      \foo is, which rather spoils the point of logical markup, or
>   b) consistently type _{\foo}, which is a right pain, or

The only Solution we found, was to configure the editors we use
( UNIX vi and MS/DOS Brief ) to generate the {} pairs after _{} and ^{}
automagically and put the cursor in front of the closing one.

In fact we redefined the opening brace to be both (Position in between)
and the closing brace skips over the next closing brace in the file
(which of course you really have to get used to!).

> 
>Has anyone any better suggestions?
> 

I believe our solution not to be better,
but it includes a lot less forgotten closing brackets and braces
and so is better than learning about the definitions of macros
which were created by staff members and are used by the secretaries.

If somebody is interested I can mail him the Brief(MsDOS) macro packet,
but i have not created any installation support yet.
 May be that is a way to solve it ???
 Yours Stucki
-- 
 Christoph von Stuckrad      *  *   !  talk to   ! <stucki@math.fu-berlin.de>  
 Freie Universitaet Berlin   |/__*  !  nickname  ! ...!unido!fub!leibniz!stucki
 Fachbereich Mathematik, EDV |\  *  !  'stucki'  ! Tel.: 49 30 838-5916
 Arnimallee 2-6              * *    !   on IRC   ! Fax:  49 30 838-5913

jeffrey@cs.chalmers.se (Alan Jeffrey) (02/28/91)

Further to my comments on how ^ and _ take in their arguments, I did a
quick hack, and you can say

\catcode`\^=\active \def^#1{\sp{#1}}
\catcode`\_=\active \def_#1{\sb{#1}}

and then use ^ and _ as macros which take in their arguments in the
standard way.  The only problems I can think of with this are

a) _ normally produces \_ when activated, so some macros which rely on
this won't work

b) there may be macro files out there that explicity catcode ^ and _
to sub- and superscript, as a way of returning to what they think the
status quo is.

c) you have to do it *after* all the other .sty files have been read
in, as some of them may assume ^ and _ are sub- and superscript.

But I don't think most LaTeX documents would be affected.  Does
anyone have evidence to the contrary, before I start using it as
standard (I'm tired of having to type _{\blah} half the time), and
more importantly, it makes the source files much harder to read
(really, or at least it does for me).

Cheers,

Alan.

Alan Jeffrey         Tel: +46 31 72 10 98         jeffrey@cs.chalmers.se
Department of Computer Sciences, Chalmers University, Gothenburg, Sweden