WeBWorK Problems

Link to local pdf

Link to local pdf

by John Jones -
Number of replies: 2
A problem author has a pdf file they want to link to from a problem.  The pdf is in the same directory as the pg file.  At first, it looks like one should use

\{  htmlLink(alias("myfile.pdf"), "read this important info") \}

in the text of the problem.  However, when viewing the problem in a web page, alias detects that the mode is html and refuses to make the alias to the pdf.  I suppose that this is because it can't tell that this is for a link rather than embedding an image in the page.

Should alias just create the alias, or is there another provision to handle this.


In reply to John Jones

Re: Link to local pdf

by Paul Pearson -
Hi John,

The alias() function is provided by PGalias.pm and is currently designed to work only for a few file extensions (.html, .png, and .gif come to mind, but there are probably a few others that are also supported by the PGalias.pm code).  For several years now, Mike Gage has said that PGalias.pm ought to be rewritten (or at least extended) to include more file extensions, such as .pdf, .txt, .js, etc.

Basically, what alias() does is to copy the file from the directory that contains the the .pg file (which is not available to the world) to a newly created and randomly named directory/file (which is available to the world).  Then, it points the user to the copy of the file in the randomly named directory/file.

Would anyone be willing to work on PGalias?  Are there any file extensions that alias() ought to support that it does not right now?

Best regards,

Paul Pearson
In reply to Paul Pearson

Re: Link to local pdf

by John Jones -
Since no one had come forward with a good reason not to have links to local pdfs, I made a small change to PGalias earlier today and submitted a pull request which would allow it.

Here is more detail for those who are interested.  There are two reasons I can think of to call alias on a local pdf file
  1. make a link to the pdf
  2. use the pdf as the src for an img tag (like including a .png image)
Use 1 seems to be a valid reason to call alias on a pdf, it did not work before, but would now work with the change.  Note, there are a variety of OPL problems which have had links to external pdfs, and the links almost invariably break over time.  If they had been local links where the pdf file had come with the problem, they would still work.

Use 2 is a wash because it fails no matter what (a tag of <img src="myfile.pdf"> doesn't work).  So I don't think we need PGalias to throw an error in that situation.