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)

  • 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: tex.stackexchange.com/questions/33261/… – amorua Apr 19 '12 at 20:45
15

Or what about an empty optional argument?

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

Which you can use

$\Ne$ or $\Ne[T]$
  • 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 tex.stackexchange.com/questions/1050/… – 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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