3

I have some locally defined commands such as

\newcommand{\cosx}[1]{\color{blue}\boldsymbol \cos^{#1} x}

and I would like to be able to unbold some part of it. Is there a more elegant way to achieve this than by repeating the commands as in:

\newcommand{\cosx}[1]{{\color{blue}\boldsymbol \cos}^{#1} {\color{blue}\boldsymbol x}}

e.g. some way of wrapping the section to be formatted normally?

I saw this question, but I believe that issue is actually more complicated as it feeds a bolded symbol into a new command; moreover, the solutions presented are beyond my ability to generalize to other situations (i.e. my question could be generalized to 'how to exempt a section in math mode from formatting (bold, colour, font etc)?').

4
  • 1
    \unboldmath, perhaps? – user31729 Feb 15 '17 at 21:02
  • thanks, but this wouldn't work for the colours or fonts, & does not appear to work for the bold, either... – Rax Adaam Feb 15 '17 at 21:09
  • \boldsymbol takes an argument so in your example it only applies to \cos how can you unbold only part of that? – David Carlisle Feb 15 '17 at 23:16
  • the first command has the \boldsymbol apply to everything i.e. \cos^{#1} x; the 2nd is a hacked version showing the effect I was trying to achieve. – Rax Adaam Feb 16 '17 at 20:40
3

I think you want (not sure why)

\documentclass{article}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{xcolor}

\DeclareMathOperator{\bcos}{\textcolor{blue}{\mathbf{cos}}}
\newcommand{\bx}{\textcolor{blue}{\bm{x}}}

\begin{document}

$\bcos^2\bx$

\end{document}

enter image description here

If you really want the \cosx macro, add

\newcommand{\cosx}[1]{\bcos^{#1}\bx}
4
  • This achieves the desired effect (I am a teacher & do extensive colour-coding in my notes to help students follow steps and see the most important info), but seems to me a variation on what I posted. Is there nothing like $\bm{\cos x \cdot \normalmath{\sin x} \cdot \cos x} = \cos^{\bm{2}}x \cdot \sin x where everything inside \normalmath{ } would be rendered in default font-style? – Rax Adaam Feb 16 '17 at 20:49
  • & is there any reason to use \DeclareMathOperator{} over \newcommand for the blue / bold cos(x)? Would be interested to learn more if you can point me in the right direction. Thank you kindly for all your help! – Rax Adaam Feb 16 '17 at 20:50
  • 1
    @RaxAdaam The main reason is that as an operator, the symbol gets the right spacing. – egreg Feb 16 '17 at 21:47
  • thank you - that is enormously helpful to know & stands to simplify a lot of the local commands I've implemented. – Rax Adaam Feb 23 '17 at 20:42

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.