1

One can use SAGE to get a LaTeX output for posets. For example entering

u=posets.BooleanLattice(4)

print(display(u),print(latex(u)))

in the sage cell (https://sagecell.sagemath.org/) will display the poset u and then give a TikZ output to obtain it in LaTeX.

Now in SAGE the points of a poset with n points are enumerated from 0 to n-1 instead of 1 to n.

Question: Is there an easy way to get the LaTeX output where the points are enumerated by 1 to n (by setting i->i+1 in the SAGE graphic)?

Of course one can do this by hand for a given example, but for big posets it would be better to have an automatic way of doing this (via SAGE?).

2 Answers 2

3

Using this page on poset documentation, you just need to use relabel() to change the vertices. SAGE takes care of the rest.

\documentclass{article}
\usepackage{sagetex}
\usepackage{tikz,tkz-graph,tkz-berge}
\begin{document}
\begin{sagesilent}
u=posets.BooleanLattice(4)
output = latex(u)

Q = u.relabel(lambda x: x+1)
output2 = latex(Q)
\end{sagesilent}
The original poset in SAGE is this:

\begin{center}
\sagestr{output}
\end{center}

After relabelling the vertices, it now looks like this:

\begin{center}
\sagestr{output2}
\end{center}
\end{document}

The output running in Cocalc is: enter image description here

3

I assume you compile the code output by latex(u) after doing u = posets.BooleanLattice(4) in Sage. In this case, you can use expsagetex to retrieve this LaTeX (actually, TikZ) code and store it in a macro (here: a tl variable). Then, it's a bit of a hack, but you can use l3regex to (sort of) replace every occurrence of L=\hbox{$〈number〉$} with L=\mbox{$〈number+1〉$} in the retrieved code:

% document.tex
\documentclass{article}
\usepackage{tikz}
\usepackage{tkz-graph}
\usepackage{xparse}
\usepackage{expsagetex}

\ExplSyntaxOn
\tl_new:N \l__mare_diagram_code_tl
\tl_new:N \l__mare_diagram_ID_tl

\NewDocumentCommand \myInsertDiagram { m }
  {
    \est_record_formatted:Nn \l__mare_diagram_ID_tl {#1}
    \est_refused:V \l__mare_diagram_ID_tl
    \tl_set:Nx \l__mare_diagram_code_tl
      { \est_get:Vnn \l__mare_diagram_ID_tl {??} { \emph{paused} } }
    \regex_replace_all:nnN { L\ *\=\ *\c{hbox} \cB\{ \cM\$ (\d+) \cM\$ \cE\} }
      { L\=\c{mbox} \cB\{ \cM\$ \c{int_eval:n} \cB\{ \1 + 1 \cE\} \cM\$ \cE\} }
      \l__mare_diagram_code_tl
    \tl_use:N \l__mare_diagram_code_tl
  }
\ExplSyntaxOff

\begin{document}

% The default output at scale=1 has many overlapping nodes
\tikzset{every picture/.append style={scale=2}}
\myInsertDiagram{posets.BooleanLattice(4)}

\end{document}

Run for instance pdflatex document.tex, then sage document.sagetex.sage, then again pdflatex document.tex and you'll obtain:

enter image description here

2
  • This isn't really a solution yet. In poset, the positioning of the vertices is important, as this Wikipedia entry explains. In the diagram you'll see: "Distinct sets on the same horizontal level are incomparable with each other."
    – DJP
    Commented Feb 18, 2020 at 16:37
  • @DJP Well, this layout is not the responsibility of my code. It is how tkz-graph formats the result of latex() called on the posets.BooleanLattice(4) object. I'm afraid that is where you should direct your complaints...
    – frougon
    Commented Feb 18, 2020 at 16:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .