Skip to content

Commit

Permalink
gh-35394: Adding a save method to class Standalone/TikzPicture for co…
Browse files Browse the repository at this point in the history
…mpatibility with sagetex

    
We add a save method to class Standalone/TikzPicture for compatibility
with sagetex. In particular, so that `\sageplot{t}` works when `t` is an
instance of Standalone/TikzPicture classes.

For example the following `file.tex`:

```
\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{sagetex}
\begin{document}
\begin{sagecommandline}
sage: from sage.misc.latex_standalone import TikzPicture
sage: V = [[1,0,1],[1,0,0],[1,1,0],[0,0,-1],[0,1,0],
....:      [-1,0,0],[0,1,1],[0,0,1],[0,-1,0]]
sage: P = Polyhedron(vertices=V).polar()
sage: s = P.projection().tikz([674,108,-731],112,
output_type='LatexExpr')
sage: t = TikzPicture(s)
\end{sagecommandline}
\begin{center}
    \sageplot{t}
\end{center}
\end{document}
```

will compile fine with the commands:
```
pdflatex file.tex
sage file.sagetex.sage
pdflatex file.tex
```
provided the `sagetex.sty` file is in the same repository.

Since sagetex creates by defaults `eps` and `pdf` images, we added
methods `dvi` and `eps` to the class Standalone following what was done
in the other methods. Also, we added a feature `dvips` to tag the
doctests with this new external feature. Finally, we made a small
improvement to the latex feature by providing more information in the
reason why a latex feature does not work.

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation accordingly.
    
URL: #35394
Reported by: Sébastien Labbé
Reviewer(s): Frédéric Chapoton, Sébastien Labbé
  • Loading branch information
Release Manager committed Apr 4, 2023
2 parents 97abc52 + fed096b commit 3d5a754
Show file tree
Hide file tree
Showing 3 changed files with 353 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/sage/doctest/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ class AvailableSoftware():
sage: from sage.doctest.external import external_software, available_software
sage: external_software
['cplex',
'dvips',
'ffmpeg',
'gurobi',
'internet',
Expand Down
47 changes: 45 additions & 2 deletions src/sage/features/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ def is_functional(self):
sage: from sage.features.latex import latex
sage: latex().is_functional() # optional - latex
FeatureTestResult('latex', True)
When the feature is not functional, more information on the reason
can be obtained as follows::
sage: result = latex().is_functional() # not tested
sage: print(result.reason) # not tested
Running latex on a sample file
(with command='latex -interaction=nonstopmode tmp_wmpos8ak.tex')
returned non-zero exit status='1' with stderr=''
and stdout='This is pdfTeX,
...
Runaway argument?
{document
! File ended while scanning use of \end.
...
No pages of output.
Transcript written on tmp_wmpos8ak.log.'
"""
lines = []
lines.append(r"\documentclass{article}")
Expand Down Expand Up @@ -77,8 +94,12 @@ def is_functional(self):
return FeatureTestResult(self, True)
else:
return FeatureTestResult(self, False, reason="Running latex on "
"a sample file returned non-zero "
"exit status {}".format(result.returncode))
"a sample file (with command='{}') returned non-zero "
"exit status='{}' with stderr='{}' "
"and stdout='{}'".format(result.args,
result.returncode,
result.stderr.strip(),
result.stdout.strip()))


class latex(LaTeX):
Expand Down Expand Up @@ -165,6 +186,27 @@ def __init__(self):
super().__init__("lualatex")


class dvips(Executable):
r"""
A :class:`~sage.features.Feature` describing the presence of ``dvips``
EXAMPLES::
sage: from sage.features.latex import dvips
sage: dvips().is_present() # optional - dvips
FeatureTestResult('dvips', True)
"""
def __init__(self):
r"""
TESTS::
sage: from sage.features.latex import dvips
sage: isinstance(dvips(), dvips)
True
"""
Executable.__init__(self, "dvips", executable="dvips",
url="https://tug.org/texinfohtml/dvips.html")

class TeXFile(StaticFile):
r"""
A :class:`sage.features.Feature` describing the presence of a TeX file
Expand Down Expand Up @@ -254,4 +296,5 @@ def all_features():
pdflatex(),
xelatex(),
lualatex(),
dvips(),
LaTeXPackage("tkz-graph")]
Loading

0 comments on commit 3d5a754

Please sign in to comment.