11

The following LaTeX code

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\[ \L, \operatorname{\L}, \mathrm{\L}
\]
\textit{
\[ \L, \operatorname{\L}, \mathrm{\L}
\]
\[ L, \operatorname{L}, \mathrm{L}
\]
}
\end{document}

produces

Barred L

Why does \L italicise in \operatorname and \mathrm environments and how can I prevent it?

4
  • 1
    were there any errors in your log? i don't believe \L is recognized in math, so the surrounding \textit rules. Commented Apr 6, 2017 at 0:40
  • @barbarabeeton Indeed. The error says \L is invalid in math mode. Surrounding them with \mathord{\text{...}} eliminates these errors but the outputs are identical. Commented Apr 6, 2017 at 0:43
  • try \textrm then. or \text{\upshape ...}. \text all by itself simply follows the style of the current environment, which (as already seen) is \textit. (it's set up this way so that "explanatory text" in a math display in a theorem follows the theorem text style.) Commented Apr 6, 2017 at 0:52
  • @barbarabeeton Indeed, \textrm does not work but \upshape does. Commented Apr 6, 2017 at 0:58

1 Answer 1

11

Compiling your example yields six warnings:

LaTeX Warning: Command \L invalid in math mode

What happens is that LaTeX recovers in the only way it knows, that is, switching to the text font which was current when the math formula started. If this is under the scope of \itshape (in your case via \textit), the Ł will appear in italics.

If you need the slashed L as a math operator, you have to do it more carefully:

\DeclareMathOperator{\Lslash}{\text{\normalfont\L}}

Here we're under the assumption that the font used by operator names is the same as the main text font.

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator{\Lslash}{\text{\normalfont\L}}

\begin{document}

$\Lslash$ \textit{$\Lslash$}

\end{document}

enter image description here

A more complex version respecting \boldmath and compatible with \bm (but operators must be treated specially with it).

\documentclass{article}
\usepackage{amsmath,pdftexcmds}
\usepackage{bm}

\makeatletter
\newcommand{\boldmathTF}[2]{%
  \ifnum\pdf@strcmp{\math@version}{bold}=\z@
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  {#1}{#2}%
}
\makeatother
\DeclareMathOperator{\Lslash}{%
  \text{\normalfont\boldmathTF{\bfseries}{}\L}%
}

\begin{document}

$\sin x$ $\Lslash x$

$\bm{\mathop{\sin}}x$ $\bm{\mathop{\Lslash}}x$

\boldmath
$\sin x$ $\Lslash x$

\end{document}

enter image description here

2
  • 1
    Is there any pro of using \text{\textnormal rather than \textnormal{?
    – Manuel
    Commented Apr 6, 2017 at 11:01
  • 1
    @Manuel They're essentially equivalent; I was thinking to the possibility of making this compatible with \boldmath.
    – egreg
    Commented Apr 6, 2017 at 11:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .