~tex-sx/tex-sx/development

« back to all changes in this revision

Viewing changes to braids.dtx

  • Committer: Andrew Stacey (Thargelion)
  • Date: 2011-10-18 18:18:43 UTC
  • Revision ID: stacey@math.ntnu.no-20111018181843-xoxrwfmpcz5q2gst
More tweaks on labels; added ability to configure crossing path

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
%</internal>
82
82
%<*package>
83
83
\NeedsTeXFormat{LaTeX2e}
84
 
\ProvidesPackage{braids}[2011/05/07 v1.0 Tikz/PGF commands for drawing braid diagrams]
 
84
\ProvidesPackage{braids}[2011/10/18 v1.1 Tikz/PGF commands for drawing braid diagrams]
85
85
%</package>
86
86
%<*driver>
87
87
\documentclass{ltxdoc}
108
108
%</driver>
109
109
% \fi
110
110
%
111
 
% \CheckSum{815}
 
111
% \CheckSum{1078}
112
112
%
113
113
% \CharacterTable
114
114
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
150
150
% This is a package for drawing braid diagrams using PGF/TikZ.
151
151
% Its inspiration was a question and answer on the website \url{http://tex.stackexchange.com}.
152
152
%
 
153
% \section{History}
 
154
%
 
155
% \begin{itemize}
 
156
% \item v1.0 First public release.
 
157
%
 
158
% \item v1.1 Added ability to configure the gap size, the control points, and the ``nudge''.
 
159
% Added ability to add labels to strands between crossings.
 
160
% \end{itemize}
153
161
% \StopEventually{}
154
162
%
155
163
% \section{Implementation}
324
332
%    \begin{macrocode}
325
333
   \braid@endscope
326
334
  \else
327
 
  \ifx\braid@token\braid@label@strand
328
 
   \let\braid@next=\braid@label@strand
 
335
  \ifx\braid@token\braid@olabel@strand
 
336
   \let\braid@next=\braid@olabel@strand
 
337
  \else
 
338
  \ifx\braid@token\braid@clabel@strand
 
339
   \let\braid@next=\braid@clabel@strand
329
340
  \else
330
341
%    \end{macrocode}
331
342
% Otherwise, we add the token to the braid label.
341
352
  \fi
342
353
  \fi
343
354
  \fi
 
355
  \fi
344
356
  \braid@next%
345
357
}
346
358
%    \end{macrocode}
523
535
  \braid@ny=\braid@ty
524
536
  \advance\braid@nx by \braid@width
525
537
  \advance\braid@ny by \braid@height
 
538
  \advance\braid@ty by \braid@nf\braid@height
 
539
  \advance\braid@ny by -\braid@nf\braid@height
526
540
  \braid@cy=\braid@ty
527
541
  \braid@dy=\braid@ny
528
 
  \advance\braid@cy by .5\braid@height
529
 
  \advance\braid@dy by -.5\braid@height
530
 
  \advance\braid@ty by .05\braid@height
531
 
  \advance\braid@ny by -.05\braid@height
 
542
  \advance\braid@cy by \braid@cf\braid@height
 
543
  \advance\braid@dy by -\braid@cf\braid@height
532
544
%    \end{macrocode}
533
545
% Now we try to find a starting point for the strand ending here.
534
546
% We might not have used this strand before, so it might not exist.
637
649
%    \end{macrocode}
638
650
% \end{macro}
639
651
%
640
 
% \begin{macro}{\braid@label@strand}
 
652
% \begin{macro}{\braid@olabel@strand}
641
653
% This macro allows us to label a strand just before a crossing.
642
654
% The first argument is the strand number at that particular crossing and the second is the label.
643
655
% We also save the current height.
 
656
% This version takes the strand number as meaning the \emph{original} ordering.
644
657
%    \begin{macrocode}
645
 
\newcommand{\braid@label@strand}[3][]{%
 
658
\newcommand{\braid@olabel@strand}[3][]{%
646
659
  \edef\braid@tmp{{\the\value{braid@level}}}%
647
 
  \ifbraid@strand@labels@absolute
648
660
  \expandafter\ifx\csname braid@strand@#2@origin\endcsname\relax
649
661
  \g@addto@macro\braid@tmp{{#2}}%
650
662
  \else
651
663
  \edef\braid@tmpa{{\csname braid@strand@#2@origin\endcsname}}%
652
664
  \ge@addto@macro\braid@tmp{\braid@tmpa}%
653
665
  \fi
654
 
  \else
655
 
  \g@addto@macro\braid@tmp{{#2}}%
656
 
  \fi
657
666
  \g@addto@macro\braid@tmp{{#3}{#1}}%
658
667
  \ge@addto@macro{\braid@strand@labels}{\braid@tmp}%
659
668
  \braid@process%
661
670
%    \end{macrocode}
662
671
% \end{macro}
663
672
%
 
673
% \begin{macro}{\braid@clabel@strand}
 
674
% This macro allows us to label a strand just before a crossing.
 
675
% The first argument is the strand number at that particular crossing and the second is the label.
 
676
% We also save the current height.
 
677
% This version takes the strand number as meaning the \emph{current} ordering.
 
678
%    \begin{macrocode}
 
679
\newcommand{\braid@clabel@strand}[3][]{%
 
680
  \edef\braid@tmp{{\the\value{braid@level}}}%
 
681
  \g@addto@macro\braid@tmp{{#2}{#3}{#1}}%
 
682
  \ge@addto@macro{\braid@strand@labels}{\braid@tmp}%
 
683
  \braid@process%
 
684
}
 
685
%    \end{macrocode}
 
686
% \end{macro}
 
687
%
664
688
% \begin{macro}{\braid@floors@trim}
665
689
% The list of floors, if given, will start with a superfluous comma.
666
690
% This removes it.
986
1010
  \let\braid@strand@labels\@empty
987
1011
  \let\braid@floors\@empty
988
1012
  \let\braid@name\empty
989
 
  \let\label=\braid@label@strand
990
 
  \pgfkeys{/pgf/braid/.cd,#1}
 
1013
  \let\clabel=\braid@clabel@strand
 
1014
  \let\olabel=\braid@olabel@strand
 
1015
  \pgfkeys{/pgf/braid/.cd,#1}%
 
1016
  \ifbraid@strand@labels@origin
 
1017
  \let\label=\braid@olabel@strand
 
1018
  \else
 
1019
  \let\label=\braid@clabel@strand
 
1020
  \fi
991
1021
  \let\braid@options\tikz@options
992
1022
  \tikz@transform
993
1023
  \setcounter{braid@strands}{\pgfkeysvalueof{/pgf/braid/number of           strands}}%
994
 
  \braid@width=\pgfkeysvalueof{/pgf/braid/width}
995
 
  \braid@height=\pgfkeysvalueof{/pgf/braid/height}
996
 
  \braid@eh=\pgfkeysvalueof{/pgf/braid/border height}
 
1024
  \braid@width=\pgfkeysvalueof{/pgf/braid/width}%
 
1025
  \braid@height=\pgfkeysvalueof{/pgf/braid/height}%
 
1026
  \braid@eh=\pgfkeysvalueof{/pgf/braid/border height}%
 
1027
  \pgfkeysgetvalue{/pgf/braid/control factor}{\braid@cf}%
 
1028
  \pgfkeysgetvalue{/pgf/braid/nudge factor}{\braid@nf}%
997
1029
  \braid@height=-\braid@height
998
1030
  \braid@eh=-\braid@eh
999
1031
  \braid@increase@leveltrue
1021
1053
%    \end{macrocode}
1022
1054
% An if to decide whether label indices should be absolute or not
1023
1055
%    \begin{macrocode}
1024
 
\newif\ifbraid@strand@labels@absolute
 
1056
\newif\ifbraid@strand@labels@origin
1025
1057
%    \end{macrocode}
1026
1058
%
1027
1059
%
1055
1087
    width/.initial=1cm,
1056
1088
    gap/.initial=.1,
1057
1089
    border height/.initial=.25cm,
 
1090
    control factor/.initial=.5,
 
1091
    nudge factor/.initial=.05,
1058
1092
    name/.code={%
1059
1093
      \def\braid@name{#1}%
1060
1094
    },
1082
1116
      \def\braid@floors@style{#1}
1083
1117
    },
1084
1118
    strand label/.style={},
1085
 
    strand label by origin/.is if=braid@strand@labels@absolute
 
1119
    strand label by origin/.is if=braid@strand@labels@origin,
1086
1120
}
1087
1121
%    \end{macrocode}
1088
1122
% \begin{macro}{\braidset}