# Eating a dot after a command

I have a bibliography in which URLs are printed with a following "." I would like to omit the URLs to save space and I could do this by redefining the URL command, but this would leave me with a dot. Is there a way to define a command that eats a following "."?

-
If all the URLs are in the form \url{...}., then redefine \url with two arguments to do nothing with them. Otherwise something slightly more complicated should be done. –  egreg Nov 14 '12 at 9:28
Maybe you can pick or design a bibliography style that will omit the url fields? That would look like a more natural way of doing it, for example in case you have urls elsewhere in your text. –  T. Verron Nov 14 '12 at 9:35
I have a bibliography that contains URLs they are set like \url{ ... }. I cannot influence this. So I have to redifine the url command to eat this dot. –  Stefan Müller Nov 14 '12 at 9:37
@StefanMüller: but it should be easy to modify your bibliography style file. –  Herbert Nov 14 '12 at 12:04

• The redefinition of \url is not trivial, because the argument might contain the percent character. Therefore the argument needs to be read with verbatim catcodes.

• The dot can be removed using \@ifnextchar.\@gobble{}. This also catches the case that \url{...} is not followed by a dot. As side effect \@ifnextchar removes spaces. This can be avoided by using \ltx@ifnextchar@nospace of package ltxcmds instead of \@ifnextchar.

Example file:

\documentclass{article}
\usepackage{url}
\makeatletter
\newcommand*{\urlgobble}{%
\begingroup
% set verbatim catcodes
\let\do\@makeother
\dospecials
% restore catcode of argument braces
\catcode\{=1 %
\catcode\}=2 %
\@urlgobble
}
\newcommand*{\@urlgobble}[1]{%
% eats the URL in #1
\endgroup
% skip an optional dot
\@ifnextchar.\@gobble{}%
}
\newcommand*{\skipurls}{\let\url\urlgobble}
\makeatother

\begin{document}
Normal url:
\url{http://www.example.org/Hello%20World.html}

\skipurls
Skipped urls:
\url{http://www.example.net/Hello%20World.html}
\url{http://www.example.com/Hello%20World.html}.
\end{document}


-
Great answer (as usual); I've changed \urlgobble into \url in the final example, which seemed to be your intent, as \skipurl was given. –  egreg Nov 14 '12 at 10:31
@egreg Thanks, it was a leftover from testing that I have forgotten to revert. –  Heiko Oberdiek Nov 14 '12 at 10:47

Works only if the URL has no special characters!

\documentclass{article}
\usepackage{url}
\begin{document}

\url{http://www.dante.de}.

\makeatletter
\let\URL\url
\def\url#1{\@ifnextchar.\url@i{\url@i.}}
\def\url@i.{}
\makeatother

Not printed: \url{http://www.dante.de}.

\URL{http://www.dante.de}

\end{document}


-