TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any preference for using \textbf or \mathbf in math mode; or \textbf works exactly the same as \mathbf in math mode? I know for example, the \textit does not work in some cases in math mode, e.g. $\textit{text1^{text2}}$ gives an error, but $\mathit{text1^{text2}}$ is valid. On the other hand, \textcolor is "usually" a better choice than \color in math mode [Ref: This post]

share|improve this question
up vote 10 down vote accepted

Spaces are ignored in the arguments of \mathbf and \mathit, but not in the arguments of \textbf and \textit.

enter image description here

Also, you can't combine \mathbf and \mathit. E.g., \mathbf{\mathit{xyz}} produces xyz rather than xyz.

And, of course, the outputs of \mathbf and \textbf will differ if you use different fonts for math-mode and text-mode material.

\documentclass{article}
\begin{document}
$\textbf{abc def}$ 

$\mathbf{abc def}$

$\textit{abc def}$

$\mathit{abc def}$
\end{document}
share|improve this answer
    
Thank you all. All of the responses deserve credits since they all provided additional information. I've concluded that I, by enlarge, should use mathbf when in math mode. – nam Feb 18 at 16:21

\textbf uses the text font (Libertine in the example) and \mathbf uses the math font (computer modern) -- same happens for \textrm and \mathrm. Libertine has no math, the reason why TeX takes the default math font. And, of course, text and math font maybe looking very different.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{libertine}
\begin{document}

$\textbf{some text}~\mathbf{some text}~some text$

\end{document}

enter image description here

share|improve this answer

The technical difference are described here Difference between \textrm{} and \mathrm{}

But more important is the semantic difference: \text... commands switch to text mode, and so they should be used, if you want to write text, that means words like "and" or "it follows that" etc. \math... commands write math, and so should be used for variables with mathematical meaning. Normally there argument is short -- only one char, sometimes some more as e.g. V_{\mathrm{max}}.

share|improve this answer
    
Completely agree. But just a small addition: if instead of V_{\mathrm{max}} one wants to write V_{\mathrm{máx}} one might need to use as an exception in that particular case V_{\textnormal{máx}} (I used \textnormal but the same applies to others). – Manuel Feb 18 at 18:38

To extend Herberts answer, the \textbf furthermore keeps the “surrounding” font style, for example when using a theorem, which typesets its content in italics, so will the \textbf will set the text bold and italic, while \mathbf will not only use the math font but furthermore only the bold font and not an italic one.

For example with

\documentclass{scrartcl}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}
\begin{document}
    In normal text
    \[
        \mathbf{A}\textbf{B}
    \]
    \begin{thm}
    In theorems, or other italic texts
    \[
        \mathbf{A}\textbf{B}
    \]
    \end{thm}
\end{document}

The result is enter image description herewhich might or might not be what you want (for example when defining own commands).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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