Ticket #12083: trac12083_tikz_polytope_review.patch

File trac12083_tikz_polytope_review.patch, 22.4 KB (added by jipilab, 10 years ago)

Apply over the precedent patch

  • sage/geometry/polyhedra.py

    # HG changeset patch
    # User Jean-Philippe Labbé <labbe at math.fu-berlin.de>
    # Date 1338471031 -7200
    # Node ID 0bfb394ac7bd32f7896c4607da026b4f717b01c0
    # Parent  65c1e557ebb3ce13d509a0eecabb8605598b920d
    trac #12083: first review version
    
    diff --git a/sage/geometry/polyhedra.py b/sage/geometry/polyhedra.py
    a b  
    120120
    121121from subprocess import Popen, PIPE
    122122from sage.misc.all import tmp_filename
    123 from sage.misc.functional import norm, n
     123from sage.misc.functional import norm
    124124from sage.misc.package import is_package_installed
     125from sage.misc.latex import LatexExpr
    125126
    126127from sage.rings.all import Integer, QQ, ZZ, primes_first_n
    127128from sage.rings.real_double import RDF
    128129from sage.modules.free_module_element import vector
    129 from sage.modules.free_module import VectorSpace
    130130from sage.matrix.constructor import matrix, identity_matrix
    131131from sage.functions.other import sqrt, floor, ceil
    132132from sage.functions.trig import sin, cos
     
    48794879        self._restricted_automorphism_group = group
    48804880        return group
    48814881
    4882     def tikz(self, view=[0,0,1], rot_angle=0, scale=2,
     4882    def tikz(self, view=[0,0,1], angle=0, scale=2,
    48834883             edge_color='blue!95!black', facet_color='blue!95!black',
    48844884             opacity=0.8, vertex_color='green', axis=False):
    48854885        """
    48864886        Return a string ``tikz_pic`` consisting of a tikz picture of ``self``
    4887         according to a projection ``view`` and an angle ``rot_angle``
     4887        according to a projection ``view`` and an angle ``angle``
    48884888        obtained via Jmol through the current state property.
    48894889
    48904890        INPUT:
    48914891
    4892         - ``view`` -- a list of length 3 representing a vector;
    4893         - ``rot_angle`` -- an angle in degree from 0 to 360;
    4894         - ``scale`` -- an integer specifying the scaling of the tikz picture;
    4895         - ``edge_color``, ``facet_color``, ``vertex_color`` -- string representing
    4896           colors which tikz recognize;
    4897         - ``opacity`` -- a real number between 0 and 1 giving the opacity of
    4898           the front facets;
    4899         - ``axis`` -- a Boolean, to draw the axes at the origin.
     4892        - ``view`` - list (default: [0,0,1]) representing the rotation axis (see note below).
     4893        - ``angle`` - integer (default: 0) angle of rotation in degree from 0 to 360 (see note
     4894          below).
     4895        - ``scale`` - integer (default: 2) specifying the scaling of the tikz picture.
     4896        - ``edge_color`` - string (default: 'blue!95!black') representing colors which tikz
     4897          recognize.
     4898        - ``facet_color`` - string (default: 'blue!95!black') representing colors which tikz
     4899          recognize.
     4900        - ``vertex_color`` - string (default: 'green') representing colors which tikz
     4901          recognize.
     4902        - ``opacity`` - real number (default: 0.8) between 0 and 1 giving the opacity of
     4903          the front facets.
     4904        - ``axis`` - Boolean (default: False) draw the axes at the origin or not.
    49004905
    49014906        OUTPUT:
    49024907
    4903         - ``tikz_pic`` -- a string containing the raw text of a TikZ picture.
     4908        - LatexExpr -- containing the TikZ picture.
    49044909
    49054910        .. NOTE::
    49064911
    4907             The inputs ``view`` and ``rot_angle`` can be obtained from the viewer
     4912            The inputs ``view`` and ``angle`` can be obtained from the viewer
    49084913            Jmol:
    49094914
    49104915            1) Right click on the image;
    4911             2) Select ``Console`;
    4912             3) Select the tab ``State`;
     4916            2) Select ``Console``;
     4917            3) Select the tab ``State``;
    49134918            4) Scroll to the line ``moveto``
    49144919
    4915             It read something like:
     4920            It read something like::
    49164921
    49174922            moveto 0.0 {x y z angle} Scale
    49184923
    4919             The ``view`` is then [x,y,z] and ``rot_angle`` is angle.
     4924            The ``view`` is then [x,y,z] and ``angle`` is angle.
    49204925            The following number is the scale.
     4926            Jmol performs a rotation of ``angle`` degrees along the vector [x,y,z] and show
     4927            the result from the z-axis.
    49214928
    49224929        EXAMPLES::
    49234930
    49244931            sage: P1 = polytopes.small_rhombicuboctahedron()
    49254932            sage: Image1 = P1.tikz([1,3,5], 175, scale=4)
    4926             sage: open('polytope-tikz.tex', 'w').write(Image1)
     4933            sage: type(Image1)
     4934            <class 'sage.misc.latex.LatexExpr'>
     4935            sage: print '\n'.join(Image1.splitlines()[:4])
     4936            \begin{tikzpicture}%
     4937                [x={(-0.939161cm, 0.244762cm)},
     4938                y={(0.097442cm, -0.482887cm)},
     4939                z={(0.329367cm, 0.840780cm)},
     4940            sage: open('polytope-tikz1.tex', 'w').write(Image1)    # not tested
    49274941
    49284942            sage: P2 = Polyhedron(vertices=[[1, 1],[1, 2],[2, 1]])
    49294943            sage: Image2 = P2.tikz(scale=3, edge_color='blue!95!black', facet_color='orange!95!black', opacity=0.4, vertex_color='yellow', axis=True)
    4930             sage: open('polytope-tikz2.tex', 'w').write(Image2)
     4944            sage: type(Image1)
     4945            <class 'sage.misc.latex.LatexExpr'>
     4946            sage: print '\n'.join(Image2.splitlines()[:4])
     4947            \begin{tikzpicture}%
     4948                [scale=3.000000,
     4949                back/.style={loosely dotted, thin},
     4950                edge/.style={color=blue!95!black, thick},
     4951            sage: open('polytope-tikz2.tex', 'w').write(Image2)    # not tested
    49314952
    49324953            sage: P3 = Polyhedron(vertices=[[-1, -1, 2],[-1, 2, -1],[2, -1, -1]])
    49334954            sage: P3
    49344955            A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 3 vertices.
    4935             sage: Image3 = P3.tikz([0.5,-1,-0.1], 55, scale=3, edge_color='blue!95!black', facet_color='orange!95!black', opacity=0.7, vertex_color='yellow', axis=True)
    4936             sage: open('polytope-tikz3.tex', 'w').write(Image3)
     4956            sage: Image3 = P3.tikz([0.5,-1,-0.1], 55, scale=3, edge_color='blue!95!black',facet_color='orange!95!black', opacity=0.7, vertex_color='yellow', axis=True)
     4957            sage: print '\n'.join(Image3.splitlines()[:4])
     4958            \begin{tikzpicture}%
     4959                [x={(0.658184cm, -0.242192cm)},
     4960                y={(-0.096240cm, 0.912008cm)},
     4961                z={(-0.746680cm, -0.331036cm)},
     4962            sage: open('polytope-tikz3.tex', 'w').write(Image3)    # not tested
    49374963
    49384964            sage: P=Polyhedron(vertices=[[1,1,0,0],[1,2,0,0],[2,1,0,0],[0,0,1,0],[0,0,0,1]])
    49394965            sage: P
     
    49434969            ...
    49444970            NotImplementedError: The polytope has to live in 2 or 3 dimensions.
    49454971
    4946 
    49474972        .. TO DO::
    49484973
    49494974            Make it possible to draw Schlegel diagram for 4-polytope.
     
    49654990            return self._tikz_2d(scale, edge_color, facet_color, opacity,
    49664991                                 vertex_color, axis)
    49674992        elif self.dim() == 2:
    4968             return self._tikz_2d_in_3d(view, rot_angle, scale, edge_color,
     4993            return self._tikz_2d_in_3d(view, angle, scale, edge_color,
    49694994                                       facet_color, opacity, vertex_color, axis)
    49704995        else:
    4971             return self._tikz_3d_in_3d(view, rot_angle, scale, edge_color,
     4996            return self._tikz_3d_in_3d(view, angle, scale, edge_color,
    49724997                                       facet_color, opacity, vertex_color, axis)
    49734998
    49744999    def _tikz_2d(self, scale, edge_color, facet_color, opacity, vertex_color, axis):
     
    49775002
    49785003        INPUT:
    49795004
    4980         - ``scale`` -- an integer specifying the scaling of the tikz picture;
    4981         - ``edge_color``, ``facet_color``, ``vertex_color`` -- string representing
    4982           colors which tikz recognize;
    4983         - ``opacity`` -- a real number between 0 and 1 giving the opacity of
    4984           the front facets;
    4985         - ``axis`` -- a Boolean, to draw the axes at the origin.
     5005        - ``scale`` - integer specifying the scaling of the tikz picture.
     5006        - ``edge_color`` - string representing colors which tikz
     5007          recognize.
     5008        - ``facet_color`` - string representing colors which tikz
     5009          recognize.
     5010        - ``vertex_color`` - string representing colors which tikz
     5011          recognize.
     5012        - ``opacity`` - real number between 0 and 1 giving the opacity of
     5013          the front facets.
     5014        - ``axis`` - Boolean (default: False) draw the axes at the origin or not.
     5015
     5016        OUTPUT:
     5017
     5018        - LatexExpr -- containing the TikZ picture.
     5019
     5020        EXAMPLES::
     5021
     5022            sage: P = Polyhedron(vertices=[[1, 1],[1, 2],[2, 1]])
     5023            sage: Image = P._tikz_2d(scale=3, edge_color='black', facet_color='orange', opacity=0.75, vertex_color='yellow', axis=True)
     5024            sage: type(Image)
     5025            <class 'sage.misc.latex.LatexExpr'>
     5026            sage: print '\n'.join(Image.splitlines()[:4])
     5027            \begin{tikzpicture}%
     5028                [scale=3.000000,
     5029                back/.style={loosely dotted, thin},
     5030                edge/.style={color=black, thick},
     5031            sage: open('polytope-tikz2.tex', 'w').write(Image2)    # not tested
    49865032
    49875033        .. NOTE::
    49885034
     
    50185064        tikz_pic += '\tedge/.style={color=%s, thick},\n' %edge_color
    50195065        tikz_pic += '\tfacet/.style={fill=%s,fill opacity=%f},\n' %(facet_color,opacity)
    50205066        tikz_pic += '\tvertex/.style={inner sep=1pt,circle,draw=%s!25!black,' %vertex_color
    5021         tikz_pic += 'fill=%s!75!black,thick,anchor=base}]\n\n\n' %vertex_color
     5067        tikz_pic += 'fill=%s!75!black,thick,anchor=base}]\n%%\n%%\n' %vertex_color
    50225068
    50235069        # Draws the axes if True
    50245070        if axis:
     
    50265072            tikz_pic += '\\draw[color=black,thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};\n'
    50275073
    50285074        # Create the coordinate of the vertices:
    5029         tikz_pic += '%% Coordinate of the vertices:\n\n'
     5075        tikz_pic += '%% Coordinate of the vertices:\n%%\n'
    50305076        for v in self.Vrep_generator():
    50315077            tikz_pic += dict_drawing[v][1]
    50325078
    50335079        # Draw the interior by going in a cycle
    5034         tikz_pic += '\n\n%% Drawing the interior\n\n'
     5080        tikz_pic += '%%\n%%\n%% Drawing the interior\n%%\n'
    50355081        cyclic_vert = cyclic_sort_vertices_2d(list(self.Vrep_generator()))
    50365082        tikz_pic += '\\fill[facet] '
    50375083        for v in cyclic_vert:
     
    50395085        tikz_pic += 'cycle {};\n'
    50405086
    50415087        # Draw the edges in the front
    5042         tikz_pic += '\n\n%% Drawing edges in the front\n\n'
     5088        tikz_pic += '%%\n%%\n%% Drawing edges in the front\n%%\n'
    50435089        tikz_pic += edges
    50445090
    50455091        # Finally, the vertices in front are drawn on top of everything.
    5046         tikz_pic += '\n\n%% Drawing the vertices in the front\n\n'
     5092        tikz_pic += '%%\n%%\n%% Drawing the vertices in the front\n%%\n'
    50475093        for v in self.Vrep_generator():
    50485094            tikz_pic += dict_drawing[v][0]
    5049         tikz_pic += '\n\n\\end{tikzpicture}'
    5050 
    5051         return tikz_pic
    5052 
    5053     def _tikz_2d_in_3d(self, view, rot_angle, scale, edge_color, facet_color,
     5095        tikz_pic += '%%\n%%\n\\end{tikzpicture}'
     5096
     5097        return LatexExpr(tikz_pic)
     5098
     5099    def _tikz_2d_in_3d(self, view, angle, scale, edge_color, facet_color,
    50545100                       opacity, vertex_color, axis):
    50555101        """
    50565102        Return a string ``tikz_pic`` consisting of a tikz picture of ``self``
    5057         according to a projection ``view`` and an angle ``rot_angle``
     5103        according to a projection ``view`` and an angle ``angle``
    50585104        obtained via Jmol through the current state property.
    50595105
    50605106        INPUT:
    50615107
    5062         - ``view`` -- a list of length 3 representing a vector;
    5063         - ``rot_angle`` -- an angle in degree from 0 to 360 (rotation along the view);
    5064         - ``scale`` -- an integer specifying the scaling of the tikz picture;
    5065         - ``edge_color``, ``facet_color``, ``vertex_color`` -- string
    5066           representing colors which tikz recognize;
    5067         - ``opacity`` -- a real number between 0 and 1 giving the opacity of
    5068           the front facets;
    5069         - ``axis`` -- a Boolean, to draw the axes at the origin.
     5108        - ``view`` - list (default: [0,0,1]) representing the rotation axis.
     5109        - ``angle`` - integer angle of rotation in degree from 0 to 360.
     5110        - ``scale`` - integer specifying the scaling of the tikz picture.
     5111        - ``edge_color`` - string representing colors which tikz
     5112          recognize.
     5113        - ``facet_color`` - string representing colors which tikz
     5114          recognize.
     5115        - ``vertex_color`` - string representing colors which tikz
     5116          recognize.
     5117        - ``opacity`` - real number between 0 and 1 giving the opacity of
     5118          the front facets.
     5119        - ``axis`` - Boolean draw the axes at the origin or not.
     5120
     5121        OUTPUT:
     5122
     5123        - LatexExpr -- containing the TikZ picture.
     5124
     5125        EXAMPLE::
     5126
     5127            sage: P = Polyhedron(vertices=[[-1, -1, 2],[-1, 2, -1],[2, -1, -1]])
     5128            sage: P
     5129            A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 3 vertices.
     5130            sage: Image = P._tikz_2d_in_3d(view=[0.5,-1,-0.5], angle=55, scale=3, edge_color='blue!95!black', facet_color='orange', opacity=0.5, vertex_color='yellow', axis=True)
     5131            sage: print '\n'.join(Image.splitlines()[:4])
     5132            \begin{tikzpicture}%
     5133                [x={(0.644647cm, -0.476559cm)},
     5134                y={(0.192276cm, 0.857859cm)},
     5135                z={(-0.739905cm, -0.192276cm)},
     5136            sage: open('polytope-tikz3.tex', 'w').write(Image3)    # not tested
    50705137
    50715138        .. NOTE::
    50725139
     
    50745141
    50755142        """
    50765143
    5077         V = VectorSpace(RDF,3)
    5078         view_vector = V(view)
    5079         rot = rotate_arbitrary(view_vector,-(rot_angle/360)*2*pi)
     5144        view_vector = vector(RDF, view)
     5145        rot = rotate_arbitrary(view_vector,-(angle/360)*2*pi)
    50805146        rotation_matrix = rot[:2].transpose()
    50815147
    50825148        # Creates the nodes, coordinate and tag for every vertex of the polytope.
     
    51035169        # Start to write the output
    51045170        tikz_pic = ''
    51055171        tikz_pic += '\\begin{tikzpicture}%\n'
    5106         tikz_pic += '\t[x={(%fcm, %fcm)},\n' %(n(rotation_matrix[0][0]),n(rotation_matrix[0][1]))
    5107         tikz_pic += '\ty={(%fcm, %fcm)},\n' %(n(rotation_matrix[1][0]),n(rotation_matrix[1][1]))
    5108         tikz_pic += '\tz={(%fcm, %fcm)},\n' %(n(rotation_matrix[2][0]),n(rotation_matrix[2][1]))
     5172        tikz_pic += '\t[x={(%fcm, %fcm)},\n' %(RDF(rotation_matrix[0][0]),RDF(rotation_matrix[0][1]))
     5173        tikz_pic += '\ty={(%fcm, %fcm)},\n' %(RDF(rotation_matrix[1][0]),RDF(rotation_matrix[1][1]))
     5174        tikz_pic += '\tz={(%fcm, %fcm)},\n' %(RDF(rotation_matrix[2][0]),RDF(rotation_matrix[2][1]))
    51095175        tikz_pic += '\tscale=%f,\n' %scale
    51105176        tikz_pic += '\tback/.style={loosely dotted, thin},\n'
    51115177        tikz_pic += '\tedge/.style={color=%s, thick},\n' %edge_color
    51125178        tikz_pic += '\tfacet/.style={fill=%s,fill opacity=%f},\n' %(facet_color,opacity)
    51135179        tikz_pic += '\tvertex/.style={inner sep=1pt,circle,draw=%s!25!black,' %vertex_color
    5114         tikz_pic += 'fill=%s!75!black,thick,anchor=base}]\n\n\n' %vertex_color
     5180        tikz_pic += 'fill=%s!75!black,thick,anchor=base}]\n%%\n%%\n' %vertex_color
    51155181
    51165182        # Draws the axes if True
    51175183        if axis:
     
    51205186            tikz_pic += '\\draw[color=black,thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};\n'
    51215187
    51225188        # Create the coordinate of the vertices:
    5123         tikz_pic += '%% Coordinate of the vertices:\n\n'
     5189        tikz_pic += '%% Coordinate of the vertices:\n%%\n'
    51245190        for v in self.Vrep_generator():
    51255191            tikz_pic += dict_drawing[v][1]
    51265192
    51275193        # Draw the interior by going in a cycle
    5128         tikz_pic += '\n\n%% Drawing the interior\n\n'
     5194        tikz_pic += '%%\n%%\n%% Drawing the interior\n%%\n'
    51295195        cyclic_vert = cyclic_sort_vertices_2d(list(self.Vrep_generator()))
    51305196        tikz_pic += '\\fill[facet] '
    51315197        for v in cyclic_vert:
     
    51335199        tikz_pic += 'cycle {};\n'
    51345200
    51355201        # Draw the edges in the front
    5136         tikz_pic += '\n\n%% Drawing edges in the front\n\n'
     5202        tikz_pic += '%%\n%%\n%% Drawing edges in the front\n%%\n'
    51375203        tikz_pic += edges
    51385204
    51395205        # Finally, the vertices in front are drawn on top of everything.
    5140         tikz_pic += '\n\n%% Drawing the vertices in the front\n\n'
     5206        tikz_pic += '%%\n%%\n%% Drawing the vertices in the front\n%%\n'
    51415207        for v in self.Vrep_generator():
    51425208            tikz_pic += dict_drawing[v][0]
    5143         tikz_pic += '\n\n\\end{tikzpicture}'
    5144 
    5145         return tikz_pic
    5146 
    5147     def _tikz_3d_in_3d(self, view, rot_angle, scale, edge_color,
     5209        tikz_pic += '%%\n%%\n\\end{tikzpicture}'
     5210
     5211        return LatexExpr(tikz_pic)
     5212
     5213    def _tikz_3d_in_3d(self, view, angle, scale, edge_color,
    51485214                       facet_color, opacity, vertex_color, axis):
    51495215        """
    51505216        Return a string ``tikz_pic`` consisting of a tikz picture of ``self``
    5151         according to a projection ``view`` and an angle ``rot_angle``
     5217        according to a projection ``view`` and an angle ``angle``
    51525218        obtained via Jmol through the current state property.
    51535219
    51545220        INPUT:
    51555221
    5156         - ``view`` -- a list of length 3 representing a vector;
    5157         - ``rot_angle`` -- an angle in degree from 0 to 360;
    5158         - ``scale`` -- an integer specifying the scaling of the tikz picture;
    5159         - ``edge_color``, ``facet_color``, ``vertex_color`` -- string
    5160           representing colors which tikz recognize;
    5161         - ``opacity`` -- a real number between 0 and 1 giving the opacity of
    5162           the front facets;
    5163         - ``axis`` -- a Boolean, to draw the axes at the origin.
    5164 
    5165         """
    5166         V = VectorSpace(RDF,3)
    5167         view_vector = V(view)
    5168         rot = rotate_arbitrary(view_vector,-(rot_angle/360)*2*pi)
     5222        - ``view`` - list (default: [0,0,1]) representing the rotation axis.
     5223        - ``angle`` - integer angle of rotation in degree from 0 to 360.
     5224        - ``scale`` - integer specifying the scaling of the tikz picture.
     5225        - ``edge_color`` - string representing colors which tikz
     5226          recognize.
     5227        - ``facet_color`` - string representing colors which tikz
     5228          recognize.
     5229        - ``vertex_color`` - string representing colors which tikz
     5230          recognize.
     5231        - ``opacity`` - real number between 0 and 1 giving the opacity of
     5232          the front facets.
     5233        - ``axis`` - Boolean draw the axes at the origin or not.
     5234
     5235        OUTPUT:
     5236
     5237        - LatexExpr -- containing the TikZ picture.
     5238
     5239        EXAMPLES::
     5240
     5241            sage: P = polytopes.small_rhombicuboctahedron()
     5242            sage: Image = P._tikz_3d_in_3d([3,7,5], 100, scale=3, edge_color='blue', facet_color='orange', opacity=0.5, vertex_color='green', axis=True)
     5243            sage: type(Image)
     5244            <class 'sage.misc.latex.LatexExpr'>
     5245            sage: print '\n'.join(Image.splitlines()[:4])
     5246            \begin{tikzpicture}%
     5247                [x={(-0.046385cm, 0.837431cm)},
     5248                y={(-0.243536cm, 0.519228cm)},
     5249                z={(0.968782cm, 0.170622cm)},
     5250            sage: open('polytope-tikz1.tex', 'w').write(Image1)    # not tested
     5251
     5252        """
     5253
     5254        view_vector = vector(RDF, view)
     5255        rot = rotate_arbitrary(view_vector,-(angle/360)*2*pi)
    51695256        rotation_matrix = rot[:2].transpose()
    5170         proj_vector = (rot**(-1))*V([0,0,1])
     5257        proj_vector = (rot**(-1))*vector(RDF, [0,0,1])
    51715258
    51725259        # First compute the back and front vertices and facets
    51735260        front_facets = []
     
    52285315        # Start to write the output
    52295316        tikz_pic = ''
    52305317        tikz_pic += '\\begin{tikzpicture}%\n'
    5231         tikz_pic += '\t[x={(%fcm, %fcm)},\n' %(n(rotation_matrix[0][0]),n(rotation_matrix[0][1]))
    5232         tikz_pic += '\ty={(%fcm, %fcm)},\n' %(n(rotation_matrix[1][0]),n(rotation_matrix[1][1]))
    5233         tikz_pic += '\tz={(%fcm, %fcm)},\n' %(n(rotation_matrix[2][0]),n(rotation_matrix[2][1]))
     5318        tikz_pic += '\t[x={(%fcm, %fcm)},\n' %(RDF(rotation_matrix[0][0]),RDF(rotation_matrix[0][1]))
     5319        tikz_pic += '\ty={(%fcm, %fcm)},\n' %(RDF(rotation_matrix[1][0]),RDF(rotation_matrix[1][1]))
     5320        tikz_pic += '\tz={(%fcm, %fcm)},\n' %(RDF(rotation_matrix[2][0]),RDF(rotation_matrix[2][1]))
    52345321        tikz_pic += '\tscale=%f,\n' %scale
    52355322        tikz_pic += '\tback/.style={loosely dotted, thin},\n'
    52365323        tikz_pic += '\tedge/.style={color=%s, thick},\n' %edge_color
    52375324        tikz_pic += '\tfacet/.style={fill=%s,fill opacity=%f},\n' %(facet_color,opacity)
    52385325        tikz_pic += '\tvertex/.style={inner sep=1pt,circle,draw=%s!25!black,' %vertex_color
    5239         tikz_pic += 'fill=%s!75!black,thick,anchor=base}]\n\n\n' %vertex_color
     5326        tikz_pic += 'fill=%s!75!black,thick,anchor=base}]\n%%\n%%\n' %vertex_color
    52405327
    52415328        # Draws the axes if True
    52425329        if axis:
     
    52455332            tikz_pic += '\\draw[color=black,thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};\n'
    52465333
    52475334        # Create the coordinate of the vertices
    5248         tikz_pic += '%% Coordinate of the vertices:\n\n'
     5335        tikz_pic += '%% Coordinate of the vertices:\n%%\n'
    52495336        for v in self.Vrep_generator():
    52505337            tikz_pic += dict_drawing[v][1]
    52515338
    52525339        # Draw the edges in the back
    5253         tikz_pic += '\n\n%% Drawing edges in the back\n\n'
     5340        tikz_pic += '%%\n%%\n%% Drawing edges in the back\n%%\n'
    52545341        tikz_pic += first_part
    52555342
    52565343        # Draw the vertices on top of the back-edges
    5257         tikz_pic += '\n\n%% Drawing vertices in the back\n\n'
     5344        tikz_pic += '%%\n%%\n%% Drawing vertices in the back\n%%\n'
    52585345        for v in self.Vrep_generator():
    52595346            if v in back_vertices and v not in front_vertices:
    52605347                tikz_pic += dict_drawing[v][0]
    52615348
    52625349        # Draw the facets in the front by going in cycles for every facet.
    5263         tikz_pic += '\n\n%% Drawing the facets\n\n'
     5350        tikz_pic += '%%\n%%\n%% Drawing the facets\n%%\n'
    52645351        for facet in front_facets:
    52655352            cyclic_vert = cyclic_sort_vertices_2d(list(facet.incident()))
    52665353            tikz_pic += '\\fill[facet] '
     
    52695356            tikz_pic += 'cycle {};\n'
    52705357
    52715358        # Draw the edges in the front
    5272         tikz_pic += '\n\n%% Drawing edges in the front\n\n'
     5359        tikz_pic += '%%\n%%\n%% Drawing edges in the front\n%%\n'
    52735360        tikz_pic += second_part
    52745361
    52755362        # Finally, the vertices in front are drawn on top of everything.
    5276         tikz_pic += '\n\n%% Drawing the vertices in the front\n\n'
     5363        tikz_pic += '%%\n%%\n%% Drawing the vertices in the front\n%%\n'
    52775364        for v in self.Vrep_generator():
    52785365            if v in front_vertices:
    52795366                tikz_pic += dict_drawing[v][0]
    5280         tikz_pic += '\n\n\\end{tikzpicture}'
    5281 
    5282         return tikz_pic
     5367        tikz_pic += '%%\n%%\n\\end{tikzpicture}'
     5368
     5369        return LatexExpr(tikz_pic)
    52835370
    52845371#############################################################
    52855372def cyclic_sort_vertices_2d(Vlist):