# Substituting character $l$ with $\ell$ throughout math mode

How do I overwrite the default $l$ character so that it is substituted by $\ell$ throughout math mode? (More generally, is there an easy way to make such symbol substitutions?)

-
I think this is generally a bad idea. The reason that people write cursive ls is to differentiate them from 1s when writing on a black board. In typeset material, there is no need for the \ell as l and 1 are already visually distinct. I realize some book authors use it, but I believe the majority do not. I see the \ell mostly in conference proceedings where the authors do not know better. – TH. Aug 18 '10 at 20:57
@TH: I disagree with the implication that there is no need to use \ell. Particularly as a subscript (a common use especially for letters near the middle of the alphabet) l can be an indistinct squiggle. And there are some specific uses (the sequence space \ell^p, for example) for which \ell really is a now-standard notation and using l instead comes across as lazy typesetting. Nevertheless, I agree that making this substitution everywhere isn't a great idea. – Mark Meckes Aug 19 '10 at 14:13
@Mark Meckes: I guess it makes sense that it would start to be used. \mathbb R came about as a way to bold on the blackboard and is now standard. I actually think that just normal bold is more elegant, somehow. (I still use \mathbb since that's what's expected.) – TH. Aug 19 '10 at 22:21
@TH: I'm not fond of normal bold in math myself. It may not be difficult in practice, but I just don't like the idea of distinguishing between characters based on the thickness of strokes, as opposed to their number, location, intersections, etc. For similar reasons I prefer \ell to l. But I'm also usually guided more by prevailing practices than my own aesthetics. – Mark Meckes Aug 20 '10 at 15:30

This is similar to how MinionPro deals with open vs closed mathematical g's.

\documentclass{article}
\mathcodel="8000
\begingroup
\makeatletter
\lccode\~=\l
\DeclareMathSymbol{\lsb@l}{\mathalpha}{letters}{l}
\lowercase{\gdef~{\ifnum\the\mathgroup=\m@ne \ell \else \lsb@l \fi}}%
\endgroup
\begin{document}
$$l = 2$$ $$\lim = 2$$
\end{document}

-
Nice approach: probably better than mine (still risky, though). – Joseph Wright Aug 18 '10 at 19:33
I've used this approach for a while and I haven't noticed any problems. Maybe I was just lucky... – Lev Bishop Aug 18 '10 at 19:39
I'm thinking of packages such as breqn that rely on all sorts of things being active. You might get something nasty happening: I've not tested this :-) – Joseph Wright Aug 18 '10 at 19:52

To do it via an external search-and-replace, you could use a script that I wrote called mathgrep. It's a perl script designed to do search and search-and-replace within maths sections of a LaTeX document.

The main limitation of this script is that it doesn't regard dollars as valid maths delimiters - but then, no-one uses them, right? Actually, I wrote a script to deal with that as well, which I called debuck for some reason that escapes me now.

(Oh yeah, I remember: dollar = buck.)

-
@Caramdir: well spotted! Thanks. – Loop Space Aug 18 '10 at 20:38

There is if you are using Lyx or SWP. E.g., you can have SWP search for l in math (SWP is wysiwym) and replace it with \ell. It will do this and ignore l in text.

-
Please give more details! – Joseph Wright Aug 18 '10 at 18:34
Thanks for that. – Joseph Wright Aug 18 '10 at 19:18

I think your best plan is to do a search and replace. You'll need to use some kind of regular expression (or, as user714 notes, so set up that can search selectively within math). The advantage of altering the source is you avoid any nasty side issues.

-
Why did you have do delete your other answer? Now I have to share the disciplined badge ;-) – Caramdir Aug 21 '10 at 13:09
I was thinking about the 'let people get answers in' point, and decided that I should lead by example :-) – Joseph Wright Aug 21 '10 at 13:27