Trouble using \oldstylenums with decimal points and hyphens

I am using Computer Modern font (default) with \oldstylenums command to typeset numbers in oldstyle format. However I am having trouble using it with non-numeric characters such as decimal points and hyphens.

For e.g. decimal points appear as triangles:

Master of Science, Computer Science, \oldstylenums{3.76/4.0}


appears as:

Also, I have trouble with hyphens, etc.

-
I have to point out that it's really easy to get oldstyle numbers with fontspec, meaning with XeTeX and LuaTeX and OpenType fonts (like lmodern). –  Martin Schröder Oct 8 '12 at 12:45

\usepackage{textcomp}


redefines \oldstylenumsto use the 8-bit encoding TS1 instead of the 7-bit math encoding OML.

Extended support

The following example parses the string to replace the digits by the old style variants.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{lmodern}

\usepackage{textcomp}
\usepackage{ltxcmds}

\makeatletter
\newcommand*{\oldstyle}[1]{%
\begingroup
\toks@={}%
\@oldstyle#1\scrollmode
}
\newcommand*{\@oldstyle}{%
\ltx@ifnextchar@nospace\scrollmode{%
\expandafter\endgroup\the\expandafter\toks@\@gobble
}{%
\ltx@ifnextchar@nospace\@sptoken{%
\expandafter
\romannumeral-\x
}{%
\@@oldstyle
}}}}}}}}}}}}%
}
\toks@\expandafter{\the\toks@#1}%
\@oldstyle
}
\newcommand*{\@@oldstyle}[1]{%
}
\makeatother

\begin{document}
Master of Science, Computer Science, \oldstyle{0-1--2---3; 7, 3.76/4.0}
\end{document}


-
Good things, when short, are twice as good :) –  Fran Oct 7 '12 at 2:29
@HeikoOberdiek: Thanks for the suggestion, it solves the decimal point problem, but hyphen is now converted to = symbol. –  abhinavkulkarni Oct 7 '12 at 2:30
@abhinavkulkarni, but on the contrary, = is converted to a long hyphen in this way. –  Fran Oct 7 '12 at 2:36
@Fran: Thanks. How can I get the short hyphen? –  abhinavkulkarni Oct 7 '12 at 2:37
@abhinavkulkarni, I do not know with a single key, but please see the trick of \sout in my answer. It works also with textcomp. –  Fran Oct 7 '12 at 2:57

If you want old style figures throughout your document, you have a couple of choices assuming you still want to use the Computer Modern fonts or variations thereof.

Package eco

\usepackage[T1]{fontenc}
\usepackage{eco}


Package cfr-lm

\usepackage[T1]{fontenc}
\usepackage[oldstyle=true]{cfr-lm}


The second package uses the Latin Modern fonts, which are very similar to Computer Modern; the first one uses a set of virtual fonts based on European Modern, again a variation of Computer Modern. I'd favor the latter.

-

I suppose that the best practice would be to leave out characters other than digits.

However, I could be a little messy, but you can obtain decimal points (mid point or down point), hyphens and fractions inside \oldstylenums in this way:

\usepackage{ulem} % needed for \sout{}
...
\oldstylenums{3·76=4·0 \sout{~} 3:76=4:0}


Another less tangled solution could be to define a newcommand for use \oldstylenums of another font that allow the use of normal characters inside the command:

\newcommand{\oldnum}[1]{{\fontfamily{artemisia}\scshape #1}}

\oldnum{3·76/4·0 - 3.76/4.0}
`

Note that in this case in there are text inside \oldnum, it appear as small caps instead of italics.

-