Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions src/sage/combinat/posets/posets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,77 @@ def _latex_(self):
"""
return self.hasse_diagram()._latex_()

def tikz(self, format=None, edge_labels=False, color_by_label=False,
prog='dot', rankdir='up', standalone_config=None,
usepackage=None, usetikzlibrary=None, macros=None,
use_sage_preamble=None, **kwds):
r"""
Return a TikzPicture illustrating the poset.

If graphviz and dot2tex are available, it uses these packages for
placements of vertices and edges.

INPUT:

- ``format`` -- string (default: ``None``), ``'dot2tex'`` or
``'tkz_graph'``. If ``None``, it is set to ``'dot2tex'`` if
dot2tex is present, otherwise it is set to ``'tkz_graph'``.
- ``edge_labels`` -- bool (default: ``False``)
- ``color_by_label`` -- boolean or dictionary or function (default:
``False``); whether to color each edge with a different color
according to its label; the colors are chosen along a rainbow, unless
they are specified by a function or dictionary mapping labels to
colors;

When using format ``'dot2tex'``, the following inputs are considered:

- ``prog`` -- string (default: ``'dot'``) the program used for the
layout corresponding to one of the software of the graphviz
suite: 'dot', 'neato', 'twopi', 'circo' or 'fdp'.
- ``rankdir`` -- string (default: ``'up'``), direction of graph layout
when prog is ``'dot'``, possible values are ``'down'``,
``'up'``, ``'right'`` and ``'left'``.

Additionnal keywords arguments are forwarded to
:meth:`sage.graphs.graph_latex.GraphLatex.set_option`.

The following inputs define the preamble of the latex standalone
document class file containing the tikzpicture:

- ``standalone_config`` -- list of strings (default: ``["border=4mm"]``);
latex document class standalone configuration options
- ``usepackage`` -- list of strings (default: ``[]``); latex
packages
- ``usetikzlibrary`` -- list of strings (default: ``[]``); tikz
libraries to use
- ``macros`` -- list of strings (default: ``[]``); list of
newcommands needed for the picture
- ``use_sage_preamble`` -- bool (default: ``None``), if ``None``
it is set to ``True`` if and only if format is ``'tkz_graph'``

OUTPUT:

An instance of :mod:`sage.misc.latex_standalone.TikzPicture`.

.. NOTE::

Prerequisite: dot2tex optional Sage package and graphviz must be
installed when using format ``'dot2tex'``.

EXAMPLES::

sage: P = Poset(([1,2], [[1,2]]), cover_relations = True)
sage: tikz = P.tikz() # optional - dot2tex graphviz # long time
sage: _ = tikz.pdf(view=False) # optional - dot2tex graphviz latex # long time

"""
G = self.hasse_diagram()
return G.tikz(format=format, edge_labels=edge_labels,
color_by_label=color_by_label, prog=prog, rankdir=rankdir,
standalone_config=standalone_config, usepackage=usepackage,
usetikzlibrary=usetikzlibrary, macros=macros,
use_sage_preamble=use_sage_preamble, **kwds)

def _repr_(self):
r"""
Return a string representation of the poset.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/generic_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ def _latex_(self):

return self.latex_options().latex()

def tikz(self, format='dot2tex', edge_labels=None,
def tikz(self, format=None, edge_labels=None,
color_by_label=False, prog='dot', rankdir='down',
standalone_config=None, usepackage=None,
usetikzlibrary=None, macros=None,
Expand Down