# Is there a command to ignore the following character?

Is there a command that ignores the following character, in the same way that \^ puts a hat over the following character?

-

I don't know if one exists already, but issuing the directive

\def\?#1{}

will do the trick: \?abc gives bc, and so on.

Edit: Here is a discussion of the question Tim N raised in the comments: getting a \caption to drop the final period in a figure number. It does not work, even in the default article class, to just let

\renewcommand*\thefigure{\arabic{figure}\?}

which gives a few errors, the first of which is actually "Argument of \? has an extra }" and not "Paragraph ended before \? was complete" (that's the second). A little \tracingmacros-trawling reveals the following phenomenon: when \caption is called, it first increments the figure counter, which calls \refstepcounter so it can be referenced, which sets up (using \edef) the current label \@currentlabel for \ref, which (finally) must contain the value of \thefigure! And guess what: the extra period does not appear after \thefigure in this context, so the \? gobbles the closing brace of the \edef command. Hence the error.

Let's see if we can get what you want. The caption line is constructed in several stages, which in article consist of the following discrete steps:

• Generate the caption "number" (the text "Figure 1.2.", for example);
• Attach it to the caption "text" (the argument of \caption) by, for example, inserting a colon and a space between them.

These correspond to the internal macros \fnum@figure and \@makecaption, which are defined by the document class, and obviously vary; it seems that Tim N's packages are putting extra periods in, but who knows whether it's in the first stage or the second? Or even in \thefigure itself? Depending on where it happens, you need a different workaround:

• If someone erroneously defined \thefigure to contain an extra period, and you know how the rest of the number ought to look, then you can just redefine it. Since there's no way to gobble the previous character, if my solution below doesn't work for you, then you should try this.

• If \fnum@figure somehow puts a period after the value of \thefigure, then under some circumstances you will be able to remove it using \?. For example, if they modified the default article definition (see below) then putting \? right after \thefigure will do the trick. However, if they produce the period by some clever device, you will have to be equally clever to unravel it.

Here is that definition:

% The default def'n doesn't have the period
\def\fnum@figure{\figurename\nobreakspace\thefigure.}
• Finally, suppose that the period is inserted in \@makecaption. Then you may be able to catch it with \?, but only if the command that produces the "number" is dropped in as-is and not fully expanded first. This is the case in the article class and, we hope, also in whatever your situation is.

So it appears the goal is to stick \? right after \thefigure as it appears in \fnum@figure only. You want to patch a command, and there are several ways to go about this, but the etoolbox package is generally useful so I'll go with it. See the following minimal document:

\documentclass{article}
% Cute but not necessary here:
% \def\?#1{}

% \renewcommand\thefigure{\arabic{figure}\?}

% GOOD:
\usepackage{etoolbox}
\makeatletter
\patchcmd\fnum@figure{\thefigure}{\thefigure\@gobble}{}{}
\makeatother

\begin{document}
\begin{figure}
\caption{A figure}
\end{figure}
\end{document}

Since we are going with \makeatletter anyway, I figure the internal \@gobble command that Yiannis pointed out is probably the wiser course, though \? is nice if you are putting it in ordinary text.

-
In the LaTeX kernel you find \@gobble. –  Yiannis Lazarides Jan 10 '12 at 0:03
@Yiannis: Oops, yes. Though it does need to be swaddled in \makeatletter...\makeatother. –  Ryan Reich Jan 10 '12 at 0:08
My goal was an ugly hack, to \renewcommand \thefigure to end with this, because for some interaction between packages, my figure captions started showing up as "Figure 1.2.:" with an extra period. The period can be made invisible by ending with \color{white}, but trying to \? it results in: ! Paragraph ended before \? was complete. –  Tim N Jan 10 '12 at 0:12
I should add that ending with \^ does put a hat over the dot. –  Tim N Jan 10 '12 at 0:12
You mention "because for some interaction between packages". There could be other ways around this, for which one would need to see a minimal working example (MWE) that illustrates your problem. However, for now, this question is most likely "answered". You could post a follow-up question. See I've just been told I have to post a follow-up question, why and how? –  Werner Jan 10 '12 at 0:27

You could try the following:

\newcommand*\swallow[1]{}

It simply consumes its argument but doesn't use it.

-
My goal was an ugly hack, to \renewcommand \thefigure to end with this, because for some interaction between packages, my figure captions started showing up as "Figure 1.2.:" with an extra period. The period can be made invisible by ending with \color{white}, but trying to \swallow it results in: ! Argument of \swallow has an extra }. –  Tim N Jan 10 '12 at 0:10
@TimN: Then the dot is added outside of the current brace group. You might want to use the caption package instead to change the caption format. –  Martin Scharrer Jan 10 '12 at 0:28
@MartinScharrer: I see. Still, \^ does what it does, so I suppose it's not impossible to solve? –  Tim N Jan 10 '12 at 0:33