Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit e9967dc

Browse files
author
Release Manager
committed
Trac #33206: PDF documentation links in Documentation from Jupyter notebook are broken
To replicate the issue: * ./configure --enable-sagemath_doc_pdf=yes * make * ./sage -n jupyter * select `New -> SageMath xxxx` * select `Help -> Sage Documentation` `Clicking` on any of the PDF icons gives, for example, in the terminal: {{{ [W 20:13:44.654 NotebookApp] Kernelspec name pdf cannot be found! [W 20:13:44.655 NotebookApp] 404 GET /kernelspecs/pdf/en/tutorial/SageTutorial.pdf (::1): Kernel spec pdf not found [W 20:13:44.656 NotebookApp] 404 GET /kernelspecs/pdf/en/tutorial/SageTutorial.pdf (::1) 2.920000ms referer=http://localhost:8888/kernelspecs/sagemath/doc/index.html }}} with a corresponding `404 : Not Found` browser page Note: if Sage is configured with `--enable-sagemath_doc_pdf=no` then PDF documentation icons/links will not appear in the Documentation. URL: https://trac.sagemath.org/33206 Reported by: strogdon Ticket author(s): Steven Trogdon, Kwankyu Lee Reviewer(s): Kwankyu Lee, Steven Trogdon
2 parents 8585f89 + 4b6ac0f commit e9967dc

File tree

2 files changed

+26
-72
lines changed

2 files changed

+26
-72
lines changed

src/doc/en/website/templates/index.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ <h2>
4141
<a class="biglink" href="tutorial/index.html">
4242
Tutorial
4343
</a>
44-
<a title="Download PDF" class="pdf" href="../../pdf/en/tutorial/SageTutorial.pdf">
44+
<a title="Download PDF" class="pdf" href="pdf/en/tutorial/SageTutorial.pdf">
4545
<img class="icon" src="_static/pdf.png"></img>
4646
</a>
4747
<br>
@@ -57,7 +57,7 @@ <h2>
5757
<a class="biglink" href="faq/index.html">
5858
FAQs
5959
</a>
60-
<a title="Download PDF" class="pdf" href="../../pdf/en/faq/faq.pdf">
60+
<a title="Download PDF" class="pdf" href="pdf/en/faq/faq.pdf">
6161
<img class="icon" src="_static/pdf.png"></img>
6262
</a>
6363
<br>
@@ -81,7 +81,7 @@ <h2>
8181
Thematic Tutorials
8282
</a>
8383
<a title="Download PDF" class="pdf"
84-
href="../../pdf/en/thematic_tutorials/thematic_tutorials.pdf">
84+
href="pdf/en/thematic_tutorials/thematic_tutorials.pdf">
8585
<img class="icon" src="_static/pdf.png"></img>
8686
</a>
8787
<br>
@@ -102,7 +102,7 @@ <h2>
102102
<a class="biglink" href="prep/index.html">
103103
PREP Tutorials
104104
</a>
105-
<a title="Download PDF" class="pdf" href="../../pdf/en/prep/prep_tutorials.pdf">
105+
<a title="Download PDF" class="pdf" href="pdf/en/prep/prep_tutorials.pdf">
106106
<img class="icon" src="_static/pdf.png"></img>
107107
</a>
108108
<br>
@@ -137,7 +137,7 @@ <h2>
137137
<a class="biglink" href="reference/index.html">
138138
Reference Manual
139139
</a>
140-
<a title="Link to PDF" class="pdf" href="../../pdf/en/reference/index.html">
140+
<a title="Link to PDF" class="pdf" href="pdf/en/reference/index.html">
141141
<img class="icon" src="_static/pdf.png"></img>
142142
</a>
143143
<br>
@@ -178,7 +178,7 @@ <h2>
178178
<a class="biglink" href="installation/index.html">
179179
Installation Guide
180180
</a>
181-
<a title="Download PDF" class="pdf" href="../../pdf/en/installation/installation.pdf">
181+
<a title="Download PDF" class="pdf" href="pdf/en/installation/installation.pdf">
182182
<img class="icon" src="_static/pdf.png"></img>
183183
</a>
184184
<br>
@@ -196,7 +196,7 @@ <h2>
196196
<a class="biglink" href="developer/index.html">
197197
Developer's Guide
198198
</a>
199-
<a title="Download PDF" class="pdf" href="../../pdf/en/developer/developer.pdf">
199+
<a title="Download PDF" class="pdf" href="pdf/en/developer/developer.pdf">
200200
<img class="icon" src="_static/pdf.png"></img>
201201
</a>
202202
<br>
@@ -231,7 +231,7 @@ <h2>
231231
<a class="biglink" href="a_tour_of_sage/index.html">
232232
A Tour of Sage
233233
</a>
234-
<a title="Download PDF" class="pdf" href="../../pdf/en/a_tour_of_sage/a_tour_of_sage.pdf">
234+
<a title="Download PDF" class="pdf" href="pdf/en/a_tour_of_sage/a_tour_of_sage.pdf">
235235
<img class="icon" src="_static/pdf.png"></img>
236236
</a>
237237
<br>
@@ -248,7 +248,7 @@ <h2>
248248
<a class="biglink" href="constructions/index.html">
249249
Constructions
250250
</a>
251-
<a title="Download PDF" class="pdf" href="../../pdf/en/constructions/constructions.pdf">
251+
<a title="Download PDF" class="pdf" href="pdf/en/constructions/constructions.pdf">
252252
<img class="icon" src="_static/pdf.png"></img>
253253
</a>
254254
<br>

src/sage_docbuild/__init__.py

Lines changed: 17 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ class WebsiteBuilder(DocBuilder):
399399
def html(self):
400400
"""
401401
After we've finished building the website index page, we copy
402-
everything one directory up. Then we call
403-
:meth:`create_html_redirects`.
402+
everything one directory up.
404403
"""
405404
DocBuilder.html(self)
406405
html_output_dir = self._output_dir('html')
@@ -413,69 +412,24 @@ def html(self):
413412
else:
414413
shutil.copy2(src, dst)
415414

416-
def create_html_redirects(self):
415+
def pdf(self):
417416
"""
418-
Writes a number of small HTML files; these are files which used to
419-
contain the main content of the reference manual before splitting the
420-
manual into multiple documents. After the split, those files have
421-
moved, so in each old location, write a file which redirects to the new
422-
version. (This is so old URLs to pieces of the reference manual still
423-
open the correct files.)
417+
# Install in the directory one level up to website_dir a symlink to the
418+
# directory containing pdf files. This symlink is necessary to access
419+
# pdf documentation files within Jupyter (see trac #33206).
424420
"""
425-
from sage.misc.superseded import deprecation
426-
deprecation(29993, "This method was created in trac #6495 for backward compatibility. Not necessary anymore.")
427-
428-
# The simple html template which will cause a redirect to the correct file.
429-
html_template = """<html><head>
430-
<meta HTTP-EQUIV="REFRESH" content="0; url=%s">
431-
</head><body></body></html>"""
432-
433-
reference_dir = os.path.abspath(os.path.join(self._output_dir('html'),
434-
'..', 'reference'))
435-
reference_builder = ReferenceBuilder('reference')
436-
refdir = os.path.join(SAGE_DOC_SRC, 'en', 'reference')
437-
for document in reference_builder.get_all_documents(refdir):
438-
# path is the directory above reference dir
439-
path = os.path.abspath(os.path.join(reference_dir, '..'))
440-
441-
# the name of the subdocument
442-
document_name = document.split('/')[1]
443-
444-
# the sage directory within a subdocument, for example
445-
# local/share/doc/sage/html/en/reference/algebras/sage
446-
sage_directory = os.path.join(path, document, 'sage')
447-
448-
# Walk through all of the files in the sage_directory
449-
for dirpath, dirnames, filenames in os.walk(sage_directory):
450-
# a string like reference/algebras/sage/algebras
451-
short_path = dirpath[len(path) + 1:]
452-
453-
# a string like sage/algebras
454-
shorter_path = os.path.join(*short_path.split(os.sep)[2:])
455-
456-
# make the shorter path directory
457-
try:
458-
os.makedirs(os.path.join(reference_dir, shorter_path))
459-
except OSError:
460-
pass
461-
462-
for filename in filenames:
463-
if not filename.endswith('html'):
464-
continue
465-
466-
# the name of the html file we are going to create
467-
redirect_filename = os.path.join(reference_dir, shorter_path, filename)
468-
469-
# the number of levels up we need to use in the relative url
470-
levels_up = len(shorter_path.split(os.sep))
471-
472-
# the relative url that we will redirect to
473-
redirect_url = "/".join(['..'] * levels_up + [document_name, shorter_path, filename])
474-
475-
# write the html file which performs the redirect
476-
with open(redirect_filename, 'w') as f:
477-
print(redirect_filename)
478-
f.write(html_template % redirect_url)
421+
super().pdf()
422+
423+
html_output_dir = self._output_dir('html')
424+
pdf_doc_dir = os.path.join(SAGE_DOC, 'pdf')
425+
426+
# relative path is preferable for symlinks
427+
dst = os.path.join(html_output_dir, '..')
428+
relpath = os.path.relpath(pdf_doc_dir, dst)
429+
try:
430+
os.symlink(relpath, os.path.join(dst, 'pdf'))
431+
except FileExistsError:
432+
pass
479433

480434
def clean(self):
481435
"""

0 commit comments

Comments
 (0)