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 am trying to convert the figures of a mixed string over which I have no control, say

+1 (234) 567 890 abcd

to old style when using the kurier font.
I know of \oldstylenums, but it switches to the OML encoding which does not support symbols such as "+", "(", etc

After trying out several things (like parsing the string with xstring and substituting the numbers for \oldstylenums{number} -- I got stuck with annoying TeX expansion issues), I finally found a way to do it by redefining the normal math font version and declaring the numbers as a special category of symbols, i.e.

\SetSymbolFont{operators}{normal}{T1}{kurier}{l}{n}
\SetSymbolFont{letters}{normal}{T1}{kurier}{l}{n}
\SetSymbolFont{symbols}{normal}{T1}{kurier}{l}{n}
\SetSymbolFont{largesymbols}{normal}{T1}{kurier}{l}{n}
\DeclareSymbolFont{numbers}{OML}{kurier}{l}{n}
\DeclareMathSymbol{0}\mathalpha{numbers}{"30}
\DeclareMathSymbol{1}\mathalpha{numbers}{"31}
\DeclareMathSymbol{2}\mathalpha{numbers}{"32}
\DeclareMathSymbol{3}\mathalpha{numbers}{"33}
\DeclareMathSymbol{4}\mathalpha{numbers}{"34}
\DeclareMathSymbol{5}\mathalpha{numbers}{"35}
\DeclareMathSymbol{6}\mathalpha{numbers}{"36}
\DeclareMathSymbol{7}\mathalpha{numbers}{"37}
\DeclareMathSymbol{8}\mathalpha{numbers}{"38}
\DeclareMathSymbol{9}\mathalpha{numbers}{"39}

I can then simply use $+1 (234) 567 890 abcde$. To solve the math spacing issue, I actually do

$\StrSubstitute{+1 (234) 567 890 abcde}{ }{$ $}$

But it's probably the ugliest hack I've writtent since a long long time...

Any idea on how to do this in an elegant way?

share|improve this question
add comment

2 Answers

Highly inefficient, but for limited use it might be good:

\documentclass[a4paper]{article}

\makeatletter
\newcommand{\pmos}{%
  \begingroup
  \pmos@assign{0}%
  \pmos@assign{1}%
  \pmos@assign{2}%
  \pmos@assign{3}%
  \pmos@assign{4}%
  \pmos@assign{5}%
  \pmos@assign{6}%
  \pmos@assign{7}%
  \pmos@assign{8}%
  \pmos@assign{9}%
  \catcode`0=\active
  \catcode`1=\active
  \catcode`2=\active
  \catcode`3=\active
  \catcode`4=\active
  \catcode`5=\active
  \catcode`6=\active
  \catcode`7=\active
  \catcode`8=\active
  \catcode`9=\active
  \@pmos}
\newcommand{\pmos@assign}[1]{%
  \begingroup\lccode`~=`#1\relax
    \lowercase{\endgroup\def~}{\oldstylenums{#1}}}
\newcommand{\@pmos}[1]{#1\endgroup}
\sbox0{\oldstylenums{0}}

\begin{document}
\pmos{+1 (234) 567 890 abcd}
\end{document}

The \sbox0{\oldstylenums{0}} is there to ensure loading of the correct font before LaTeX tries to use it for \pmos (Poor man's old style), so load your font package before this code.

share|improve this answer
    
Thanks! Not quite handsome, but definitely better than my solution. I just need to find why it is conflicting with my code (your case example works, but \pmos{} doesn't produce any oldstyle figures when used in my complex class so far :( –  Xavier Dec 17 '11 at 2:25
    
I am sorry, but I cannot understand why this solution (of which I must confess I understand almost nothing...) is "definitely better than the original" which seems to work perfectly on my file...thanks! –  Filippo Alberto Edoardo Aug 3 '13 at 6:56
    
@FilippoAlbertoEdoardo The original changes the appearance of all digits in math mode. –  egreg Aug 3 '13 at 16:45
    
@egreg: Thanks, I see. So, most probably, I misunderstood what the OP wanted. Since I do want to change all digits (meaning: in each single occurrency of math mode), I am opting for the OP's version. By the way, since I was trying the same but got stuck, can you tell me where/how can one figure out that the slots corresponding to oldstyle numbers are "31-"39? –  Filippo Alberto Edoardo Aug 4 '13 at 6:34
    
@FilippoAlbertoEdoardo Normally, oldstyle figures are meant to be used inside text, while modern figures are meant to be used in equations, tables, etc. So the ability to chose which one to use is definitely an improvement. –  Xavier Aug 4 '13 at 7:19
show 2 more comments

Are you willing and able to switch from (pdf)latex to XeLaTeX? (If you're running either TeXLive2011 or MikTeX2.9, you have XeLaTeX.) If so, there's good news: the Kurier font family is available in OpenType format, making it very straightforward to use with XeLaTeX. The following MWE shows how you might go about using XeLaTeX for your purposes:

% !TEX program = xelatex
\documentclass{article}
\usepackage[no-math]{fontspec}
\defaultfontfeatures{Ligatures=TeX,
   Numbers={OldStyle,Proportional}}
\setmainfont{Kurier} 
\begin{document}
+1 (234) 567 8900 abcd
\end{document}

enter image description here

share|improve this answer
    
Unfortunately no, the code has to be 100% compatible with LaTeX. I should have specified that. –  Xavier Dec 17 '11 at 1:50
add comment

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.