# new command and L with stroke

I need a boldface L often, so I'd like to use \newcommand\L\{\mathbf{L}}. This gives me a problem however, because I need a L with a stroke to write "Łoś's Theorem", for which the command is \L.

Is it possible to define \L in such a way that it gives an L with a stroke outside math mode and a boldface L inside math mode?

If not, how can I get an L with a stroke in a different way, so I can still use \L for my boldface L in math mode?

• Why not use \bL for bold L? – Sigur Jan 14 '14 at 16:52
• Welcome to TeX.SX! While \L may seem a good shortcut, it's better avoiding different meanings of the same macro depending on the context. – egreg Jan 14 '14 at 16:57
• Also, \L is too short a macro; use, say, \LosThm. – Svend Tveskæg Jan 14 '14 at 17:01
• @SvendTveskæg, I agree. But my feeling says that OP does not know how to use auto completion tools. lol – Sigur Jan 14 '14 at 17:03
• @SvendTveskæg, OK. Long life TeXstudio (and Linux, of course). – Sigur Jan 14 '14 at 17:06

Focusing on your point that "how can I get an L with a stroke in a different way, so I can still use \L for my boldface L in math mode?", others (notably egreg) have pointed out that it is definitely not a good idea to redefine \L.

But since that was the essence of your question, and if you prefer to throw caution to the wind, you can obtain it thus:

\documentclass[english]{article}
\let\strokeL\L
\renewcommand\L{\mathbf{L}}
\begin{document}
In \strokeL o\'s's Theorem, we need stroke L, but inline, $\L$ gives bold L.
\end{document}


For more ease of use, you could check for the presence of math mode and decide on the fly the definition of \L. That way you could use \L in text and math mode and get your hoped-for result.

\documentclass[english]{article}
\let\strokeL\L
\DeclareRobustCommand{\L}{\ifmmode\mathbf{L}\else\strokeL\fi}
\begin{document}
In \L o\'s's Theorem, we need stroke L, but inline, $\L$ gives bold L.
\end{document}


Thanks to egreg for showing the need for \DeclareRobustCommand in preference to \newcommand, as originally pointed out by David Carlisle. To reiterate, however, experts like egreg caution against the approach of redefining \L.

• $\begin{array}{c} \L=\L\end{array}$ hmmmm:-) – David Carlisle Jan 14 '14 at 17:21
• @DavidCarlisle $\begin{array}{c} {\L}=\L\end{array}$ Touche! – Steven B. Segletes Jan 14 '14 at 17:28
• @StevenB.Segletes You need \relax before \ifmmode, not an additional pair of braces. Better yet, \DeclareRobustCommand should be used (which would make \relax redundant). – egreg Jan 14 '14 at 18:29
• @StevenB.Segletes the extra braces would break the text use as it prevents any font-specified kerns between the slashed L and any other letter. – David Carlisle Jan 14 '14 at 18:37
• @tohecz I advocate more “semantic” names for personal macros; maybe less easy to type, but surely more readable. – egreg Jan 14 '14 at 18:59

It's possible, although dubious, to define a macro that behaves differently in text or in math mode. There are LaTeX macros that do:

\strut \verb \phantom \smash \ensuremath \underline
\, \\$ \{ \} \P \S \dag \ddag \_ \copyright \pounds \dots
\@inmatherror \@inmathwarn <...other internal macros...>


The first group consists of macros that must do different calls in one mode or the other, for technical reasons; for instance, \strut calls \unhcopy\strutbox in text mode, while it calls \uncopy\strutbox in horizontal mode. Of course \ensuremath has to do different things in the two modes.

The second group consists of commands that print the same symbol in both modes, but need different technical realizations. The third group is formed by internal macros that can signal some command can't or shouldn't be used in math mode, or do important bookkeeping jobs.

It's important to notice that the semantics of the commands in the first two groups doesn't change: for the final user they do “the same thing”. It's similar to \\ that has several different meanings depending on the context, but for the final user it always means “terminate a line”.

Defining a macro that has different semantics in text and math mode is not good practice, because it hinders clarity in the input and makes it difficult to remember what it means.

As a general rule, commands belonging to the LaTeX Internal Character Representation (LICR) shouldn't be redefined, as they can pop out in unexpected places. Once I received a frantic message by a user who couldn't print his coauthor's name, who happened to be Turkish and his name started with “Ş”; my colleague had, in his preamble,

\def\c{\gamma}


and of course “Ş” must be typed \c{S} or Ş (which inputenc translates into \c{S} anyway).

After this long premise, aimed at discouraging you to redefine \L, here's how you can do

\let\polishL\L % save the old meaning
\DeclareRobustCommand{\L}{\ifmmode\mathbf{L}\else\polishL\fi}


We don't want that \L is untimely expanded when in moving arguments, say

\section{\L o\'s theorem}


so we need to declare it as a robust command. However, this is not really a good definition, because commands such as \L are defined in an “encoding dependent” way. So saving the meaning of \L in a place can give it a meaning that could be different from the meaning it would have had in the document. Say that a package loads, at begin document, the T1 output encoding (some font packages may do it). If you don't load the T1 encoding beforehand, your \polishL would mean

\OT1-cmd \L \OT1\L


\T1-cmd \L \T1\L


and this can cause obscure font related error messages or wrong output.

## Final words

Don't. Use a meaningful macro based on the meaning of your boldface mathematical L, not \L.