1

I would like to use smaller fonts for the subscripts and superscripts in a user-defined LaTeX command. Do you have any ideas how to scale down the subscripts/superscripts proportionally? My MWE is the following:

\documentclass{article}

\usepackage{etoolbox} \usepackage{ifmtarg}

\newcommand{\defineSpecies}[2]{\csdef{spec@#1}{#2}} \newrobustcmd{\spec}[1]{% \ifcsname spec@#1\endcsname% \csuse{spec@#1}% \else \GenericError{}{Undefined species `#1'}{}{} \fi }

\defineSpecies{hhe3+}{HHe$_3^+$}

\begin{document}

\fontsize{5}{6}\selectfont \spec{hhe3+}

\end{document}

Here I would like to have much smaller subscript 3 and superscript +. A solution modifying the \spec{} command globally would be preferred, as I have a lot of species defined such a way. I would not switch to other 'chemistry' packages but stick to this command.

TobiR
  • 584

1 Answers1

1

I am assuming your question is

I changed the text font size to be 5pt, but now the superscript and subscripts look too large; how do I change them to match?

Since you are creating the super/subscripts using math mode, you need to change the math sizes. This is accomplished through the \DeclareMathSizes{}{}{}{} command. In the example below I changed script size to 3pts and scriptscript size to 2pts.

(As an aside, since you didn't specify a fancy font, we are using Computer Modern, which doesn't allow arbitrary scalings; to fix that we load fix-cm.)

\RequirePackage{fix-cm}
\documentclass{article}
\usepackage{etoolbox}
\usepackage{ifmtarg}

\newcommand{\defineSpecies}[2]{\csdef{spec@#1}{#2}} \newrobustcmd{\spec}[1]{% \ifcsname spec@#1\endcsname% \csuse{spec@#1}% \else \GenericError{}{Undefined species `#1'}{}{} \fi }

\defineSpecies{hhe3+}{HHe$_3^+$}

\DeclareMathSizes{5}{5}{3}{2}

\begin{document}

\fontsize{5}{6}\selectfont \spec{hhe3+}

\end{document}

enter image description here

Willie Wong
  • 24,733
  • 8
  • 74
  • 106
  • 1
    Remark: if you use multiple different font sizes throughout your document, you may need to have a corresponding \DeclareMathSizes for each text size. – Willie Wong Jun 06 '23 at 17:22