I've been using the braids package and it has worked quite well for me. I'm trying to "decorate" the braids that I'm drawing, and since TikZ can often take a lot of time to draw manually, I'm trying to automate this process. What I want is:
- Top and bottom bars to my braid
- Numeric labels "1,2, ..., n" at the top bar
- The corresponding labels at the bottom given by the braid itself (which brings me to my question)
I've mostly got all of this except the last point. An example is below:
Specifically I have the first and second things I want. Using the code of Shrodinger's Cat in another question of mine, I was shown how to automatically draw the top and bottom bars. Then, I used the calc package and a for loop to draw the top numbers "1, 2, 3, ..." automatically at the top.
My question: I of course want to draw the numbers at the bottom, right? But how should I do this? This is kind of hard because you need to now calculate the permutation of the braid in question.
My ideas:
- Create a program in TeX that (1) parses a copy of my braid e.g. "
s_1 s_2 s_3 ...
" The program will parse through this string, recover its underlying permutation (this is the hard part). Using this underlying permutation, TikZ then knows where to draw all of the integers at the bottom bar. Perhaps I could use somehow get LaTeX to communicate with a python shell, because this is probably easier to code in python. - Simply copy and paste "
\node at ...
" over and over again and manually label the bottom bar. This is less elegant and less in the spirit of automating the drawing, but perhaps method (1) will require so many for loops that it will take forever to compile and ultimately be useless.
However, does anyone have any other ideas on how to do this? I'm looking for suggestions/package references since this is kind of hard, and maybe there's an easier way I'm not seeing.
MWE of above braid:
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usepackage{calc}
\usetikzlibrary{braids}
\begin{document}
\def\nstrands{4} % NUMBER OF STRANDS
\newcounter{xcoord}
\begin{tikzpicture}
\pic[local bounding box=my braid,braid/.cd,
number of strands = \nstrands,
thick, % change me if you want
name prefix=braid]
{braid={ s_1, s_2, s_3}}; % BRAID GENERATORS
\draw[thick] % the top and bottom bars; help from https://tex.stackexchange.com/questions/549755/tikz-braids-how-to-draw-singular-braids-intersections
([xshift=-1ex]my braid.north west) -- ([xshift=1ex]my braid.north east)
([xshift=-1ex]my braid.south west) -- ([xshift=1ex]my braid.south east);
% labels the top bar with numbers automatically
\foreach \n in {1,...,\nstrands}{
\setcounter{xcoord}{\n -1}
\node at ([xshift = \thexcoord cm, yshift = 0.3 cm]my braid.north west) {\n};
}
% Prints the numbers on the bottom bar...
% ..One problem is calculating the permutation of the braid.
% theoretically, this is very easy, but for us it requires (1) a parser
% (2) a permutation calculator (3) a way to return these values
% back into latex...
% They're drawn manually for now.
\node at ([xshift = 0 cm, yshift = -0.3 cm]my braid.south west) {2};
\node at ([xshift = 1 cm, yshift = -0.3 cm]my braid.south west) {3};
\node at ([xshift = 2 cm, yshift = -0.3 cm]my braid.south west) {4};
\node at ([xshift = 3 cm, yshift = -0.3 cm]my braid.south west) {1};
\end{tikzpicture}
\end{document}