In latex.ltx you can find


What was this needed for?


2 Answers 2


It was added due to this bug reported:


  • 3
    In that bug, it seems to reference an earlier one where it was first detected.
    – Werner
    Nov 17, 2013 at 17:45

Some packages (particularly the AMS packages) redefine \@ifnextchar. Usually the redefined version has all of the properties of the original, but there are some places where the original is needed, which is what \kernel@ifnextchar is for.

If you look at the places where it is used, you'll find that it is mainly used in the definitions associated to \newcommand and \newenvironment so that they always behave as intended.

The entire source of the latex.ltx is documented in source2e.pdf (available through texdoc).

  • 3
    The documentation considers this a bug in the amsmath package: "It should really be fixed in the amsmath package one day, but..." (p.32) but since the amsmath packages are so widely used it makes sense to have the workaround, so that there exists an \ifnextchar macro that is guaranteed to work as originally intended. I don't know if that's democratic. It's certainly pragmatic.
    – Alan Munn
    Nov 17, 2013 at 15:37
  • 3
    @Ruben it is a late version of "this is a kernel command do not mess with it ..." of which there are only a few in LaTeX2e (unfortunately). It was an interface overwrite that should not have happened at least not everywhere. Nov 17, 2013 at 22:45
  • 1
    @FrankMittelbach so the ams writers should have done someting like \AMS@ifnextchar instead of redefining the kernel command? (just to understand the direction of your comment)
    – Ruben
    Nov 18, 2013 at 0:06
  • 1
    @Ruben it is not that simple: the intention of the AMS was to make \\ not to skip spaces in their environments because that is often a source of error in math (if \\ picks up a * on the next line, say), In reality that is sensible for most environments (that's where the original spect of LaTeX have been sub-optimal). On the other hand there are cases where ifnextchar should skip spaces. So it is sensible to have both versions which we evenually did. However it would have been better if the AMS had kept the change confined to their environments. Nov 18, 2013 at 13:27
  • 1
    @Ruben so we provided a "kernel" command and used it in the places where the space skipping is essential but kept \@ifnextchar in others so that the AMS package could overwrite those. We could not change those places ourselves as the officially documented behavior in the LaTeX manual is that spaces are skipped and modifying this for documents not using amsmath could have broken those. That's why the two are initially identical, but the intention here is to use \@ifnextchar in places where space skipping is potentially unwanted. Nov 18, 2013 at 13:31

You must log in to answer this question.

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