Math & Sciencenewcommand superscript

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
dax42
Posts: 11
Joined: Wed Jun 16, 2010 1:07 pm

newcommand superscript

Post by dax42 »

Hi there,

I would like to define a new command to make sub- and superscripts easier. I found this online, which works well:

\newcommand{\super}[1]{\ensuremath{^{\textnormal{#1}}}}
\newcommand{\sub}[1]{\ensuremath{_{\textnormal{#1}}}}

However, my normal text is 11pt and thus the sub/superscripted letters are too big for my taste. How can I define this command so it uses, say, 8pt?

Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10321
Joined: Mon Mar 10, 2008 9:44 pm

newcommand superscript

Post by Stefan Kottwitz »

Hi,

insert an appropriate font size command. To match the size LaTeX uses for subscripts choose \scriptsize, like

Code: Select all

\newcommand{\super}[1]{\ensuremath{^{\textnormal{\scriptsize #1}}}}
Btw. \textnormal prevents the italic shape which is normally used in math sub-/superscripts.

Stefan
LaTeX.org admin
dax42
Posts: 11
Joined: Wed Jun 16, 2010 1:07 pm

newcommand superscript

Post by dax42 »

Sweet, thanks!
\textnormal prevents the italic shape which is normally used in math sub-/superscripts.
Which is exactly why I'm using it... :)
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

newcommand superscript

Post by svend_tveskaeg »

@dax42:
Morten Høgholm once came up with an elegant solution on a Danish mailing list:

Code: Select all

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools}

\makeatletter
 \newcommand\textupperscript[2]{%
  \@textupperscript{\selectfont#1}{\selectfont#2}
 }
 \def\@textupperscript#1#2{%
  {\m@th\ensuremath{%
    ^{\mbox{\fontsize\sf@size\z@#1}}
    _{\mbox{\fontsize\sf@size\z@#2}}
  }}
 }
\def\@super{^}
\def\@sub{_}

\catcode`^\active
\catcode`_\active
  \def\@super@sub#1_#2{\textbothscript{#1}{#2}}
  \def\@sub@super#1^#2{\textbothscript{#2}{#1}}
    \def\@@super#1{\@ifnextchar_{\@super@sub{#1}}{\textsuperscript{#1}}}
    \def\@@sub#1{\@ifnextchar^{\@sub@super{#1}}{\textsubscript{#1}}}
      \def^{\let\@next\relax\ifmmode\@super\else\let\@next\@@super\fi\@next}
      \def_{\let\@next\relax\ifmmode\@sub\else\let\@next\@@sub\fi\@next}
\makeatother

\begin{document}
Something:
\begin{equation*}
  \Psi\textupperscript{Horse}{Fish}(x)
\end{equation*}
\end{document}
I hope this is (somewhat) what you are looking for.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply