Skip to content

Conversation

seblabbe
Copy link
Contributor

@seblabbe seblabbe commented Oct 3, 2024

We add a tikz (or latex_standalone) method within combinat.crystals module in every class where a latex method is defined. When the string is a tikzpicture, we add a tikz method. When the string is a generic picture, we add a latex_standalone method.

Hopefully, it fixes #38745.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • 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

None.

The branch was written on top of old SageMath version 10.4.beta9, Release Date: 2024-06-09

Notes

While writing this branch, it made me realize that the latex code generated by the following two methods is broken:

x = crystals.infinity.GeneralizedYoungWalls(3)([[],[1,0,3,2],[2,1],[3,2,1,0,3,2],[],[],[2]])
x._latex_()
x.large_latex()

because the last draw command uses variable \t which is defined in the inner scope. I did not try to fix that issue here. This is why I added a "known bug" tag at two places.

Copy link

github-actions bot commented Oct 3, 2024

Documentation preview for this PR (built with commit c88ab90; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@anneschilling anneschilling mentioned this pull request Oct 5, 2024
2 tasks
@anneschilling
Copy link
Contributor

Hi Sebastien,

Thank you for your branch. I had to fold in your branch with #38339 since otherwise the view command does not work on my MacOS. However, when I then run

sage: B = crystals.Tableaux(['B',2],shape=[1])
sage: latex(B)
\begin{tikzpicture}[>=latex,line join=bevel,]
%%
\node (node_0) at (8.0bp,314.0bp) [draw,draw=none] {${\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}$}}$};
\node (node_1) at (8.0bp,238.0bp) [draw,draw=none] {${\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}\raisebox{-.6ex}{$\begin{array}[b]{
{1}c}\cline{1-1}\lr{2}\\cline{1-1}\end{array}$}}$};
\node (node_2) at (8.0bp,162.0bp) [draw,draw=none] {${\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}\raisebox{-.6ex}{$\begin{array}[b]{{1}c}\cline{1-1}\lr{0}\\cline{1-1}\end{array}$}}$};
\node (node_3) at (8.0bp,86.0bp) [draw,draw=none] {${\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}\raisebox{-.6ex}{$\begin{array}[b]{
{1}c}\cline{1-1}\lr{\overline{2}}\\cline{1-1}\end{array}$}}$};
\node (node_4) at (8.0bp,10.0bp) [draw,draw=none] {${\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}\raisebox{-.6ex}{$\begin{array}[b]{*{1}c}\cline{1-1}\lr{\overline{1}}\\cline{1-1}\end{array}$}}$};
\draw [blue,->] (node_0) ..controls (8.0bp,292.79bp) and (8.0bp,273.03bp) .. (node_1);
\definecolor{strokecol}{rgb}{0.0,0.0,0.0};
\pgfsetstrokecolor{strokecol}
\draw (17.0bp,276.0bp) node {$1$};
\draw [red,->] (node_1) ..controls (8.0bp,216.79bp) and (8.0bp,197.03bp) .. (node_2);
\draw (17.0bp,200.0bp) node {$2$};
\draw [red,->] (node_2) ..controls (8.0bp,140.79bp) and (8.0bp,121.03bp) .. (node_3);
\draw (17.0bp,124.0bp) node {$2$};
\draw [blue,->] (node_3) ..controls (8.0bp,64.789bp) and (8.0bp,45.027bp) .. (node_4);
\draw (17.0bp,48.0bp) node {$1$};
%
\end{tikzpicture}
sage: view(B)

I still get a cropped figure. Do I need to run another command?

Anne

…o 38759_tikz_crystals

* 'tikz_crystals_tableaux' of github.com:seblabbe/sage:
  border=1pt by default
  adding tikz or latex_standalone methods within crystals module
@seblabbe
Copy link
Contributor Author

seblabbe commented Oct 8, 2024

Yes, you need to run another command.

But your example made me realize that I forgot to add a method tikz inside of the categories/cristals.py file... I just did that after updating the version of Sage I am using to the most recent one. After the new commits, you should be able to do the following:

sage: T = crystals.Tableaux(['B',2], shape=[1])
sage: t = T.tikz(standalone_config=['border=1cm'])        # default is border=1pt
sage: t
\documentclass[tikz]{standalone}
\standaloneconfig{border=1cm}
\begin{document}
\begin{tikzpicture}[>=latex,line join=bevel,]
%%
\node (node_0) at (8.5bp,301.5bp) [draw,draw=none] {${\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}$}}$};
  \node (node_1) at (8.5bp,228.5bp) [draw,draw=none] {${\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}\raisebox{-.6ex}{$\begin{array}[b]{*{1}c}\cline{1-1}\lr{2}\\\cline{1-1}\end{array}$}}$};
  \node (node_2) at (8.5bp,155.5bp) [draw,draw=none] {${\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}\raisebox{-.6ex}{$\begin{array}[b]{*{1}c}\cline{1-1}\lr{0}\\\cline{1-1}\end{array}$}}$};
---
9 lines not printed (1827 characters in total).
Use print to see the full content.
---
  \draw (17.0bp,119.0bp) node {$2$};
  \draw [blue,->] (node_3) ..controls (8.5bp,61.978bp) and (8.5bp,43.649bp)  .. (node_4);
  \draw (17.0bp,46.0bp) node {$1$};
%
\end{tikzpicture}
\end{document}

Then, in the terminal, you can do:

sage: T.tikz().pdf(view=False)
'/tmp/tmphddbvpcl/tikz_0rzrm6r6.pdf' 
sage: T.tikz().pdf('myfile.pdf')    # providing the filename disables the view by default
'path/to/local/folder/myfile.pdf'
sage: T.tikz().pdf()   # this opens the file in a viewer, maybe there is something to fix here so that it also works on mac (?), for me on linux, it currently works great
'/tmp/tmphddbvpcl/tikz_0rzrm6r6.pdf' 

Also, in the Jupyter notebook, it is transparent. That is, the following just draw the picture below the input cell:

T = crystals.Tableaux(['B',2], shape=[1])
T.tikz()

crystal_jupyter1

Using TikzPicture.from_graph (declared experimental during review, because it should become a tikz method of graph at some point, I will do this during the next Sage Thursdays in Bordeaux), you may ask for the direction to go right:

crystals_jupyter2

I don't know if that is useful, but it is available.

@anneschilling
Copy link
Contributor

Thank you, Sebastien, for trying to address the issue described in #38745. However, the issue I have is that the view command (in general, not just for tableaux) with tightpage=True does not crop the picture correctly. It only shows a fraction of the picture.

@seblabbe
Copy link
Contributor Author

In fact, what I propose here does not fix view. It gives an alternative way to open the image in a viewer where you have more control on the output. For instance, when generating the tikzpicture object, you may increase the border to fix the cropping issue seen on a mac:

\documentclass[tikz]{standalone}
\standaloneconfig{border=1cm}
\begin{document}
\begin{tikzpicture}[>=latex,line join=bevel,]
...
\end{tikzpicture}
\end{document}

What you need to do is:

sage: T = crystals.Tableaux(['B',2], shape=[1])
sage: t = T.tikz(standalone_config=['border=1cm'])
sage: t.pdf()

or even, maybe the default border is fine (you can test?):

sage: T = crystals.Tableaux(['B',2], shape=[1])
sage: T.tikz().pdf()

@seblabbe
Copy link
Contributor Author

I removed the 2 'known bug' tags since these are now fixed in #39594

@seblabbe seblabbe requested a review from fchapoton February 28, 2025 14:30
@seblabbe
Copy link
Contributor Author

Note that since tikz method was recently added to graphs/digraphs, one may do the following without importing TikzPicture module:

image

vbraun pushed a commit to vbraun/sage that referenced this pull request Mar 9, 2025
sagemathgh-39594: fix latex code in one crystal file
    
and also notices a bug in the unicode art, fixed here.

The issue about latex was noticed in sagemath#38759

### 📝 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.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.
    
URL: sagemath#39594
Reported by: Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
vbraun pushed a commit to vbraun/sage that referenced this pull request Mar 9, 2025
sagemathgh-39594: fix latex code in one crystal file
    
and also notices a bug in the unicode art, fixed here.

The issue about latex was noticed in sagemath#38759

### 📝 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.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.
    
URL: sagemath#39594
Reported by: Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem with view on MacOS
3 participants