# macro that deletes whatever symbol follows after the code and leave no space

How would the following macro X be defined in TeX?

word in previous sentence?\macroX . Next sentence


gives output identical to

word in previous sentence? Next sentence


The motivation: a period is placed by another macro automatically, to automate repetitive data entry and display in parts of a document. Sometimes however different punctuation is required. The period is appropriate in 95% of all cases but in the exceptions such a macro X would be required to allow the data entry to remain automated. One may imagine this has been done before somewhere already, likely for the same reason?

To clarify, the idea is that whatever character is after the macro simply gets ignored.

EDIT: My question itself was actual simpler than question that was answered (I must add here that, in my case, egreg suggested a better solution to the concrete problem I was trying to solve in the first place).

My question was merely (1): what macro deletes whatever character is found to the right of it?

For future knowledge and general completeness of the question for anyone else searching for this type of output, perhaps myself later, does anyone know what macro fits the description in my question (1)? (In case the object to be deleted is not a period but some arbitrary letter or number.)

MWE (this general case):

\documentclass[12pt]{article}
\usepackage{amsfonts,mathtools,amsthm,amssymb}
\def\relevantpartofbigmacro{\textit{#1}.\egroup\par}
\begin{document}
\relevantpartofbigmacro{test}
\end{document}


gives

\textit{test}.


whereas the idea is to write (in the exceptional cases)

\documentclass[12pt]{article}
\usepackage{amsfonts,mathtools,amsthm,amssymb}
\def\relevantpartofbigmacro{\textit{#1}.\egroup\par}
\begin{document}
\relevantpartofbigmacro{test?\macroX}
\end{document}


to give

\textit{test?}


Or again

\documentclass[12pt]{article}
\usepackage{amsfonts,mathtools,amsthm,amssymb}
\def\relevantpartofbigmacro{\textit{#1}5\egroup\par}
\begin{document}
\relevantpartofbigmacro{test}
\end{document}


gives

\textit{test}5


whereas the idea is to write (in the exceptional cases)

\documentclass[12pt]{article}
\usepackage{amsfonts,mathtools,amsthm,amssymb}
\def\relevantpartofbigmacro{\textit{#1}5\egroup\par}
\begin{document}
\relevantpartofbigmacro{test7\macroX}
\end{document}


to give

\textit{test7}

-
Yes, it's done in amsthm and its \@addpunct command. –  egreg Jul 20 at 10:33
How would this be used? word in previous sentence?\@addpunct . Next sentence outputs added word in previous sentence?addpunct . Next sentence so I am doing something wrong, yes? –  Guido Jorg Jul 20 at 10:45
Did you test the definition of \relevantpartofbigmacro with \@addpunct{.} instead of .? I did, and it gives the expected result without any need of adding \macroX in the input. –  egreg Jul 20 at 13:20
Yes, that works perfectly, as I mentioned, since in my special reason for asking the question was to deal with punctuation. But I was wondering if there is a similar macro that executes "go right delete token" in general, for any token, because it would be very useful to have to define macros. Imagine the . replaced by 5 for instance. But suppose there are a couple exceptions that end with 7. –  Guido Jorg Jul 20 at 13:29
in what way is \@gobble not the answer to your edited question (1) ? –  David Carlisle Jul 20 at 21:53

I'm not sure I understand the problem. Here's how it's treated with the macro \@addpunct made available by amsthm:

\documentclass{article}
\usepackage{amsthm}

\makeatletter
}
\makeatother

\begin{document}
Here we use \macroaddingperiod{on some text}

\end{document}


Let's tackle the case where the user is supposed to help LaTeX and type \macroX in the exceptional case.

\documentclass[12pt]{article}
\usepackage{amsfonts,mathtools,amsthm,amssymb}

\makeatletter
\def\relevantpartofbigmacro#1{%
\bgroup...% just to have a balance
\textit{#1}%
5%
\egroup\par
}
\def\macroX{\aftergroup\macroX@aux}
\def\macroX@aux#1#2{#1}
\makeatother

\begin{document}
\relevantpartofbigmacro{test7}
\relevantpartofbigmacro{test7\macroX}
\end{document}


This exploits the fact that \textit already puts \maybe@ic after the group; so with \macroX@aux we remove the first token (the 5) and apply \maybe@ic to the next one.

-
I see now. That worked great for punctuation, the case I was trying to solve here. I am accepting you answer. Actually my question itself was basically just: what macro simply deletes whatever character is separated from it by one space to the right? For general future knowledge, do you know what macro does that? (In case the object to be deleted is not a period but some arbitrary letter or number.) –  Guido Jorg Jul 20 at 12:29
@GuidoJorg \macroX . has no space; for removing a token after \macroX let it equal to \@gobble. –  egreg Jul 20 at 12:41
I see gobble must have a makeatother places after the part to be deleted. –  Guido Jorg Jul 20 at 13:00
@GuidoJorg Of course, you can't use \@gobble without doing \makeatletter. Without a real example of what you want to do, it's just guesswork. –  egreg Jul 20 at 13:01
MWE added to the question. –  Guido Jorg Jul 20 at 13:15

the question isn't very clear but

\newcomamnd\macroX[1]{}


appears to do what you ask.

-
Yes, this is exactly what I was looking for in the general case. Turns out I was looking for the simplest one input macro in all TeX :) –  Guido Jorg Jul 21 at 9:00
@GuidoJorg go on then: move the tick from egreg to me, it always makes him so happy when that happens:-) –  David Carlisle Jul 21 at 9:07
I'd like to tick both as is often the case. The macroX case ended up a thing to keep in the toolbox for future reference [to deal with other exceptions]. egreg's solution is better thing to use in my described application since it s typed once inside the macro def itself. My (in this case inefficient) idea was to brutishly type \macroX after ? or ! each and every time I had {blah?} instead of {blah}. How about you make a comment or two here and I vote up them also? –  Guido Jorg Jul 22 at 2:51
@GuidoJorg don't worry about it: egreg and I have more than enough rep already so we amuse each other in chat by trying to steal ticks from each other (I must say mostly egreg steals them from me, so I thought I had a chance to get one back:-) –  David Carlisle Jul 22 at 7:32