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

This is a follow-up to this question.

Suppose you want to denote vectors by upright bold letters; then \mathbf{u} works fine, except that if it's a Greek letter you have to use \boldsymbol{\omega} instead.

Question: Is it possible to define a generic vector command in LaTeX which automatically chooses between \mathbf and \boldsymbol, so that one can write just \vect{u} and \vect{\omega} without having to treat the Greek symbols specially by hand?

(Just to be clear: \newcommand{\vect}[1]{\boldsymbol{#1}} is no good in this situation, since \boldsymbol{u} gives bold italic instead of roman.)

share|improve this question
    
\boldsymbol(\omega) -> \boldsymbol{\omega}; I couldn't edit because of some "minimum 6 character" rule... – equaeghe Feb 22 '13 at 15:35
    
@equaeghe: Fixed. – Hans Lundmark Feb 23 '13 at 8:30
up vote 20 down vote accepted

You can use both commands together and define something like

\usepackage{bm}
\newcommand{\vect}[1]{\boldsymbol{\mathbf{#1}}}

which should work for most cases.

share|improve this answer
\usepackage{bm,xstring}

$\vect{{\cal M}}$
share|improve this answer
2  
Welcome to TeX.SX! I'm not entirely sure how this answers the question. xstring in particular looks extraneous and you don't seem to be using bm. Moreover, if I turn your code into a minimal working example (MWE), it does not compile. – Sean Allred Jan 21 at 10:33

The macro

\newcommand{\vect}[1]{\boldsymbol{\mathbf{#1}}}

does not work with mathtime pro lite fonts (and from the comments it appears that it does not work with mathpazo either). Another approach is to simply check if the argument is A-Za-z.

\usepackage{bm,xstring}

\def\VEC#1%
    {\IfSubStr{ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz}{#1}
        {\mathbf{#1}}
        {\bm{#1}}}

This is inefficient since it performs the substring check for each execution. One could define macros \VEC@A, \VEC@B etc (using a simple loop), and then check do

\def\VEC#1%
    {\ifcsname VEC@#1\endcsname
        \mathbf{#1}%
     \else
         \bm{#1}%
     \fi}
share|improve this answer

Although this doesn't answer your question, have you tried using the bm package? Then $\bm{\omega}$ gives a bold omega, $\bm{u}$ gives a bold (math italic) u, and $\bm{\mathrm{u}}$ a bold roman u.

share|improve this answer
2  
Indeed, defining something like \newcommand{\vect}[1]{\boldsymbol{\mathbf{#1}}} would do the trick. – Juan A. Navarro Sep 27 '10 at 18:55
    
@Juan: why not make an answer out of your comment? – Konrad Swanepoel Sep 27 '10 at 19:02
    
Hmm.. because I thought it was pretty much the same (i.e. use both commands together), but maybe not? – Juan A. Navarro Sep 27 '10 at 19:07
    
@Juan: Thanks, that works! Except that I'm getting weird errors from an \underbrace in a file where I tried it: "Use of \reserved@a doesn't match its definition." and " LaTeX Error: Too many math alphabets used in version bold." Unfortunately that particular formula works fine in a file on its own, so I'm having trouble producing a minimal example where it fails... – Hans Lundmark Sep 27 '10 at 19:41
    
@Juan: Anyway, if you put your comment in an answer instead I can accept it. – Hans Lundmark Sep 27 '10 at 19:42

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.