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:


It has the advantage that it works with paragraphs like and does not need more than one argument. I can just use it like this: \pg{}

  • you were nearly there but you put a space and a spurious {} into the URL your URL ended html# jls-{6.1} not html#jls-6.1 – David Carlisle Mar 14 '17 at 14:18
  • For me using evince and firefox the link works. – Skillmon likes topanswers.xyz Mar 14 '17 at 14:19

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.