Skip to content

Commit d16eb00

Browse files
author
Release Manager
committed
gh-38848: Adding a tikz method to FinitePoset class We add a `tikz` method to the class `FinitePoset` returning a `TikzPicture` instance from `sage.misc.latex_standalone` module. ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies It uses the tikz method for graphs added in #38798 and the follow-up small fix made in #38847. URL: #38848 Reported by: Sébastien Labbé Reviewer(s): Frédéric Chapoton, Travis Scrimshaw
2 parents b397659 + 4518878 commit d16eb00

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

src/sage/combinat/posets/posets.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,76 @@ def _latex_(self):
13961396
"""
13971397
return self.hasse_diagram()._latex_()
13981398

1399+
def tikz(self, format=None, edge_labels=False, color_by_label=False,
1400+
prog='dot', rankdir='up', standalone_config=None,
1401+
usepackage=None, usetikzlibrary=None, macros=None,
1402+
use_sage_preamble=None, **kwds):
1403+
r"""
1404+
Return a TikzPicture illustrating the poset.
1405+
1406+
If ``graphviz`` and ``dot2tex`` are available, it uses these packages for
1407+
placements of vertices and edges.
1408+
1409+
INPUT:
1410+
1411+
- ``format`` -- string (default: ``None``), ``'dot2tex'`` or
1412+
``'tkz_graph'``. If ``None``, it is set to ``'dot2tex'`` if
1413+
dot2tex is present, otherwise it is set to ``'tkz_graph'``.
1414+
- ``edge_labels`` -- bool (default: ``False``)
1415+
- ``color_by_label`` -- boolean or dictionary or function (default:
1416+
``False``); whether to color each edge with a different color
1417+
according to its label; the colors are chosen along a rainbow, unless
1418+
they are specified by a function or dictionary mapping labels to
1419+
colors;
1420+
1421+
When using format ``'dot2tex'``, the following inputs are considered:
1422+
1423+
- ``prog`` -- string (default: ``'dot'``) the program used for the
1424+
layout corresponding to one of the software of the graphviz
1425+
suite: 'dot', 'neato', 'twopi', 'circo' or 'fdp'.
1426+
- ``rankdir`` -- string (default: ``'up'``), direction of graph layout
1427+
when prog is ``'dot'``, possible values are ``'down'``,
1428+
``'up'``, ``'right'`` and ``'left'``.
1429+
1430+
Additional keywords arguments are forwarded to
1431+
:meth:`sage.graphs.graph_latex.GraphLatex.set_option`.
1432+
1433+
The following inputs define the preamble of the latex standalone
1434+
document class file containing the tikzpicture:
1435+
1436+
- ``standalone_config`` -- list of strings (default: ``["border=4mm"]``);
1437+
latex document class standalone configuration options
1438+
- ``usepackage`` -- list of strings (default: ``[]``); latex
1439+
packages
1440+
- ``usetikzlibrary`` -- list of strings (default: ``[]``); tikz
1441+
libraries to use
1442+
- ``macros`` -- list of strings (default: ``[]``); list of
1443+
newcommands needed for the picture
1444+
- ``use_sage_preamble`` -- bool (default: ``None``), if ``None``
1445+
it is set to ``True`` if and only if format is ``'tkz_graph'``
1446+
1447+
OUTPUT:
1448+
1449+
An instance of :mod:`sage.misc.latex_standalone.TikzPicture`.
1450+
1451+
.. NOTE::
1452+
1453+
Prerequisite: dot2tex optional Sage package and graphviz must be
1454+
installed when using format ``'dot2tex'``.
1455+
1456+
EXAMPLES::
1457+
1458+
sage: P = Poset(([1,2], [[1,2]]), cover_relations=True)
1459+
sage: tikz = P.tikz() # optional - dot2tex graphviz # long time
1460+
sage: _ = tikz.pdf(view=False) # optional - dot2tex graphviz latex # long time
1461+
"""
1462+
G = self.hasse_diagram()
1463+
return G.tikz(format=format, edge_labels=edge_labels,
1464+
color_by_label=color_by_label, prog=prog, rankdir=rankdir,
1465+
standalone_config=standalone_config, usepackage=usepackage,
1466+
usetikzlibrary=usetikzlibrary, macros=macros,
1467+
use_sage_preamble=use_sage_preamble, **kwds)
1468+
13991469
def _repr_(self):
14001470
r"""
14011471
Return a string representation of the poset.

0 commit comments

Comments
 (0)