2

So this question explains why \mathnormal doesn't actually return numbers in the default font, but doesn't offer any solution for achieving this.

I'm working with KaTeX and have a set of macros for bolding & colouring symbols, but would like to be able to define an \unstyle macro that exempts part of an expression. For example, if \blue{} applies \boldsymbol and {\color{blue}} to its argument, I'd like to be able to write something like:

\blue{x^3 + 2x \unstyle{+ x} - 12}

such that everything except the "+ x" is in boldsymbol and colour{blue} and the "+ x" is in the default ("normal" math).

NB. double invocation of \blue, like:

\blue{x^3 + 2x} + x \blue{- 12}

does not solve the issue, as it breaks the rendering of + and - as operators:

last term's addition operator has incorrect spacing

Any suggestions as to how to achieve this? I've played around with every combination of the fonts options available on KaTeX; however, the ones that resolve the issue for numbers change the font for the letters and vice-versa. I'm surprised that there isn't an actual "normalmath" (i.e. defaultmath) option.

Any advice would be greatly appreciated.

3
  • 1
    katex is javascript rather than tex so not really on topic but in latex assuming \blue{..} was defined as \textcolor{blue}{...} then you could restore the binary operator spacing by adding empty math atoms {} so x \blue{{}+12} Feb 21, 2021 at 1:30
  • Thank you for the suggestion for fixing the spacing. I wasn't sure about KaTeX -- noticed there wasn't a tag. What is the process for defining scope on new topics for TeX SE? Seems to me there is some scope of La/TeX-related questions that wouldn't be any more inappropriate here than other flavours of TeX (forgive me if this is naive: I am not very knowledgeable about the inner workings of any of these systems). I would be interested in helping this effort, if I could.
    – Rax Adaam
    Feb 21, 2021 at 23:36
  • there has been much discussion about mathjax and that has the same issues about emulating latex math syntax but not using tex. see tex.meta.stackexchange.com/questions/272/… for example or the mathjax tag wiki Feb 21, 2021 at 23:53

1 Answer 1

2
\newcommand\unstyle[1]{\textcolor{normalcolor}{#1}}

$\blue{x^3 + 2x \unstyle{+ x} - 12}$

$x^3+2x+x-12$

enter image description here

Of course, this doesn't work in standard LaTeX, but it could be adjusted.

\documentclass{article}
\usepackage{xcolor}

\newcommand{\blue}[1]{\textcolor{blue}{#1}}
\newcommand{\unstyle}[1]{\begingroup\normalcolor#1\endgroup}

\begin{document}

$\blue{x^3 + 2x \unstyle{+ x} - 12}$

$x^3+2x+x-12$

\end{document}

enter image description here

1
  • Thank you very much @egreg; however, the main challenge has been to undo the effect of boldsymbol, not the colour, alone. My apologies: excluding the colour would've made that clearer, but I didn't think of it, as the actual commands also apply colour.
    – Rax Adaam
    Feb 21, 2021 at 23:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .