def _latex_(self, scale=0.5): r""" Return a latex representation of this Dynkin diagram EXAMPLES:: sage: latex(DynkinDiagram(['A',3,1])) \begin{tikzpicture}[scale=0.5] \draw (-1,0) node[anchor=east] {$A_{3}^{(1)}$}; \draw (0 cm,0) -- (4 cm,0); \draw (0 cm,0) -- (2.0 cm, 1.2 cm); \draw (2.0 cm, 1.2 cm) -- (4 cm, 0); \draw[fill=white] (0 cm, 0 cm) circle (.25cm) node[below=4pt]{$1$}; \draw[fill=white] (2 cm, 0 cm) circle (.25cm) node[below=4pt]{$2$}; \draw[fill=white] (4 cm, 0 cm) circle (.25cm) node[below=4pt]{$3$}; \draw[fill=white] (2.0 cm, 1.2 cm) circle (.25cm) node[anchor=south east]{$0$}; \end{tikzpicture} """ if self.cartan_type() is None: return "Dynkin diagram of rank {}".format(self.rank()) from sage.graphs.graph_latex import setup_latex_preamble setup_latex_preamble() ret = "\\begin{{tikzpicture}}[scale={}]\n".format(scale) ret += "\\draw (-1,0) node[anchor=east] {{${}$}};\n".format(self.cartan_type()._latex_()) ret += self.cartan_type()._latex_dynkin_diagram() ret += "\\end{tikzpicture}" return ret
def _latex_(self, show_box=False, colors=["white", "lightgray", "darkgray"]): r""" Return latex code for ``self``, which uses TikZ package to draw the plane partition. INPUT: - ``show_box`` -- boolean (default: ``False``); if ``True``, also shows the visible tiles on the `xy`-, `yz`-, `zx`-planes - ``colors`` -- (default: ``["white", "lightgray", "darkgray"]``) list ``[A, B, C]`` of 3 strings representing colors OUTPUT: Latex code for drawing the plane partition. EXAMPLES:: sage: PP = PlanePartition([[1]]) sage: latex(PP) \begin{tikzpicture} \draw[fill=white,shift={(210:0)},shift={(-30:0)},shift={(90:1)}] (0,0)--(-30:1)--(0,-1)--(210:1)--(0,0); \draw[fill=darkgray,shift={(210:0)},shift={(-30:1)},shift={(90:0)}] (0,0)--(210:1)--(150:1)--(0,1)--(0,0); \draw[fill=lightgray,shift={(210:1)},shift={(-30:0)},shift={(90:0)}] (0,0)--(0,1)--(30:1)--(-30:1)--(0,0); \end{tikzpicture} """ from sage.graphs.graph_latex import setup_latex_preamble setup_latex_preamble() ret = "\\begin{tikzpicture}\n" def add_topside(i, j, k): return "\\draw[fill={},shift={{(210:{})}},shift={{(-30:{})}},shift={{(90:{})}}]\n(0,0)--(-30:1)--(0,-1)--(210:1)--(0,0);\n".format( colors[0], i, j, k) def add_leftside(j, k, i): return "\\draw[fill={},shift={{(210:{})}},shift={{(-30:{})}},shift={{(90:{})}}]\n(0,0)--(0,1)--(30:1)--(-30:1)--(0,0);\n".format( colors[1], i, j, k) def add_rightside(k, i, j): return "\\draw[fill={},shift={{(210:{})}},shift={{(-30:{})}},shift={{(90:{})}}]\n(0,0)--(210:1)--(150:1)--(0,1)--(0,0);\n".format( colors[2], i, j, k) funcs = [add_topside, add_rightside, add_leftside] tableaux = [self.z_tableau(), self.y_tableau(), self.x_tableau()] for i in range(3): f = funcs[i] tab = tableaux[i] for r in range(len(tab)): for c in range(len(tab[r])): if tab[r][c] > 0 or show_box: ret += f(r, c, tab[r][c]) return ret + "\\end{tikzpicture}"
def _latex_(self, show_box=False, colors=["white","lightgray","darkgray"]): r""" Return latex code for ``self``, which uses TikZ package to draw the plane partition. INPUT: - ``show_box`` -- boolean (default: ``False``); if ``True``, also shows the visible tiles on the `xy`-, `yz`-, `zx`-planes - ``colors`` -- (default: ``["white", "lightgray", "darkgray"]``) list ``[A, B, C]`` of 3 strings representing colors OUTPUT: Latex code for drawing the plane partition. EXAMPLES:: sage: PP = PlanePartition([[1]]) sage: latex(PP) \begin{tikzpicture} \draw[fill=white,shift={(210:0)},shift={(-30:0)},shift={(90:1)}] (0,0)--(-30:1)--(0,-1)--(210:1)--(0,0); \draw[fill=darkgray,shift={(210:0)},shift={(-30:1)},shift={(90:0)}] (0,0)--(210:1)--(150:1)--(0,1)--(0,0); \draw[fill=lightgray,shift={(210:1)},shift={(-30:0)},shift={(90:0)}] (0,0)--(0,1)--(30:1)--(-30:1)--(0,0); \end{tikzpicture} """ from sage.graphs.graph_latex import setup_latex_preamble setup_latex_preamble() x = self._max_x y = self._max_y z = self._max_z ret = "\\begin{tikzpicture}\n" def add_topside(i,j,k): return "\\draw[fill={},shift={{(210:{})}},shift={{(-30:{})}},shift={{(90:{})}}]\n(0,0)--(-30:1)--(0,-1)--(210:1)--(0,0);\n".format(colors[0],i,j,k) def add_leftside(j,k,i): return "\\draw[fill={},shift={{(210:{})}},shift={{(-30:{})}},shift={{(90:{})}}]\n(0,0)--(0,1)--(30:1)--(-30:1)--(0,0);\n".format(colors[1],i,j,k) def add_rightside(k,i,j): return "\\draw[fill={},shift={{(210:{})}},shift={{(-30:{})}},shift={{(90:{})}}]\n(0,0)--(210:1)--(150:1)--(0,1)--(0,0);\n".format(colors[2],i,j,k) funcs = [add_topside, add_rightside, add_leftside] tableaux = [self.z_tableau(), self.y_tableau(), self.x_tableau()] for i in range(3): f = funcs[i] tab = tableaux[i] for r in range(len(tab)): for c in range(len(tab[r])): if tab[r][c] > 0 or show_box: ret += f(r, c, tab[r][c]) return ret + "\\end{tikzpicture}"
def _latex_(self): r""" Return a latex representation of ``self``. EXAMPLES:: sage: MV = crystals.infinity.MVPolytopes(['C', 2]) sage: b = MV.module_generators[0].f_string([1,2,1,2]) sage: latex(b) \begin{tikzpicture} \draw (0, 0) -- (-1, 1) -- (-1, 1) -- (-2, 0) -- (-2, -2); \draw (0, 0) -- (0, -2) -- (-1, -3) -- (-1, -3) -- (-2, -2); \draw[fill=black] (0, 0) circle (0.1); \draw[fill=black] (-2, -2) circle (0.1); \end{tikzpicture} sage: MV = crystals.infinity.MVPolytopes(['D',4]) sage: b = MV.module_generators[0].f_string([1,2,1,2]) sage: latex(b) \text{\texttt{MV{ }polytope{ }...}} TESTS:: sage: MV = crystals.infinity.MVPolytopes(['A',2]) sage: u = MV.highest_weight_vector() sage: b = u.f_string([1,2,2,1]) sage: latex(b) \begin{tikzpicture} \draw (0, 0) -- (3/2, -989/1142) -- (3/2, -2967/1142) -- (0, -1978/571); \draw (0, 0) -- (-3/2, -989/1142) -- (-3/2, -2967/1142) -- (0, -1978/571); \draw[fill=black] (0, 0) circle (0.1); \draw[fill=black] (0, -1978/571) circle (0.1); \end{tikzpicture} """ latex_options = self.parent()._latex_options P = latex_options['P'] plot_options = P.plot_parse_options( projection=latex_options["projection"]) proj = plot_options.projection if proj(P.zero()).parent().dimension() != 2: from sage.misc.latex import latex return latex(repr(self)) # We need this to use tikz from sage.graphs.graph_latex import setup_latex_preamble setup_latex_preamble() pbw_data = self._pbw_datum.parent W = pbw_data.weyl_group w0 = W.long_element() al = P.simple_roots() ret = "\\begin{tikzpicture}\n" final = None for red in w0.reduced_words(): ret += "\\draw " cur = proj(P.zero()) red = tuple(red) ret += str(cur) roots = [ proj(P.sum(c * al[a] for a, c in root)) for root in pbw_data._root_list_from(red) ] datum = pbw_data.convert_to_new_long_word(self._pbw_datum, red) for i in reversed(range(len(datum.lusztig_datum))): cur -= roots[i] * datum.lusztig_datum[i] ret += " -- " + str(cur) final = cur ret += ";\n" if latex_options["mark_endpoints"]: circle_size = latex_options["circle_size"] ret += "\\draw[fill=black] {} circle ({});\n".format( proj(P.zero()), circle_size) ret += "\\draw[fill=black] {} circle ({});\n".format( final, circle_size) ret += "\\end{tikzpicture}" return ret
def _latex_(self): r""" Return a latex representation of ``self``. EXAMPLES:: sage: MV = crystals.infinity.MVPolytopes(['C', 2]) sage: b = MV.module_generators[0].f_string([1,2,1,2]) sage: latex(b) \begin{tikzpicture} \draw (0, 0) -- (0, -2) -- (-1, -3) -- (-1, -3) -- (-2, -2); \draw (0, 0) -- (-1, 1) -- (-1, 1) -- (-2, 0) -- (-2, -2); \draw[fill=black] (0, 0) circle (0.1); \draw[fill=black] (-2, -2) circle (0.1); \end{tikzpicture} sage: MV = crystals.infinity.MVPolytopes(['D',4]) sage: b = MV.module_generators[0].f_string([1,2,1,2]) sage: latex(b) \text{\texttt{MV{ }polytope{ }...}} TESTS:: sage: MV = crystals.infinity.MVPolytopes(['A',2]) sage: u = MV.highest_weight_vector() sage: b = u.f_string([1,2,2,1]) sage: latex(b) \begin{tikzpicture} \draw (0, 0) -- (3/2, -989/1142) -- (3/2, -2967/1142) -- (0, -1978/571); \draw (0, 0) -- (-3/2, -989/1142) -- (-3/2, -2967/1142) -- (0, -1978/571); \draw[fill=black] (0, 0) circle (0.1); \draw[fill=black] (0, -1978/571) circle (0.1); \end{tikzpicture} """ latex_options = self.parent()._latex_options P = latex_options['P'] plot_options = P.plot_parse_options(projection=latex_options["projection"]) proj = plot_options.projection if proj(P.zero()).parent().dimension() != 2: from sage.misc.latex import latex return latex(repr(self)) # We need this to use tikz from sage.graphs.graph_latex import setup_latex_preamble setup_latex_preamble() pbw_data = self._pbw_datum.parent W = pbw_data.weyl_group w0 = W.long_element() al = P.simple_roots() ret = "\\begin{tikzpicture}\n" final = None for red in sorted(w0.reduced_words()): ret += "\\draw " cur = proj(P.zero()) red = tuple(red) ret += str(cur) roots = [proj(P.sum(c*al[a] for a,c in root)) for root in pbw_data._root_list_from(red)] datum = pbw_data.convert_to_new_long_word(self._pbw_datum, red) for i in reversed(range(len(datum.lusztig_datum))): cur -= roots[i] * datum.lusztig_datum[i] ret += " -- " + str(cur) final = cur ret += ";\n" if latex_options["mark_endpoints"]: circle_size = latex_options["circle_size"] ret += "\\draw[fill=black] {} circle ({});\n".format(proj(P.zero()), circle_size) ret += "\\draw[fill=black] {} circle ({});\n".format(final, circle_size) ret += "\\end{tikzpicture}" return ret
def latex_state_evolution(self, num, scale=1): r""" Return a latex version of the evolution process of the state ``num``. .. SEEALSO:: :meth:`state_evolution`, :meth:`print_state_evolution` EXAMPLES:: sage: B = SolitonCellularAutomata('113123', 3) sage: B.evolve(3) sage: B.latex_state_evolution(0) \begin{tikzpicture}[scale=1] \node (i0) at (0,0.9) {$1$}; \node (i1) at (-2,0.9) {$1$}; \node (i2) at (-4,0.9) {$3$}; \node (i3) at (-6,0.9) {$1$}; \node (i4) at (-8,0.9) {$2$}; \node (i5) at (-10,0.9) {$3$}; \node (t0) at (0,-1) {$1$}; \node (t1) at (-2,-1) {$3$}; \node (t2) at (-4,-1) {$2$}; \node (t3) at (-6,-1) {$3$}; \node (t4) at (-8,-1) {$1$}; \node (t5) at (-10,-1) {$1$}; \node (u0) at (1,0) {$111$}; \node (u1) at (-1,0) {$111$}; \node (u2) at (-3,0) {$113$}; \node (u3) at (-5,0) {$112$}; \node (u4) at (-7,0) {$123$}; \node (u5) at (-9,0) {$113$}; \node (u6) at (-11,0) {$111$}; \draw[->] (i0) -- (t0); \draw[->] (u0) -- (u1); \draw[->] (i1) -- (t1); \draw[->] (u1) -- (u2); \draw[->] (i2) -- (t2); \draw[->] (u2) -- (u3); \draw[->] (i3) -- (t3); \draw[->] (u3) -- (u4); \draw[->] (i4) -- (t4); \draw[->] (u4) -- (u5); \draw[->] (i5) -- (t5); \draw[->] (u5) -- (u6); \end{tikzpicture} sage: B.latex_state_evolution(1) \begin{tikzpicture}[scale=1] ... \end{tikzpicture} """ from sage.graphs.graph_latex import setup_latex_preamble from sage.misc.latex import latex, LatexExpr setup_latex_preamble() u = self.state_evolution(num) # Also evolves as necessary final = self._states[num + 1] vacuum = self._vacuum_elt initial = [vacuum] * (len(final) - len(self._states[num])) + list( self._states[num]) def simple_repr(x): return ''.join(repr(x).strip('[]').split(', ')) ret = '\\begin{{tikzpicture}}[scale={}]\n'.format(scale) for i, val in enumerate(initial): ret += '\\node (i{}) at ({},0.9) {{${}$}};\n'.format( i, -2 * i, simple_repr(val)) for i, val in enumerate(final): ret += '\\node (t{}) at ({},-1) {{${}$}};\n'.format( i, -2 * i, simple_repr(val)) for i, val in enumerate(u): ret += '\\node (u{}) at ({},0) {{${}$}};\n'.format( i, -2 * i + 1, simple_repr(val)) for i in range(len(initial)): ret += '\\draw[->] (i{}) -- (t{});\n'.format(i, i) ret += '\\draw[->] (u{}) -- (u{});\n'.format(i, i + 1) ret += '\\end{tikzpicture}' return LatexExpr(ret)