Math & Science ⇒ newcommand superscript
newcommand superscript
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!
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- Stefan Kottwitz
- Site Admin
- Posts: 10324
- Joined: Mon Mar 10, 2008 9:44 pm
newcommand superscript
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}}}}
Stefan
newcommand superscript
Which is exactly why I'm using it...\textnormal prevents the italic shape which is normally used in math sub-/superscripts.

- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
newcommand superscript
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}
-- Zapp Brannigan, Futurama (season 1, episode 4)