Take the 2-minute tour ×
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.

I’m using pdfLaTeX, and I want all vectors I typeset to be in bold, upright font. Unfortunately, based on whether the symbol is latin, lowercase greek, or uppercase greek, there are different commands necessary to make it bold and upright. I’d like to be able to define a single macro — say, \vector — such that it does what I want no matter the argument and I don’t have to think about it:

\vector{a}       =>  \mathbf{a}
\vector{\alpha}  =>  \boldsymbol{\upalpha}
\vector{\Omega}  =>  \boldsymbol{\Omega}

This popular question deals with some of this issue, but the solutions there still have the lowercase greek vectors in bold italic, not bold upright. Plenty of other questions touch on this issue in various ways, but I haven't been able to find a definitive answer to this exact variant. Perhaps the answer is “you can’t” — but I haven't seen that definitively either.


Edited \Alpha, which doesn't exist, to \Omega.

share|improve this question
    
Perhaps this might be a starting point: tex.stackexchange.com/questions/109375/… –  Christian Hupfer Mar 23 at 9:33

2 Answers 2

A modification of my answer to Automatically check if a math character is greek or latin should do:

\documentclass{article}
\usepackage{xparse}
\usepackage{bm,upgreek}

\ExplSyntaxOn
\NewDocumentCommand\Vector{m}
 {
  \commexo_vector:n { #1 }
 }

\cs_new_protected:Npn \commexo_vector:n #1
 {
  \tl_map_inline:nn { #1 }
   {
    \commexo_vector_inner:n { ##1 }
   }
 }

\cs_new_protected:Npn \commexo_vector_inner:n #1
 {
  \tl_if_in:VnTF \g_commexo_latin_tl { #1 }
   {% we check whether the argument is a Latin letter
    \mathbf { #1 } % a Latin letter
   }
   {% if not a Latin letter, we check if it's an uppercase Greek letter
    \tl_if_in:VnTF \g_commexo_ucgreek_tl { #1 }
     {
      \bm { #1 } % a Greek uppercase letter
     }
     {% if not, we check if it's a lowercase Greek letter
      \tl_if_in:VnTF \g_commexo_lcgreek_tl { #1 }
       {
        \commexo_makeboldupright:n { #1 }
       }
       {% none of the above, just issue #1
        #1 % fall back
       }
     }
   }
 }

\cs_new_protected:Npn \commexo_makeboldupright:n #1
 {
  \bm { \use:c { up \cs_to_str:N #1 } }
 }

\tl_new:N \g_commexo_latin_tl
\tl_new:N \g_commexo_ucgreek_tl
\tl_new:N \g_commexo_lcgreek_tl
\tl_gset:Nn \g_commexo_latin_tl
 {
  ABCDEFGHIJKLMNOPQRSTUVWXYZ
  abcdefghijklmnopqrstuvwxyz
 }
\tl_gset:Nn \g_commexo_ucgreek_tl
 {
  \Gamma\Delta\Theta\Lambda\Pi\Sigma\Upsilon\Phi\Chi\Psi\Omega
 }
\tl_gset:Nn \g_commexo_lcgreek_tl
 {
  \alpha\beta\gamma\delta\epsilon\zeta\eta\theta\iota\kappa
  \lambda\mu\nu\xi\pi\rho\sigma\tau\upsilon\phi\chi\psi\omega
  \varepsilon\vartheta\varpi\varphi\varsigma\varrho
 }

\ExplSyntaxOff
\begin{document}
$\Vector{X}\Vector{\Lambda}\Vector{\alpha}\Vector{\beta}$

$\Vector{X\Lambda}$
\end{document}

enter image description here

What does \commexo_makeboldupright:n do? It takes its input, say \alpha, strips away the backslash from the name with \cs_to_str:N and builds the control sequence \upalpha via \use:c: saying \use:c{upalpha} is equivalent to typing \upalpha.

share|improve this answer
    
Yes, this certainly does the job. And you even named some of the pieces after me! But my god what a mess. Couple of questions: Is there a reason you opted for bm over boldsymbol? Also, I'm not going to ask you to explain the inner mechanics of the whole thing, but can you maybe explain what \commexo_makeboldupright is doing? –  thecommexokid Mar 24 at 19:45
    
Also, btw, you left out \varrho, \varsigma, and \varphi from the lowercase greek alphabet list. –  thecommexokid Mar 24 at 19:46

As it may be of benefit to others, I will mention the solution I currently use: In a document with a lot of greek vectors, I switch the document font from Computer Modern to Charter and use the isomath package, such that \mathbf works as expected on greek characters:

\documentclass{article}

\usepackage[charter,cal=cmcal]{mathdesign}
\usepackage[OMLmathrm,OMLmathbf]{isomath}
\newcommand{\vect}[1]{\mathbf{#1}}    

\begin{document}
    $\a$, $\omega$, $\Omega$

    $\vect a$, $\vect\omega$, $\vect\Omega$
\end{document}

bold upright a, omega, Omega

I posted the question because I prefer Computer Modern to Charter, but since apparently the solution in Computer Modern is at the very least quite complicated, perhaps someone else may find this comparatively simpler solution useful.

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.