10

Let's say I want to write N^{eT}, but have N^e as a predefined command \Ne. Thus, I want to append the character T to the superscript of \Ne. Is this possible?

(Note that I don't want to write {\Ne}^T, since that will result in the T being one level above the e. This was adressed in Trick LaTeX into doing double superscripts by the way)

andreasdr
  • 615
  • 1
    It may help to explain how you intend to use the macro. Something along the lines of \def\Ne#1{$N^{e#1}$} is acceptable in your case? (usage: \Ne T) – guillem Apr 19 '12 at 14:46
  • 1
    What about using $\Ne{}^T$ (maybe putting it into a box to prevent a break between e and T)? – Stephen Apr 19 '12 at 18:08
  • Haha, I actually didn't know that was possible, Stephen. Thanks! – andreasdr Apr 19 '12 at 19:54
  • Similar question has been answered some time ago: http://tex.stackexchange.com/questions/33261/defining-a-newcommand-with-sub-or-superscript-and-avoiding-double-subscript-e – amorua Apr 19 '12 at 20:45

3 Answers3

15

Or what about an empty optional argument?

\newcommand*\Ne[1][]{N^{e#1}}

Which you can use

$\Ne$ or $\Ne[T]$
Danie Els
  • 19,694
  • Accepted for conciseness. Thanks to all responders! – andreasdr Apr 19 '12 at 15:18
  • By the way, what does the asterisk after "\newcommand" do? – andreasdr Apr 19 '12 at 15:45
  • 2
    @andreasdr: The starred variant of \newcommand removes the capability to include lengthy arguments (like paragraphs). Surely, since your superscripts will only contain characters (not paragraphs), using \newcommand* is appropriate. – Werner Apr 19 '12 at 16:12
  • @andreasdr: A more detailed explanation of \newcommand* can be found at http://tex.stackexchange.com/questions/1050/whats-the-difference-between-newcommand-and-newcommand – Jake Apr 24 '12 at 10:40
8

Here is a "clever hack" inspired by (read: shamelessly copied from) the definition of math prime:

\documentclass{article}

\makeatletter
\def\Ne{N^\bgroup\e@s}
\def\e@s{%
  e\futurelet\@let@token\e@@s}
\def\e@@s{%
  \ifx^\@let@token
     \expandafter\expandafter\expandafter\e@@@s
  \else
     \egroup
  \fi}
\def\e@@@s#1#2{#2\egroup}
\makeatother

\begin{document}
\[
\Ne^T \Ne^T_5
\]
\end{document}

You can do \Ne^{}_{} but not \Ne_{}^{}, otherwise the positioning is exactly as N^{}_{}

4

I would define \Ne in the following way:

\newcommand{\Ne}{\ensuremath{N^e\vphantom{N}}}

This ensures that any following superscripts start at the same height as regular superscripts to N, but also trick TeX in thinking that it's not doubling a superscript:

enter image description here

\documentclass{article}
\newcommand{\Ne}{\ensuremath{N^e\vphantom{N}}}
\begin{document}
\Ne\ $\Ne^T$\ $N^{eT}$
\end{document}

Note that this will not work properly for subscripts, since the placement will be off. It would require more effort to make that work.

Werner
  • 603,163