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.

Is there any more convenient (concise) way to insert Math-mode Accents? For example is it possible to use a syntax like following:

a\^ %instead of \hat{a} 
a\- %instead of \bar{a}
a\~ %instead of \tilde{a}

or

\^a %instead of \hat{a} 
\-a %instead of \bar{a}
\~a %instead of \tilde{a}
share|improve this question
2  
If you do not need the text mode accents you can just go \let\^\hat and use \^ . If you do want \^ to work as before in text mode then it's a bit trikier (and quite hard to do in a way that will never affect text mode kerns) –  David Carlisle Aug 9 '12 at 13:11

1 Answer 1

up vote 7 down vote accepted

You can do this by redefining the accent macros only for mathmode, using the \everymath and \everydisplay token lists. You can do this as follows:

% Create a token list for your custom math accent macros
\newtoks\mymathaccents
\mymathaccents={%
  \let\^\hat
  \let\-\bar
  \let\~\tilde
  % etc.
}

% The following adds your custom macros for math accents
% to both inline and displayed math mode 
\everymath=\expandafter\expandafter\expandafter{%
           \expandafter\the\expandafter\everymath\the\mymathaccents} 

\everydisplay=\expandafter\expandafter\expandafter{%
              \expandafter\the\expandafter\everydisplay\the\mymathaccents} 

This should also preserve the normal meanings of the accent macros for text mode. — Note that for the other part of your question: there is no mechanism to define a new macro to accept an argument which immediately precedes it, as in the examples you give.

share|improve this answer

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.