2

Is it possible to define a macro which (in math mode) typesets normal math and subscripts in different fonts?

Concretely, I am interested in typesetting the math in roman and the subscripts in italic, such that

$\mymacro{A_pB_r}$

would result in

enter image description here


In response to an answer, let me clarify that the hope would be that this works on equal footing for a general parameter string (at least as long as it only includes characters and alphanumerical subscripts), such as $A_pB_r$, $ABC_s$, $A_xBC_y$, and so further. Clearly, this can be broken down to individual letters with & without subscripts, but this would make the involved expressions extremely cumbersome and lengthy to type up.

4

enter image description here

\documentclass{article}

\def\mymacro#1{\mbox{$\textfont1=\textfont0 #1$}}

\begin{document}

$\mymacro{A_pB_r}$

\end{document}
5
  • This will break some things expecting to find the math italic font in slot 1, but ... Sep 4 '18 at 20:22
  • Cool, thanks! How does it work? (Or rather: Where can I learn how it works? Seems pretty simple!)
    – Norbert
    Sep 4 '18 at 20:30
  • ... Ah, guess I found it out! :) Thanks again!
    – Norbert
    Sep 4 '18 at 20:33
  • 1
    @Norbert TeXBook has the details of this (and other things). Is this for Chemistry? (in which case one of the dedicated chemistry packages would be better) Sep 4 '18 at 20:37
  • Cool, thanks (though reading 500 pages to understand how to do this sounds a bit intimidating :-/ ). No, it's not for chemistry -- some self-cooked-up notation for physics/math. Not even sure it will stay like that, which is one reason why I'd prefer a macro.
    – Norbert
    Sep 4 '18 at 20:57
1

The unicode-math package supports this through the \setmathfont[script-font = ...] option. Here is a contrived example that sets the script font to XITS Math:

\documentclass[varwidth, preview]{standalone}
\usepackage{unicode-math}

\setmathfont[Scale = MatchLowercase,
             script-font = XITS Math
            ]{Latin Modern Math}

\begin{document}
\( t_x + \beta_\rho = b_a
\)
\end{document}

Latin Modern Math, XITS scripts

For comparison, using the default settings:

Latin Modern Math

According to §4.2 of the unicode-math manual, this is intended to be used with fonts such as Minion Math. However, some families of text fonts package the smaller size as a different font, for example, to use Aldus as the script size for Palatino.

If your font comes with optical sizes but not mathematical script sizes, you would select those with script-features and sscript-features.

ETA

It’s possible to change the math font in the middle of a document or to have more than one math version. If you want to set only a few subscripts in a particular font, one way to do it is _\text{...}, then use text-mode font-selection commands inside the braces. Optionally wrap that in \mathord{} or \mathop{}, as appropriate. If you do this more than once, make it a comamnd in your preamble.

2
  • Thanks! Though I guess with will change it for all formulas, rather only for selected ones (which is what I am looking for).
    – Norbert
    Sep 4 '18 at 20:58
  • 1
    @Norbert Added an addendum.
    – Davislor
    Sep 4 '18 at 21:05
0

Maybe that? It's definitely not the best answer, but (at least) a proposal …

\documentclass{article}
\usepackage{amsmath,amssymb,amsfonts}
\newcommand{\mycom}[2]{\mathrm{#1}_{#2}}
\begin{document}
    \Huge
    \[
        \mycom{A}{p} \ \mycom{B}{r}
    \]
\end{document}

Here is the output:

Screenshot

1
  • 1
    Ah, I should have been more specific: I don't know in which form the parameters will be passed -- some will have subscripts, some won't, and their number will also be different. Would be good if I this could all be taken care of by one macro.
    – Norbert
    Sep 4 '18 at 17:25

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.