If my codes have a statement like ${\bfseries{\emph{something}}$, it will return an error:

\bfseries invalid in math code.

But if I change the order of the control sequences, like this ${\emph{\bfseries{something}}$, everything is fine. Why is that?

  • 1
    Welcome to TeX.SX! You can highlight code in your post using back-ticks. To highlight code-blocks, either indent them by four spaces or use the {} on the gui. – Andrew Dec 6 at 5:19
  • Why don't you use $\textbf{...}$? – JouleV Dec 6 at 5:22
  • Thanks for the help.I'm new here.@Andrew – StevenZ Dec 6 at 5:22
  • @JouleV.Yeah,I also know that key word, but it only works in English. – StevenZ Dec 6 at 5:26
  • Did you use a language other than English? If so, did you use babel? Or did you use xeCJK? – zyy Dec 6 at 5:29

\emph is defined to be a "text command" and therefore sets its argument in text mode. That's why you're allowed to use

$\emph{\bfseries <stuff>}$

since \bfseries occurs within text mode. The other way around,

$\bfseries\emph{<stuff>}$

\bfseries occurs inside math mode, which is not allowed.

If you want to set text in bold inside math, consider using \textbf{<stuff>} or \text{\bfseries <stuff>} if you're using amsmath. If you want bold math content, you can use \mathbf. Alternatively, if you want bold italic math content, use $\bm{<stuff>}$ and also add \usepackage{bm} to your preamble.

Note how \bfseries is used above; there is no argument. That is, {\bfseries ...}, not \bfseries{...}.

  • That's impressive!Thanks! – StevenZ Dec 6 at 8:02

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.