Skip to content

Commit

Permalink
sagemathgh-38764: Fix the latex representation of crystals tableaux
Browse files Browse the repository at this point in the history
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Fixes sagemath#38745

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [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.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->

sagemath#38339
    
URL: sagemath#38764
Reported by: Kwankyu Lee
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Oct 8, 2024
2 parents 0e3942d + 53f0371 commit 67ec665
Showing 1 changed file with 55 additions and 22 deletions.
77 changes: 55 additions & 22 deletions src/sage/graphs/graph_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,21 @@ def tkz_picture(self):
%
%
\end{tikzpicture}
For a complicated vertex, a TeX box is used. ::
sage: B = crystals.Tableaux(['B', 2], shape=[1])
sage: latex(B)
\begin{tikzpicture}
...
\newsavebox{\vertex}
\sbox{\vertex}{${\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}
\raisebox{-.6ex}{$\begin{array}[b]{*{1}c}\cline{1-1}
\lr{1}\\\cline{1-1}
\end{array}$}
}$}\Vertex[style={minimum size=1.0cm,draw=cv0,fill=cfv0,text=clv0,shape=circle},LabelOut=false,L=\usebox{\vertex},x=...,y=...]{v0}
...
\end{tikzpicture}
"""
# This routine does not handle multiple edges
# It will properly handle digraphs where a pair of vertices has an edge
Expand Down Expand Up @@ -1938,48 +1953,66 @@ def translate(p):
s += [str(round(el_color[edge][2], 4)), '}\n']
s += ['%\n']

# Create each vertex
# Create vertices
v = []
box = ''
used = False
for u in vertex_list:
s += ['\\Vertex[']
t = [r'\Vertex[']
# colors, shapes, sizes, labels/placement for 'Custom' style
if customized:
s += ['style={'] # begin style list
s += ['minimum size=', str(round(float(scale * v_size[u]), 4)),
t += ['style={'] # begin style list
t += ['minimum size=', str(round(float(scale * v_size[u]), 4)),
units, ',']
s += ['draw=', vertex_color_names[u], ',']
s += ['fill=', vertex_fill_color_names[u], ',']
t += ['draw=', vertex_color_names[u], ',']
t += ['fill=', vertex_fill_color_names[u], ',']
if vertex_labels:
s += ['text=', vertex_label_color_names[u], ',']
t += ['text=', vertex_label_color_names[u], ',']
if v_shape[u] == 'sphere':
s += ['shape=circle,shading=ball,line width=0pt,ball color=', vertex_color_names[u], ',']
t += ['shape=circle,shading=ball,line width=0pt,ball color=', vertex_color_names[u], ',']
else:
s += ['shape=', v_shape[u]]
s += ['},'] # end style list
t += ['shape=', v_shape[u]]
t += ['},'] # end style list
if vertex_labels:
if vl_placement[u] == 'center':
s += ['LabelOut=false,']
t += ['LabelOut=false,']
else:
s += ['LabelOut=true,']
s += ['Ldist=', str(round(float(scale * vl_placement[u][0]), 4)), units, ',']
s += ['Lpos=', str(round(float(vl_placement[u][1]), 4)), ','] # degrees, no units
t += ['LabelOut=true,']
t += ['Ldist=', str(round(float(scale * vl_placement[u][0]), 4)), units, ',']
t += ['Lpos=', str(round(float(vl_placement[u][1]), 4)), ','] # degrees, no units
else:
s += ['NoLabel,']
t += ['NoLabel,']
# vertex label information is available to all pre-built styles
# but may be ignored by the style, so not apparent
if vertex_labels or not customized:
if vertex_labels_math and not (isinstance(u, str) and u[0] == '$' and u[-1] == '$'):
lab = r'\hbox{$%s$}' % latex(u)
ltx = str(latex(u))
if '\\' in ltx: # complicated case; use \sbox
box = r'\sbox{\vertex}{$' + ltx + '$}'
lab = r'\usebox{\vertex}'
else:
lab = r'\hbox{$%s$}' % ltx
else:
lab = r'\hbox{%s}' % u
s += ['L=', lab, ',']
t += ['L=', lab, ',']
scaled_pos = translate(pos[u])
s += ['x=', str(round(float(scale * scaled_pos[0]), 4)), units, ',']
s += ['y=', str(round(float(scale * scaled_pos[1]), 4)), units]
s += [']']
s += ['{', prefix, str(index_of_vertex[u]), '}\n']
t += ['x=', str(round(float(scale * scaled_pos[0]), 4)), units, ',']
t += ['y=', str(round(float(scale * scaled_pos[1]), 4)), units]
t += [']']
t += ['{', prefix, str(index_of_vertex[u]), '}\n']
if box:
v += [box] + t
box = ''
used = True
else:
v += t
if used:
s += [r'\newsavebox{\vertex}' + '\n'] + v
else:
s += v
s += ['%\n']

# Create each edge or loop
# Create edges and loops
for e in self._graph.edges(sort=False):
edge = (e[0], e[1])
loop = e[0] == e[1]
Expand Down

0 comments on commit 67ec665

Please sign in to comment.