I am trying do define a macro that automatically links to a paragraph in the Java Language Specifications. But for some reason, it is not working.
I want to call the command with a paragraph number, e.g. \pg{6.6}
, and it should display as §6.6
which links to the correct JLS entry (in this case this link http://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.6).
This is what I have so far:
\newcommand{\pg}[1]{\href{http://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html\# jls-{#1}}{§#1}}
But this code causes a problem with the link. It is not working correctly. When I hover over the text, it indicates a link, but clicking won't do anything.
Another problem is that this command would only work for paragraphs in chapter 6, because of the chapter declaration in the link. Is there a way around this?
EDIT: This my current solution which is based on Davids Solution and uses the xstring
package:
\newcommand{\pg}[1]{%
\StrLeft{#1}{1}[\firstletter]%
\href{http://docs.oracle.com/javase/specs/jls/se8/html/jls-\firstletter.html\#jls-#1}{§#1}%
}
It has the advantage that it works with paragraphs like 5.3.1.4 and does not need more than one argument. I can just use it like this: \pg{5.3.1.4}
{}
into the URL your URL endedhtml# jls-{6.1}
nothtml#jls-6.1