Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method tikz (or latex_standalone) within combinat.crystals module #38759

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

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 975f73d; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@anneschilling
Copy link

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

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()

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