In my paper, I use a lot of commands instead of symbols. E.g. for a Lipschitz constant, instead of L I would define a command \lip which expands into L. But, occasionally, I or someone else may type L instead of \lip, and, of course, it'll compile just fine. Then we can change the notation (e.g. \lip will become \ell), but manually typed L won't change, which is a problem.

Question: is there a way to fail the compilation when we see a "free" L in math mode? In particular, it should also fail when L is an argument, e.g. when I type \frac L2. A more advanced version is the case when instead of \lip -> L it could be something more complicated (e.g. \lip -> \mathcal L), but I'll be satisfied if I'll be able to at least handle single letters (since it's harder to type \mathcal L accidently).

Or maybe there are other ways to solve this issue?

  • 1
    A regex search in your editor for an upper case L followed by a non-alphabetic character will probably catch most of the described cases. Also careful proofreading of the resulting pdf (which you have to do anyway) should catch such issues. It's nice to automate things with LaTeX (and the solution below is quite clever) but often a simpler solution is equally effective and, well, simpler :)
    – Marijn
    Apr 6, 2021 at 8:55

1 Answer 1


Caveat: wildly untested. This should be used only as a quick check when you get a file from your collaborators.

\documentclass[twocolumn]{article}% twocolumn for smaller snapshot

\lowercase{\endgroup\def~}{\uppercasel\typeout{There is an explicit `L' on line \the\inputlineno}}



See an L here in text mode, $L$, or
\frac L2 % bad style anyway
but no problem with $\Leftarrow$ or $\lip$.


enter image description here

On screen you'll see

There is an explicit `L' on line 14
There is an explicit `L' on line 16

If you really want an error you can replace the \typeout by something else. You could also simply write


and you'll get just an error Undefined control sequence \ERROR, which should be enough to identify the culprit.

  • Thanks! I've found a few places where L was used without command. Can I ask you please to briefly explain what's going on here? Thanks!
    – Dmitry
    Apr 6, 2021 at 22:23
  • 1
    @Dmitry The first \mathchardef line makes a copy of the "normal" letter L in math mode. Then with \mathcode`\L="8000 the L is made math active, i.e. in math mode it behaves like it were a macro. The lines in between give the meaning of this macro. This could be done by using \gdef, see e.g. \lowercase trick vs. \gdef (shameless self-publicity).
    – campa
    Apr 7, 2021 at 7:45

You must log in to answer this question.

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