[Tex/LaTex] Command to italicize text with slanted numbers

fontsitalic

I often find myself adding a lot of \textsl{} around inside \emph{} or \textit{} blocks because I find italicized digits to look too "showoffy" and "baroque" and to hinder legibility (I'm using $$ when the number has a mathematical sense, but this situation occurs in less technical texts like CVs, and such.).

Could someone help me write a renewcommand to automate this, or better, a single low level command that makes \emph, \itshape, \textit and friends choose slanted over italic for numbers? I'm not too familiar with the low level latex font selection system nor with a way to detect digits from regular letters.

Edit: MWE of what I need and what I want to avoid

\documentclass{article}
\begin{document}
He thought: '\emph{Why 1234567890 apples?}'
then he realized '\emph{ah yes, he has \textsl{1234567890} childs}'
\end{document}

gives:

I find the italicized version (first one) of 2,3,4 and 7 to look especially bad.

Best Answer

As I understand, there's no maths involved since you are writing just text. This solution is not perfect but may give you a start.

This solution replaces all the numbers with the \textsl{…} version. If you want any number not to be replaced, you must enclose it in {…}.

\documentclass{scrartcl}

\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand \italicize { m }
  { \nathdwek_italicize:n { #1 } }
\cs_new_protected:Npn \nathdwek_italicize:n #1
 {
  \tl_set:Nn \l_tmpa_tl { #1 }
  \tl_map_inline:nn { 0123456789 }
   { \tl_replace_all:Nnn \l_tmpa_tl { ##1 } { \textsl { ##1 } } }
  \textit { \tl_use:N \l_tmpa_tl }
 }
\ExplSyntaxOff

\begin{document}
I want this with upright numbers. Like 1, or 2 or 123.\par
\emph{I want this with italics numbers. Like 1, or 2 or 123.}\par
\italicize{I want this with slanted numbers. Like 1, or 2 or 123.}
\end{document}

enter image description here