I'm having trouble using newcommand with the \href

I would like a newcommand like this:


This command works fine quite all, for exemple:


But it does not work when the URL name has code like #1. For example, it does not work in this exemple:


It does not work because the #1 in the URL name is used with the #1 in the newcommand.

How could I solve this problem?

  • Thank you for your answer. I believe this is not a duplicate topic. But may be I did not understand your suggestion. In my case, there are websides that have in your URL codes as # 1, for example: [matematica.obmep.org.br/index.php/modulo/index#1] And there are websites with simpler URL, for example: [impa.br] In all of my cases, I wish that the URL is send to the newcommand as a string. Oct 24, 2014 at 16:19
  • You could use \edef\temp{#1}\href{\temp} Oct 24, 2014 at 17:46
  • Excuse me. Unfortunately I did not understand your suggestion. Could you explain how it would look all the code so that I can pass any URL address for the newcommand? Thank you. Oct 25, 2014 at 12:52

1 Answer 1


Really this is a duplicate of Problem with use of '#' in custom \href command. But just to make it clear how to use this in your case here is a complete example:








As in the other question, one defines a helper command which is called with # given an appropriate category code so it is no longer interpreted as a command argument.


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