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 "."?

  • 1
    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
  • 1
    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. Nov 14 '12 at 9:37
  • @StefanMüller: but it should be easy to modify your bibliography style file.
    – user2478
    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:

    % set verbatim catcodes
    % restore catcode of argument braces
    \catcode`\{=1 %
    \catcode`\}=2 %
  % eats the URL in #1
  % skip an optional dot

Normal url:

Skipped urls:


  • 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. Nov 14 '12 at 10:47

Works only if the URL has no special characters!




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



enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.