#17498: Pictures in the doc through ".. plot::" directive
-------------------------+-------------------------------------------------
Reporter: | Owner:
ncohen | Status: needs_review
Type: | Milestone: sage-6.5
enhancement | Resolution:
Priority: major | Merged in:
Component: | Reviewers:
documentation | Work issues:
Keywords: | Commit:
Authors: | 361f9a8a79aa51fa1f0d39dc08be0a379fb9b30a
Nathann Cohen | Stopgaps:
Report Upstream: N/A |
Branch: |
public/17498 |
Dependencies: |
#17508 |
-------------------------+-------------------------------------------------
Comment (by jhpalmieri):
Something like this might do it:
{{{
#!diff
diff --git a/Makefile b/Makefile
index 254c36c..7154e75 100644
--- a/Makefile
+++ b/Makefile
@@ -59,6 +59,9 @@ doc: doc-html
doc-html: build
$(PIPE) "./sage --docbuild --no-pdf-links all html
$(SAGE_DOCBUILD_OPTS) 2>&1" "tee -a logs/dochtml.log"
+doc-html-no-pix: build
+ $(PIPE) "./sage --docbuild --no-pdf-links all html-no-pix
$(SAGE_DOCBUILD_OPTS) 2>&1" "tee -a logs/dochtml.log"
+
doc-html-mathjax: build
$(PIPE) "./sage --docbuild --no-pdf-links all html -j
$(SAGE_DOCBUILD_OPTS) 2>&1" "tee -a logs/dochtml.log"
diff --git a/src/doc/common/builder.py b/src/doc/common/builder.py
index c817d86..36e45f3 100644
--- a/src/doc/common/builder.py
+++ b/src/doc/common/builder.py
@@ -1613,6 +1613,12 @@ if __name__ == '__main__':
# Set up Intersphinx cache
C = IntersphinxCache()
+ if type == 'html-no-pix':
+ type = 'html'
+ os.environ['SPHINX-INCLUDE-PLOTS'] = 'False'
+ else:
+ os.environ['SPHINX-INCLUDE-PLOTS'] = 'True'
+
# Get the builder and build.
try:
getattr(get_builder(name), type)()
diff --git a/src/doc/common/conf.py b/src/doc/common/conf.py
index 4bf8a1d..11be416 100644
--- a/src/doc/common/conf.py
+++ b/src/doc/common/conf.py
@@ -23,9 +23,28 @@ extensions = ['inventory_builder', 'multidocs',
'sphinx.ext.inheritance_diagram', 'sphinx.ext.todo',
'sphinx.ext.extlinks',
'matplotlib.sphinxext.plot_directive']
-from matplotlib.sphinxext import plot_directive
-from sage.plot.misc import plot_pre_code
+# This code is executed before each ".. PLOT::" directive in the Sphinx
+# documentation. It defines a 'draw' functions that displays a Sage
object
+# through mathplotlib, so that it will be displayed in the HTML doc
+plot_pre_code = """
+def sphinx_plot(plot):
+ import matplotlib.image as mpimg
+ from sage.misc.temporary_file import tmp_filename
+ import matplotlib.pyplot as plt
+ if os.environ.get('SPHINX-INCLUDE-PLOTS', False) == 'True':
+ fn = tmp_filename(ext=".png")
+ plot.plot().save(fn)
+ img = mpimg.imread(fn)
+ plt.imshow(img)
+ plt.margins(0)
+ plt.axis("off")
+ plt.tight_layout(pad=0)
+
+from sage.all_cmdline import *
+"""
+
plot_html_show_formats = False
# We do *not* fully initialize intersphinx since we call it by hand
diff --git a/src/sage/plot/misc.py b/src/sage/plot/misc.py
index e6e2058..79bfc30 100644
--- a/src/sage/plot/misc.py
+++ b/src/sage/plot/misc.py
@@ -377,22 +377,3 @@ def get_matplotlib_linestyle(linestyle, return_type):
"'dashed', 'dotted', dashdot', 'None'}, "
"respectively {'-', '--', ':', '-.', ''}"%
(linestyle))
-
-# This code is executed before each ".. PLOT::" directive in the Sphinx
-# documentation. It defines a 'sphinx_plot' function that displays a Sage
object
-# through mathplotlib, so that it will be displayed in the HTML doc.
-plot_pre_code = """
-def sphinx_plot(plot):
- import matplotlib.image as mpimg
- from sage.misc.temporary_file import tmp_filename
- import matplotlib.pyplot as plt
- fn = tmp_filename(ext=".png")
- plot.plot().save(fn)
- img = mpimg.imread(fn)
- plt.imshow(img)
- plt.margins(0)
- plt.axis("off")
- plt.tight_layout(pad=0)
-
-from sage.all_cmdline import *
-"""
}}}
Unfortunately, the presence or lack of pictures is cached in
`src/doc/output/doctrees`, so to see any difference between `make doc-
html` and `make doc-html-no-pix`, it's probably safest to first run `make
doc-clean`.
By the way, why not put "sphinx_plot" directly in `conf.py`, rather than
import it from `sage.plot.misc`? Also, the comment before it should be
changed to mention "sphinx_plot" instead of "draw".
--
Ticket URL: <http://trac.sagemath.org/ticket/17498#comment:45>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.