7

I really like how Steven is generating upright greek letters in his answer:

\documentclass[a4paper]{article}
\newsavebox{\foobox}
\newcommand{\slantbox}[2][0]{\mbox{%
        \sbox{\foobox}{#2}%
        \hskip\wd\foobox
        \pdfsave
        \pdfsetmatrix{1 0 #1 1}%
        \llap{\usebox{\foobox}}%
        \pdfrestore
}}
\newcommand\unslant[2][-.25]{\slantbox[#1]{$#2$}}

\newcommand\ualpha{\unslant\alpha}
\newcommand\ubeta{\unslant\beta}
\newcommand\ugamma{\unslant\gamma}

\begin{document}
$\alpha\beta\gamma$ \par
$\ualpha\ubeta\ugamma$ \par

$X_{\alpha\beta 123}$ \par
$X_{\ualpha\ubeta 123}$ \par
\end{document}

However, when it comes to subscripts, it just does not look right:

enter image description here

Especially the gap between the letters and the numbers looks bad and the come out way too big.

I experimented with

\newcommand\unslant[2][-.25]{\slantbox[#1]{$#2\!$}}

but now it comes out badly in normal text:

enter image description here

Is there any solution to get it work? Or do I need to define separate commands, for both cases subscripts and normal?

I'd like to avoid to return to packages like upgreek, which just doesn't fit a lot of fonts. But I didn't had these problems though.


Splitting up the definitions would work, not perfect but on could live with it:

\newcommand\ualpha{\unslant\alpha}
\newcommand\ubeta{\unslant\beta}
\newcommand\ugamma{\unslant\gamma}
\newcommand\sualpha{\scriptsize\unslant\alpha\kern-0.075em}
\newcommand\subeta{\scriptsize\unslant\beta\kern-0.07em}
\newcommand\sugamma{\scriptsize\unslant\gamma\kern-0.07em}

\begin{document}
$\alpha\beta\gamma$ \par
$\ualpha\ubeta\ugamma$ \par

$X_{\alpha\beta 123}$ \par
$X_{\sualpha\subeta 123}$ \par
\end{document}

enter image description here

But is that really necessary?

2 Answers2

8

I made two adjustments to your MWE

  1. I did a small \mkern and minus \mkern around each character to better align them with the slanted counterparts; and

  2. More importantly, I used the \ThisStyle{...\SavedStyle...} syntax of the scalerel package to preserve the math style of the argument.

Here is the MWE.

\documentclass[a4paper]{article}
\usepackage{scalerel}
\newsavebox{\foobox}
\newcommand{\slantbox}[2][0]{\mbox{%
        \sbox{\foobox}{#2}%
        \hskip\wd\foobox
        \pdfsave
        \pdfsetmatrix{1 0 #1 1}%
        \llap{\usebox{\foobox}}%
        \pdfrestore
}}
\newcommand\unslant[2][-.25]{%
  \mkern1mu%
  \ThisStyle{\slantbox[#1]{$\SavedStyle#2$}}%
  \mkern-1mu%
}

\newcommand\ualpha{\unslant\alpha}
\newcommand\ubeta{\unslant\beta}
\newcommand\ugamma{\unslant\gamma}

\begin{document}
$\alpha\beta\gamma$ \par
$\ualpha\ubeta\ugamma$ \par

$X_{\alpha\beta 123}$ \par
$X_{\ualpha\ubeta 123}$ \par
\end{document}

enter image description here

2

The problem is that \unslant put the unslanted character on the right edge of the space originally needed for the slanted version. The following variation centers the unspanted character in the same space.

\documentclass{article}
\usepackage{mathtools}

\newsavebox{\foobox}
\newlength{\foodim}
\newcommand{\slantbox}[2][0]{\mbox{%
        \sbox{\foobox}{#2}%
        \foodim=#1\wd\foobox
        \hskip \wd\foobox
        \hskip -0.5\foodim
        \pdfsave
        \pdfsetmatrix{1 0 #1 1}%
        \llap{\usebox{\foobox}}%
        \pdfrestore
        \hskip 0.5\foodim
}}
\newcommand\unslant[2][-.25]{\slantbox[#1]{$#2$}}

\let\oldalpha=\alpha
\def\alpha{\unslant{\oldalpha}}
\let\oldbeta=\beta
\def\beta{\unslant{\oldbeta}}
\let\oldgamma=\gamma
\def\gamma{\unslant{\oldgamma}}

\begin{document}
$\alpha\beta\gamma$ \par

$X_{\alpha\beta 123}$ \par
\end{document}

unslandted greek

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • In this answer the subscripts have the same size as the normal letters. Thats not the idea. Apart from that, the answer is practically identical to the accepted one? – Robert Seifert Apr 21 '15 at 16:26
  • I just used and referenced your answer at http://tex.stackexchange.com/questions/239791/is-this-laplace-transform-symbol-available-in-latex/239796#239796 – Steven B. Segletes Apr 21 '15 at 16:35
  • @thewaywewalk John's answer adds value to my own answer in that he achieves the horizontal spacing correction directly inside the \slantbox, rather than relying on an externally applied \mkern as I do. I take his answer as a suggested improvement to my own, though you are correct in pointing out he does not preserve the math style. – Steven B. Segletes Apr 21 '15 at 16:37
  • @StevenB.Segletes I see! But I could just combine both answer, right? – Robert Seifert Apr 21 '15 at 16:40
  • It was originally posted April 5 to the wrong question. I was just moving it to the right question. – John Kormylo Apr 21 '15 at 16:41
  • @thewaywewalk Yes, you can combine the best of both. – Steven B. Segletes Apr 21 '15 at 16:56