WeBWorK Problems

Link to local pdf

Link to local pdf

by John Jones -
Number of replies: 5
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.


In reply to John Jones

Re: Link to local pdf

by Sukhjit Singh Sehra -


Was there any success in attaching link to local pdf files to .pg file?

I want to upload an assignment in PDF to file manager of the course and release on Webwork Assignment for students. But, when I open it: Webwork throws an error message: 

                                 No display module found for path '/CourseName/assignment_name/1/template/file.pdf/

Here, I am trying to access the file.pdf uploaded in File Manage. Any input will be appreciated. 

In reply to Sukhjit Singh Sehra

Re: Link to local pdf

by Danny Glin -

WeBWorK is not designed to provide direct access to files in the templates directory.

From within a pg file you can use the following to create a link to a pdf file:

\{ htmlLink( alias('file.pdf'), "link to file", "TARGET='_blank'" ) \}

If you are using PGML you would use this instead:

[@ \{ htmlLink( alias('error2.pdf'), "link to file", "TARGET='_blank'" ) @]*

Note that the alias subroutine is hard-coded to only handle certain file formats, so pdfs are okay, but if you try to link to some exotic file format you might get an error.

In reply to Danny Glin

Re: Link to local pdf

by Alex Jordan -

Danny's code works for when `file.pdf` is in the same directory as the pg file, as OP describes.

An alternative that is better in some (not all!) situations, is to put the file in the course's html/ folder. That folder is parallel to templates/, so you navigate up one level in the File Manager to get there.

And then replace `alias('file.pdf')` with:

And if you really want to hard code a link to that file in one specific course's html/ folder, then replace  `alias('file.pdf')` with:
where `myschool` and `mycourse` are edited appropriately.

To decide what is best, think about the consequences of how the .pg file is coded, and what will happen if it propagates to other courses.