2

For my document I have some commands that write a bit of text in a different font-size. This works fine until I want to set this text as subscript. The text generated by my command then has the same absolute size in both cases (as expected).
Is there a way to modify my command in a way that it changes the size according to whether it is in normal script or subscript? I could have different commands for subscript and normal but then I would have to find adequate sizes for the subscript and my commands list would blow up even more.

MWE:

\documentclass{article}

\usepackage{amsmath}
\newcommand{\mytext}[0]{\text{\normalsize{World}}}
\begin{document}
    IS:\\
    Normal: Hello $\mytext$\\
    Subscript: Hello $_\mytext$\\
    \par
    WANT:\\
    Normal: Hello World\\
    Subscript: Hello $_\text{World}$
\end{document}

enter image description here
Obviously, I don't actually use \normalsize but e.g. \footnotesize, \small, etc.

4
  • 2
    There is the relsize package that provides the commands \larger and \smaller, which are relative to the current size.
    – Marijn
    Jul 30, 2021 at 15:45
  • thx, that's it. Do you want to post an answer?
    – Xoriun
    Jul 30, 2021 at 15:55
  • Done. As an unrelated comment: your use of \normalsize{argument} is incorrect, \normalsize is a switch that does not take arguments. It has local scope in a group (here the scope is the \text command) so you don't get any side effects in this particular case, but what happens is that \normalsize changes the font size for everything inside the scope and {} is ignored. So correct is {\normalsize World} which explicitly sets the scope around the switch and does not use arguments.
    – Marijn
    Jul 30, 2021 at 16:02
  • true, I forgot that in the MWE, but thx for point that out!
    – Xoriun
    Jul 30, 2021 at 16:59

1 Answer 1

2

The relsize package defines relative size commands. The main command is \relsize{n} with n positive or negative for larger and smaller text, respectively. There are also shortcut commands \larger and \smaller for \relsize{1} and \relsize{-1}.

To replicate the MWE the main command can be used:

\documentclass{article}
\usepackage{relsize}
\usepackage{amsmath}
\newcommand{\mytext}[0]{\text{\relsize{0}World}}
\newcommand{\mysmalltext}[0]{\text{\relsize{-1}World}}
\begin{document}
    IS:\\
    Normal: Hello $\mytext$\\
    Subscript: Hello $_\mytext$\\
    \par
    WANT:\\
    Normal: Hello World\\
    Subscript: Hello $_\text{World}$\\
    \par
    IS:\\
    Normal: Hello $\mysmalltext$\\
    Subscript: Hello $_\mysmalltext$\\
\end{document}

Result:

enter image description here

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.