I want to set a new command which aims at using href (from hyperref package) but by providing some hypertarget as argument of the new command for a specific pdf.

Classical use of hypperref and href is : In first document A, I put some hypertarget :

\hypertarget{fileAhypertarget}{Should come to this}

In the second document B, I make a reference to hypertarget of document FileA.pdf

\href{fileA.pdf#fileAhypertarget}{Let's go to file A!}

Please notice that syntax of href for url in pdf use a # symbol

It works, but now I want to define a command of this type


But it does not work as # symbol of href command enters in conflict with # symbol of arguments of \newcommand.

Have you any idea, I try different syntax, \protect and thought to \expandafter but I failed.

If you have any idea, Thanks a lot

  • 1
    you need ## for the # and #1 for the argument, so 3 # Apr 16 '14 at 15:34
  • @DavidCarlisle Did you try?
    – egreg
    Apr 16 '14 at 15:42
  • @egreg no I went home:-) (I thought hyperref rescanned it, I guess not:-) Apr 16 '14 at 17:28

You need that LaTeX sees a “stringified” #; here's a way


\begingroup\lccode`?=`# \lowercase{\endgroup

\myhref{fileAhypertarget}{Let's go}

Of course you lose the special treatment \href does to special characters, but it's not a problem if argument #1 has none of them.

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.