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.

If you have:

\documentclass{article}
\DeclareMathAlphabet      {\mathbf}{T1}{futs}{bx}{n}
\begin{document}
\[
\mathbf{123}\quad\mathbf{xyz}
\]
\end{document}

Then numbers 0-9 and letters a-z and A-Z will be typeset using futs (considering they are the argument of my \mathbf command). However this is not what I want. I only want the digits 0-9 to be typeset in futs and the rest (letters a-z and A-Z) to be typeset in a previous font used by \mathbf (say LaTeX's default cmr family). This is what I did:

\documentclass{article}
\usepackage{expl3,xparse}
\makeatletter
\ExplSyntaxOn
\cs_new_eq:NN \orig_mathbf:n \mathbf
\NewDocumentCommand \new@mathbf { m } {
 \orig_mathbf:n {
   \prg_stepwise_inline:nnnn { `0 } { \c_one } { `9 } {
     \mathcode ##1 = \numexpr "100 * \symnew@mathbf@font@digits + ##1 \relax
   }
   #1
 }
}
 \DeclareSymbolFont{new@mathbf@font@digits}{T1}{futs}{bx}{n}%
\cs_set_eq:NN \mathbf \new@mathbf
\ExplSyntaxOff
\makeatother
\begin{document}
\[
\mathbf{123}\quad\mathbf{xyz}
\]


\end{document}

So far with my testing, this works well but it has one important side effect: it uses one more math alphabet. So my question is, is there any better approach to do what I want without using a new math alphabet?

share|improve this question
2  
I think the underlying concept, the way you are using \mathbf is wrong. In text mode it makes sense to put such commands around larger text portions like words or sentences. But math is about single entities. A command like \mathbf should be used to give one entity a definite look which shows its meaning. So a command \mynum{123}` which leads internally to \mathbf{123} is okay (entity is a number), \unit{cm}/\mathbf{cm} also (a unit), but \mathbf{arbitrary mix 123} not. –  Ulrike Fischer Jun 26 '12 at 9:41
    
I edited my question. –  Vafa Khalighi Jun 26 '12 at 10:01
1  
Well if I would want a second \mathbf for numbers I would simply define a new math alphabet: \DeclareMathAlphabet {\nummathbf}{T1}{futs}{bx}{n} and then use internally \nummathbf{123}. I would normally not use \mathbf in a document as it is not semantical markup. –  Ulrike Fischer Jun 26 '12 at 10:29
    
I already know that but that is not what I am asking. –  Vafa Khalighi Jun 26 '12 at 11:05
    
Yes I know that I didn't answer your question. I don't know what you want to achieve in the end, but imho you are trying to manipulate the wrong level. Either go one up and write a semantical command which chooses either \mathbf or \nummathbf depending on the argument, or one down and write a virtual font. Your idea to split \mathbf sounds wrong for me. –  Ulrike Fischer Jun 26 '12 at 11:20

1 Answer 1

up vote 4 down vote accepted

The idea of a math alphabet is to provide digits and basic alphabetic characters of a specific design in a formula. While most characters in a formula have a fixed representation (i.e., are taken from a fixed symbol font) the digits and the alphabetic characters can vary their appearance by selecting a different math alphabet.

Technically speaking each symbol in a formula comes from one math family (of fonts) and there are a maximum of 16 such families. The speciality is that some symbols can be marked as "variable symbols" so that they are taken from the math family associated with a math alphabet when they appear within the scope of a math alphabet command.

What math font families are associated with what fonts can be changed on a per formula basis (this is what \boldmath does it changes the mappings to bold fonts) but within a formula the association between math font family and real fonts is fixed.

For symbols that are taken from "symbol fonts" out of fixed positions one has to define the math font family up front because these commands like \timesare just defined as "pick up the glyph of math font family X in slot position Y". The situation with math alphabets is different, when they are used for the first time they can make the association between a math font family and some external font and then select that math family and use it.

That doesn't get us around the maximum limit of 16 math families but it allows us to offer more alternatives and choose among them only when actually used.

So much for the general background.

Now, if for some reason a math alphabet should actually be constructed from more than one font (e.g., the digits from one font and the letters from another) then there aren't many options available to implement this:

  • the probably most efficient way to do this would be to construct a virtual font that combines the glyphs from the two fonts in the way wanted. As a result to TeX we end up with a single font which needs a single math alphabet.

  • If a technical solution within TeX/LaTeX is intended then the only way to achieve this is along the lines suggested in the question, i.e.,

    • locally turning one group of "variable symbols" into fixed symbols pointing to a symbol font.
    • that symbol font however has to be available as a separate math font family so unless it is already loaded for some reason one has to declare it (upfront) and this way blow another math family
    • another downside of the approach is of course that all those redefinitiions have to happen each time \mathbf is used ... fortunately computers are faster these days.

So bottom line the approach in the question is by an large the only one within TeX (of course the implementation could be done differently). A much faster solution would be to define two math alphabets one for bold letters and one for bold digits (avoiding the internal remappings) but if the idea is to pretend that there is only \mathbf and the change of fonts is only there for some aesthetic reason (which could be a valid reason enough) then the above solution or the something similar or the use of virtual fonts is the way to go.

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.