[Tex/LaTex] Typeset an upright ell

italicmath-modesymbols

The $\ell$ character in math-mode is clearly slanted to match the usual slant of math-mode characters. Is there a way to typeset an upright version, that won't look slanted amid other upright-math-mode characters?

Best Answer

I defined a new control sequence \uell which typesets an \ell but rotated by 10 degrees. It also adjusts the spacing around the rotated \ell to be the same as for unrotated \ell.

\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{graphicx}
\makeatletter
\DeclareRobustCommand*\uell{\mathpalette\@uell\relax}
\newcommand*\@uell[2]{
  % We need to adjust the width of \uell to be the same as \ell
  \setbox0=\hbox{$#1\ell$}
  \setbox1=\hbox{\rotatebox{10}{$#1\ell$}}
  \dimen0=\wd0 \advance\dimen0 by -\wd1 \divide\dimen0 by 2
  \mathord{\lower 0.1ex \hbox{\kern\dimen0\unhbox1\kern\dimen0}}
}
\begin{document}
\section{$\uell$}
\ttfamily
\begin{tabular}{ll}
  \string\ell  & $jk\ell mn$                  \\
  \string\uell & $jk\uell mn$                 \\
  \string\ell  & $jk\ell_{\ell_{\ell}} mn$    \\
  \string\uell & $jk\uell_{\uell_{\uell}} mn$ \\
\end{tabular}
\end{document}

enter image description here

Using expl3

The output stays the same, of course.

\documentclass{article}
\pagestyle{empty}% for cropping
%\usepackage{xparse} expl3 is now default since 2020
\ExplSyntaxOn

\box_new:N \l_uell_box
\dim_new:N \l_uell_dim

\cs_new_protected:Npn \__uell:nn #1#2
  {
    % We need to adjust the width of \uell to be the same as \ell
    \hbox_set:Nn \l_uell_box { $#1\ell$ }
    \dim_set:Nn \l_uell_dim { \box_wd:N \l_uell_box }
    \box_rotate:Nn \l_uell_box { 10 }
    \dim_set:Nn \l_uell_dim { (\box_wd:N \l_uell_box - \l_uell_dim) / (-2) }
    \tex_mathord:D {
      \box_move_down:nn { .1ex } {
        \hbox:n {
          \tex_kern:D \l_uell_dim
          \hbox_unpack_drop:N \l_uell_box
          \tex_kern:D \l_uell_dim
        }
      }
    }
  }

\NewDocumentCommand\uell{}
  {
    \mathpalette \__uell:nn \scan_stop:
  }

\ExplSyntaxOff
\begin{document}
\section{$\uell$}
\ttfamily
\begin{tabular}{ll}
  \string\ell  & $jk\ell mn$                  \\
  \string\uell & $jk\uell mn$                 \\
  \string\ell  & $jk\ell_{\ell_{\ell}} mn$    \\
  \string\uell & $jk\uell_{\uell_{\uell}} mn$ \\
\end{tabular}
\end{document}