summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/multicolrule/multicolrule.dtx
blob: 3e370bc7f98f8610a4ccda192f662202360fec05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
% \iffalse meta-comment
% !TEX program  = pdfLaTeX
%<*internal>
\iffalse
%</internal>
%<*readme>
multicolrule - Decorative rules between columns
=================================================

The multicolrule package lets you customize the appearance of
the vertical rule that appears between columns of multicolumn
text. It is primarily intended to work with the multicol
package, hence its name, but it also supports the twocolumn
option and \twocolumn macro provided by the standard classes
(and related classes such as the KOMA-Script equivalents).

Installation
------------

This package is provided as a .dtx file. To install it and
compile the documentation at the same time, simply process the
.dtx file with LaTeX (for example, `pdflatex multicolrule.dtx`).
To extract the package only, process the file with TeX 
(`tex multicolrule.dtx`). Note that the documentation uses
the l3doc class to index the code, and so to get the index, you
must issue:

`makeindex -s gind.ist -o multicolrule.ind multicolrule.idx`

and to get the change list, you must issue

`makeindex -s gglo.ist -o multicolrule.gls multicolrule.glo`.

This package requires LaTeX3 support to run, and compiling the
documentation requires a variety of other packages, all of which
are available on CTAN and any modern installation (TeX Live,
MiKTeX, etc.).
%</readme>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
\expandafter\begingroup
\fi
%</internal>
%<*install>
\input l3docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble
----------------------------------------------------------------
multicolrule --- Decorative rules between columns
Author: Karl Hagen
Email: latex@polysyllabic.com
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
----------------------------------------------------------------

\endpreamble
\postamble
Copyright (C) 2018 by Karl Hagen <latex@polysyllabic.com>
 
This file may be distributed and/or modified under the
conditions of the LaTeX Project Public License (LPPL), either
version 1.3c of this license or (at your option) any later
version. The latest version of this license is in the file:
    https://www.latex-project.org/lppl.txt

This work is "maintained" (as per LPPL maintenance status) by
  Karl Hagen.

This work consists of the files multicolrule.dtx and
                                mcrule-examples.tex,
and the derived files           multicolrule.ins,
                                multicolrule.sty,
                                multicolrule.pdf, and
                                mcrule-examples.pdf.
\endpostamble
\usedir{tex/latex/multicolrule}
\generate{
  \file{\jobname.sty}{\from{\jobname.dtx}{package}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/multicolrule}
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
\usedir{doc/latex/multicolrule}
\generate{
  \file{README.md}{\from{\jobname.dtx}{readme}}
}
\ifx\fmtname\nameofplainTeX
\expandafter\endbatchfile
\else
\expandafter\endgroup
\fi
%</internal>
%<*driver|package>
\RequirePackage{expl3}
\RequirePackage{xparse}
%</driver|package>
%<*driver>
\PassOptionsToPackage{svgnames}{xcolor}
\documentclass{l3doc}
\usepackage[T1]{fontenc}
\usepackage[ttscale=0.85]{libertine}
\usepackage{microtype}
\usepackage[tikz]{multicolrule}
\usepackage{longtable}
\usepackage{scrlayer-scrpage}
\usepackage{scrlayer-notecolumn}
\usepackage{bbding}
\usepackage{pgfornament}
\pagestyle{scrheadings}
\automark[subsection]{section}
\DeclareNewNoteColumn[
  reversemarginpar,
  font=\color{Navy}\footnotesize\sffamily
]{illustration}
\ProvideDocumentCommand\opt{m}{\texttt{#1}}
\NewDocumentCommand{\stydsc}{m}{^^A
  \makenote*[illustration]{^^A
    \hspace*{32pt}\parbox{\marginparwidth-32pt}{^^A
      \raggedright\texttt{#1}}^^A
  }^^A
}
\NewDocumentCommand{\mcrule}{}{\textcolor{Maroon}{multicolrule}}
\NewDocumentCommand{\kvdesc}{m}{\textcolor{Navy}{\texttt{#1}}}
\setlength{\columnsep}{24pt}
\SetMCRule{width=thin,color=Maroon,line-style=dots}
\EnableCrossrefs         
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
%\GetFileInfo{\jobname.sty}
%
%\DoNotIndex{\AfterPackage,\begin,\bool_gset_true:N,\bool_if:NTF,
%   \bool_lazy_and:nnT,\cs_gset_eq:NN,\bool_if_p:n,\bool_lazy_and:nnTF,
%   \bool_not_p:n,\bool_new:N,\box_ht:N,\box_dp:N,\box_move_down:nn,
%   \cs_generate_variant:Nn,\cs_gset:Npn,\cs_new:Npn,
%   \cs_new_nopar:Npn,\cs_set:Npn,\dim_compare_p:nNn,\dim_new:N,\dim_set:Nn,
%   \dim_compare:nNnTF,\dim_eval:n,\dimen,
%   \end,\ExplSyntaxOff,\ExplSyntaxOn,\fill,\hbox:n,\hspace,\ht,
%   \int_compare_p:nNn,\int_new:N,\int_set:Nn,\kern,\keys_define:nn,
%   \keys_set:nn,\msg_error:nnn,\msg_info:nnn,\msg_new:nnn,\msg_warning:nn,
%   \NewDocumentCommand,\node,\prg_replicate:nn,\ProcessKeysOptions,
%   \ProvidesExplPackage,\RequirePackage,\rule,\normalcolor,
%   \tl_if_empty:NT,\tl_if_empty:NTF,\tl_new:N,\tw@,
%   \tl_set:Nn,\vbox:n,\vbox_to_ht:nn,\vfill,\vrule,
%   \cs_new_protected:Npn,\@ifpackageloaded,\@width,\xpatchcmd}
%
%\title{^^A
%  \textsf{multicolrule} --- Decorative rules between columns\thanks{^^A
%   This file describes version \fileversion, last revised \filedate.^^A
%  }^^A
%}
%\author{^^A
%  Karl Hagen\thanks{\href{mailto://latex@polysyllabic.com}^^A
%   {latex@polysyllabic.com}}}
%\date{Released \filedate}
%
%\maketitle
%
%\changes{v1.0}{2018/12/15}{Initial public release}
%\changes{v1.1}{2018/12/21}{Work with \pkg{bidi} and allow extending rules}
%
%\begin{abstract}
% The \mcrule{} package lets you customize the appearance of the vertical rule
% that appears between columns of multicolumn text. It is primarily intended to
% work with the \pkg{multicol} package, hence its name, but it also supports
% the twocolumn option and \cs{twocolumn} macro provided by the standard
% classes (and related classes such as the KOMA-Script equivalents), as well as
% the \pkg{bidi} package (and through it, all RTL scripts loaded with
% \pkg{polyglossia}).
%\end{abstract}
%
%\tableofcontents
%
%\begin{documentation}
%
%\begin{multicols}{2}[\section{Introduction}]
%\SetMCRule{line-style=dashed}
%  
% In\stydsc{line-style=dashed} \LaTeX, there are two lengths that control the
% formatting between columns of multicolumn text: \cs{columnsep} specifies the
% space between adjacent columns, and \cs{columnseprule} specifies the width of
% a solid vertical rule that is placed centered between the columns. The
% \pkg{multicol} package adds the ability to change the color of the rule, but
% in both vanilla \LaTeX{} and \pkg{multicol}, the rule itself is drawn
% directly inside the routines that output the column boxes, and is therefore
% difficult for users to alter.
%
% Of course it's a legitimate question why anyone should \emph{want} to change
% this rule, or indeed use one at all, as good typography tends to avoid using
% large vertical lines.\footnote{See, for example, the remarks in the
% documentation for the \pkg{booktabs} package} In my own case, I needed to
% modify the rule because of the requirements of a particular style I was
% imitating, and having done the hard work of creating the necessary
% infrastructure for one line style, it was simple to extend the solution to a
% more general case. I hope someone else will find the options here useful.
%
% The basic line styles that \mcrule{} makes available are illustrated
% throughout this guide. The default line-width used is 0.4pt (thin), and the
% default color is \texttt{Maroon}. You can also find examples of rules created
% with all available options in the file \file{mcrule-example.pdf}.
%
% \subsection*{New for Version 1.1}
% Version 1.1 now supports drawing decorative rules if you have the \pkg{bidi}
% package loaded, which can occur automatically if you set a right-to-left
% language with \pkg{polyglossia}. It also provides a mechanism to extend or
% shrink rules by fixed amounts, as well as to have the rule fill the available
% space to the end of the text area (see section \ref{sec:extend}).
%
% \end{multicols}
%
% \begin{multicols}{2}[\subsection{Bugs and Known Limitations}]
% There\stydsc{line-style=dots} are likely bugs that remain to be uncovered,
% as well as missing features and inefficient methods that should be improved
% upon. The development code is maintained on github
% (\url{https://github.com/polysyllabic/multicolrule}), and you can file
% feature requests or bug reports there. Alternatively, you can send an email
% to \href{mailto://latex@polysyllabic.com}{latex@polysyllabic.com}. I welcome
% contributions for additional styles, especially to provide more options when
% running the package without \pkg{tikz}.
%  
% The line styles that work by repeating elements in a tiled pattern may have
% significant gaps at the end of columns, particularly for larger patterns.
% You can mitigate this problem slightly by tweaking the spaces above and
% below a pattern, but the basic problem is a side-effect of the way these
% patterns are implemented (with \cs{cleaders}), which means that only an
% integer number of copies can be produced. Lines drawn with \pkg{tikz} do not
% have this problem.
% 
% I have also noticed occasional instances, most noticeably when a
% \env{multicols} environment starts near the bottom of a page and the columns
% continue to the next one, where the rules are either somewhat shorter than
% they should be or shifted upward from where they belong. In the limited
% testing I have done, this appears to be a consequence of how \pkg{multicol}
% works, as the default rules show the same behavior. I may try to nail down
% this issue in future version, but as it's an edge case that disappears when
% you add page breaks or rewrite the text to alter how the columns are filled,
% it hasn't seemed worth taking the time to fix at this point.
% 
% This package works by patching the output routines of either \pkg{multicol}
% or the \LaTeX{} kernel, depending on the mode of operation. If \pkg{bidi} is
% loaded, it will also patch that. It will have no effect if you use a class or
% package that outputs column text via alternate mechanisms. This includes
% \pkg{parcolumns}, and probably other classes and packages designed to typeset
% parallel-column text as well, although I have not done a survey to determine
% whether this is the case. If you would like support for one of these, please
% send me an email or file a feature request on github and I'll see what I can
% do.
% 
% \mcrule{} is written using expl3 syntax, and so requires a less-than-ancient
% installation of \LaTeX. It uses the packages \pkg{l3keys2e}, \pkg{xparse},
% \pkg{xpatch}, and \pkg{xcolor}, and depending on the mode of operation may
% also require \pkg{multicol} and \pkg{tikz}. If you have an up-to-date
% distribution, these requirements should cause no issues.
% \end{multicols}
%
% \begin{multicols}{2}[\subsection{License}]
% \SetMCRule{width=ultra-thick,line-style=dotted}
% The\stydsc{\texttt{line-style=dotted, width=ultra-thick}} \mcrule{}
% package is copyright 2018 by Karl Hagen. It may be distributed and/or
% modified under the conditions of the \LaTeX{} Project Public License, either
% version 1.3c of this license or (at your option) any later version. The
% latest version of this license is in
% \url{http://www.latex-project.org/lppl.txt}.
%  
% This work has the LPPL maintenance status `maintained.' The Current
% Maintainer of this work is Karl Hagen.
% \end{multicols}
%
%\begin{multicols}{2}[\section{Package Options}]
% \SetMCRule{line-style=dash-dot}
%
% \subsection{Default Operation}
% If\stydsc{line-style=dash-dot} you load \mcrule{} with its default settings,
% it will enable \pkg{multicol} support, and that package will be loaded if it
% hasn't been already. Note that if you need to pass any parameters to
% \pkg{multicol}, such as |docolaction|, you should load \pkg{multicol} with
% the appropriate settings \emph{before} you load \mcrule, as \LaTeX{} does not
% support reloading packages with different parameters.
% 
% \subsection{Option `twocolumn'}
% \DescribeOption{twocolumn}
% The \mcrule{} package recognizes the option \opt{twocolumn},
% either as a package option or as a global class option. If you pass this option
% to your document class, you do not need to pass it a second time to the
% package. It is only necessary to use the package option if you plan to have a
% predominantly one-column document and use \cs{twocolumn} to switch
% temporarily into two-column mode.
% 
% Because \pkg{multicol} does not work well with the ordinary two-column
% mode, \mcrule{} is only designed to work with one or the other at a time. If
% you try to use the \opt{twocolumn} option when
% \pkg{multicol} has already been loaded, you will receive a warning, and
% nothing is guaranteed. But the custom rules will at best only appear in the
% conventional two-column mode and not within a \env{multicols} environment.
% 
% \subsection{Option `tikz'}
% \DescribeOption{tikz}
% You have access to a wider set of line styles if you also use the \pkg{tikz}
% package. Some line styles are only available if \pkg{tikz} is enabled, and
% others look better with it. The default behavior of \mcrule{} depends on the
% status of the \pkg{tikz} package at the time \mcrule{} is loaded. If
% \mcrule{} detects that \pkg{tikz} is already loaded, then tikz support will
% be enabled by default. Otherwise, you need the \opt{tikz} to enable it. This
% option also accepts explicit boolean values, so you can pass |tikz=false| if
% you want to explicitly disable tikz support. If tikz support is not enabled
% (or if it is explicitly disabled), the line styles marked \emph{tikz only}
% in section \ref{sec:linestyles} will be unavailable and errors will result
% if you try to use them.
% \end{multicols}
%
% \begin{multicols}{2}[\section{The User Interface}]
% \SetMCRule{width=2pt,line-style=circles}
% The\stydsc{line-style=circles,\\width=2pt} \mcrule{} package has
% just a single user command:
%
% \cs{SetMCRule} \marg{key-value}
%
% \noindent It takes one parameter containing a key-value list of all options you
% want to set. You can issue this command in the preamble or the document body.
% Changes to the rule settings are local to the current group. For example, if
% you call \cs{SetMCRule} inside a \env{multicols} environment, the rule
% settings will revert to their previous values once the environment ends. Also
% note that any changes made with \cs{SetMCRule} when multiple columns are
% active will appear starting on the same page as your current location when you
% issue the command, and will extend the height of the full column box. It is not
% possible to have a rule change styles in the middle of a page unless you close
% out one \env{multicols} environment and begin another.
%  
% Table \ref{table:mcrulekeys} summarizes the keys available in \cs{SetMCRule}.
% The functions of each is described in detail in the sections that follow.
% \end{multicols}
%
% \begin{longtable}{lp{3.5in}}
% \caption{\cs{SetMCRule} keys\label{table:mcrulekeys}} \\
% \toprule
% Key & Purpose\\
% \midrule
% \endfirsthead
% \caption{\textbackslash SetMCRule keys (cont.)} \\
% \toprule
% Key & Purpose\\
% \midrule
% \endhead
% \kvdesc{color} & Set the color of the rule (see sec. \ref{sec:color})\\
% \kvdesc{color-model} & Set the color model of the rule (see sec.
% \ref{sec:color})\\
% \kvdesc{custom-line} & Set a custom \pkg{tikz} line for the rule 
% (\emph{tikz only}; see sec. \ref{sec:custom})\\
% \kvdesc{custom-pattern} & Set a custom individual pattern for the rule (see
% sec. \ref{sec:custom})\\
% \kvdesc{custom-tile} & Set a custom tiling pattern for the rule
% (see sec. \ref{sec:custom})\\
% \kvdesc{double} & Draw two copies of the rule (see sec.
% \ref{sec:repeats})\\
% \kvdesc{extend-bot} & Set an extra amount to extend the rule at the bottom of
% the column (see sec. \ref{sec:extend})\\
% \kvdesc{extend-fill} & Extend rule to the bottom of the text area
% (\emph{multicol} only; see sec. \ref{sec:extend})\\
% \kvdesc{extend-reserve} & Space to reserve at bottom of text area when using
% \kvdesc{extend-fill} (\emph{multicol} only; see sec, \ref{sec:extend})\\
% \kvdesc{extend-top} & Set an extra amount to extend the rule at the top of 
% the column (see sec. \ref{sec:extend})\\
% \kvdesc{line-style} & Select the type of rule printed 
% (default=\emph{default}; see sec. \ref{sec:linestyles})\\
% \kvdesc{single} & Draw a single copy of the rule (\emph{default};
% see sec. \ref{sec:repeats})\\
% \kvdesc{repeat} & Set the number of times to draw the rule (see
% sec. \ref{sec:repeats})\\
% \kvdesc{repeat-distance} & Set the horizontal space between
% adjacent copies of repeated rules (see sec. \ref{sec:repeats})\\
% \kvdesc{triple} & Draw three copies of the rule (see sec.
% \ref{sec:repeats})\\
% \kvdesc{width} & Set the width of the rule (see sec.
% \ref{sec:width})\\
% \bottomrule
% \end{longtable}
%
% \begin{multicols}{2}[\subsection{Styles with the `line-style' option}^^A
%   \label{sec:linestyles}]
%  \SetMCRule{width=4pt,line-style=solid-circles}
%  
% You\stydsc{line-style= solid-circles,\\ width=4pt} choose a style for the rule
% with the \kvdesc{line-style} key.  If the predefined styles are insufficient,
% see section \ref{sec:custom} for different ways to customize it. The width of
% most line styles depends on the setting of \cs{columnseprule}, the default
% \LaTeX{} length that controls the width of the column rule (see section
% \ref{sec:width}). 
%  
% Table \ref{table:linestyles} summarizes the available line styles. Most of
% the basic patterns come in three versions, differing only in how closely the
% pattern is spaced: normal, dense, and loose. These settings parallel those
% found in \pkg{tikz}.
% \end{multicols}
%
% \begin{longtable}{lp{3in}}
%   \caption{Styles available for the line-style key\label{table:linestyles}}\\
%   \toprule
%   Style & Description\\
%   \midrule
%   \endfirsthead
%   \caption{Available line-style settings (cont.)} \\
%   \toprule
%   Style & Description\\
%   \midrule
%   \endhead
%   \kvdesc{circles} & A series of hollow circles (\emph{tikz
%     only})\\
%   \kvdesc{dash-dot} & A dash followed by a square dot (\emph{tikz
%     only})\\
%   \kvdesc{dash-dot-dot} & A dash followed by two square dots
%     (\emph{tikz only})\\
%   \kvdesc{dashed} & A series of dashed lines\\
%   \kvdesc{default} & A solid rule drawn the same way as the default
% \pkg{multicol} rule. Does not support extended rules.\\
%   \kvdesc{dense-circles} & The same as \kvdesc{circles}
%     but more closely spaced (\emph{tikz only})\\
%   \kvdesc{dense-dots} & The same as \kvdesc{dots} but
%     more closely spaced\\
%   \kvdesc{dense-solid-circles} & The same as \kvdesc{solid-circles} but more
% closely spaced (\emph{tikz only})\\
%   \kvdesc{densely-dash-dot} & The same as \kvdesc{dash-dot} but more closely
% spaced (\emph{tikz only})\\
%   \kvdesc{densely-dash-dot-dot} & The same as \kvdesc{dash-dot-dot} but more
% closely spaced (\emph{tikz only})\\
%   \kvdesc{densely-dashed} & The same as \kvdesc{dashed} but more closely
% spaced\\
%   \kvdesc{densely-dotted} & The same as \kvdesc{dotted} but more closely
% spaced\\
%   \kvdesc{dots}  & A series of dots drawn with the period (full-stop) of the
% current font\\
%   \kvdesc{dotted} & A series of square dots\\
%   \kvdesc{loose-dots} & The same as \kvdesc{dots} but spaced further apart\\
%   \kvdesc{loose-circles} & The same as \kvdesc{circles} but spaced further
% apart (\emph{tikz only})\\
%   \kvdesc{loose-solid-circles} & The same as \kvdesc{solid-circles} but
% spaced further apart (\emph{tikz only})\\
%   \kvdesc{loosely-dash-dot} & The same as \kvdesc{dash-dot} but spaced
% further apart (\emph{tikz only})\\
%   \kvdesc{loosely-dash-dot-dot} & The same as \kvdesc{dash-dot-dot} but
% spaced further apart (\emph{tikz only})\\
%   \kvdesc{loosely-dashed} & The same as \kvdesc{dashed} but spaced further
% apart\\
%   \kvdesc{loosely-dotted} & The same as \kvdesc{dotted} but spaced further
% apart\\
% \kvdesc{solid} & A solid line, like \kvdesc{default}, but supports extending
% rules\\
% \kvdesc{solid-circles} & A series of filled circles (\emph{tikz only})\\
% \bottomrule
% \end{longtable}
%
% \begin{multicols}{2}[\subsubsection{Notes on the Styles}]
% \SetMCRule{width=thin,line-style=solid} 
% The\stydsc{line-style=solid} \kvdesc{default} and \kvdesc{solid} line styles
% are nearly the same, except that the \kvdesc{solid} line (as of version 1.1)
% supports the rule-extension commands described in section \ref{sec:extend}.
% This means that if you want a solid rule with altered top or bottom
% extensions, you must explicitly set the line style to \kvdesc{solid}. If you
% make no calls to \cs{SetMCRule} after loading \mcrule, the column divider
% will continue to behave exactly as it does with the ordinary \pkg{multicol}
% package.
%
% You can alter the rule's width and color either through \cs{SetMCRule} with
% the \kvdesc{width} and \kvdesc{color} keys described in sections
% \ref{sec:width} and \ref{sec:color}, respectively, or directly by changing
% the value of \cs{columnseprule} and renewing the \cs{columnseprulecolor}
% macro. All line styles, including \kvdesc{default}, can be repeated as many
% times as you like (see section \ref{sec:repeats}).
%  
% The \kvdesc{dots} style and its variants are rendered with a period (.) in
% the currently active font. This means that changing \cs{columnseprule} will
% not change the size of these dots, although, as with all rules, it will not
% appear at all if \cs{columnseprule} is set to 0pt. Custom tiles and patterns
% also do not scale with \cs{columnseprule}.
%
% The \kvdesc{dotted} styles differ from \kvdesc{dots} in that the former are
% squares with side lengths equal to \cs{columnseprule}. This mirrors the
% behavior of the equivalently named dotted patterns in \pkg{tikz}.
% \end{multicols}
%
% \subsubsection{Custom Patterns}\label{sec:custom}
%
% \begin{multicols}{2}[\noindent\texttt{custom-tile=} \marg{pattern} \marg{space above}
%   \marg{space below}]
% \SetMCRule{custom-tile={\SparkleBold}{16pt}{16pt}}
%
% There\stydsc{custom-tile= \{\textbackslash SparkleBold\} \{16pt\}\{16pt\}}
% are three options to create custom rules with \mcrule. The first is the
% \kvdesc{custom-tile} key. This creates a rule consisting of vertically
% stacked boxes of arbitrary content---the tile---running the height of the
% column separator. The \kvdesc{custom-tile} key takes three parameters,
% which must all be enclosed brackets and may not be omitted. The first
% should contain the tokens you want to appear as the content of the tile.
% The second is a dimension specifying the leading vertical space to apply
% above each copy of the tile. The third is a dimension specifying the
% trailing vertical space to insert below each copy of the tile.
%
% The rule in this section uses the \cs{SparkleBold} symbol from
% \pkg{bbding}. Notice that when you use the \kvdesc{custom-tile} parameter,
% of any of the other custom key commands, you do \emph{not} specify a separate
% \kvdesc{line-style}. If you try to provide both, the last style given in the
% list will be the one that is kept.
% \end{multicols}
%
% \begin{multicols}{2}[\noindent\texttt{custom-pattern=} \marg{pattern} \marg{shift
%    down} \marg{shift up}]
% \SetMCRule{custom-pattern={\HandRight}{0pt}{0pt}} 
%
% The\stydsc{custom-pattern= \{\textbackslash HandRight\} \{0pt\}\{0pt\}}
% second custom option is with the \kvdesc{custom-pattern} key. The syntax
% is identical to that for \kvdesc{custom-tile}, but the content you specify
% will appear once per page or column pair (if the columns occupy less than a
% full page). This content will be vertically centered if the second and third
% parameters are both 0pt. You can shift the content down by increasing the
% second parameter, and up by increasing the third. The rule in this section
% uses the \cs{HandRight} symbol from \pkg{bbding}.
% \end{multicols}
%
% \clearpage
% \begin{multicols}{2}[\noindent\texttt{custom-line=} \marg{draw command}]
% \SetMCRule{width=1pt,custom-line={\draw[line width=\columnseprule] (TOP) to
%   [ornament=88] (BOT);}}
%
% The\stydsc{custom-line=\{ \textbackslash draw[line width= \textbackslash
%   columnseprule] (TOP) to [ornament=88] (BOT);\},\\width=1pt} third custom
% pattern involves setting your own \pkg{tikz} drawing
% function using the key \kvdesc{custom-line}. The rule in this section is
% drawn with an ornament from \pkg{pgfornaments}. Obviously, this feature
% requires \pkg{tikz} support. The value you provide to the
% \kvdesc{custom-line} key should consist of a \pkg{tikz} command, such as
% \cs{draw}, without the surrounding \env{tikzpicture} environment.
% 
% Before the drawing command is called, \mcrule{} will set up a
% \env{tikzpicture} with both the x- and y-coordinates scaled to points, and
% two nodes, named \texttt{(TOP)} and \texttt{(BOT)}, which are set to the
% coordinates of the top and bottom of the rule. You can then specify your own
% \cs{draw} function in whatever way you like. The rule separating these
% columns was drawn with a decorative element from the \pkg{pgfornaments}
% package.
%
% This function will use the color set in
% \cs{columnseprulecolor} if you don't set it explicitly within the tikz
% command, but you must provide everything else necessary to draw the line
% correctly, including the line width. Note that this function should be
% considered experimental. It works for single-line commands such as the one
% shown in the example, but I haven't tested it with anything more elaborate. 
% \end{multicols}
%
% \begin{multicols}{2}[\subsection{Colors}\label{sec:color}]
% \SetMCRule{width=2pt,line-style=solid,color-model=cmy,color={0.7,0.5,0.3}}
% You\stydsc{line-style=solid,\\width=2pt\\color-model=cmy,\\
% color=\{0.7,0.5,0.3\}} can set colors for the rule through the
% \kvdesc{color} and, optionally, the \kvdesc{color-model} keys. \mcrule{} loads the
% \pkg{xcolor} package to manage colors, and the \kvdesc{color}
% parameter accepts any name that \pkg{xcolor} recognizes, either natively or
% as the result of any names you have defined with \cs{definecolor}
% (see the \pkg{xcolor} documentation). Note that if you want to use color names that
% are defined through the one of \pkg{xcolor}'s package options, you must load 
% \pkg{xcolor} before both \mcrule{} and \pkg{tikz} with the relevant options.
%  
% To specify a color by a numeric specification, you use the
% \kvdesc{color-model} parameter to specify any color model that
% \pkg{xcolor} recognizes (rgb, cmy, etc), and \kvdesc{color} to
% hold the color-specification list. Because that list is itself comma-separated,
% you must enclose it in brackets.
%  
% The current color setting can always be found in
% \cs{columnseprulecolor}. If you are running in twocolumn
% mode without \pkg{multicol}, this command will be provided and colors will
% work the same way they do with \pkg{multicol}. Note that setting the 
% \kvdesc{color} key causes \cs{columnseprulecolor}
% to be redefined within the current group only. If you directly redefine
% \cs{columnseprulecolor}, the color of the custom rule will
% reflect this setting. This way, the settings of any packages that might alter
% the rule color will be respected.
%\end{multicols}
%
% \begin{multicols}{2}[\subsection{Width}\label{sec:width}]
% \SetMCRule{width=thick,line-style=dash-dot-dot}
% You\stydsc{line-style= dash-dot-dot,\\ width=thick} can set the width of the
% rule with the \kvdesc{width} key. Legal values are any explicit dimension or
% dimension expression, as well as with names that parallel those used by
% \pkg{tikz}, except that spaces in the key names are replaced with hyphens.
%  
% The current width of the rule is kept in \cs{columnseprule}, just as in
% vanilla \LaTeX, and if it is set separately, the custom rule's width will
% reflect this change. Note that although some line styles do not depend 
% directly on \cs{columnseprule} to calculate their actual width, the value
% of \cs{columnseprule} must be greater than 0pt for any rule to appear. This
% behavior is intentional and is in keeping with the way the default column
% rules work.
% \end{multicols}
%
% \begin{longtable}{ll}
%   \caption{Sizes of named line widths\label{table:linewidths}} \\
%   \toprule
%   Name & Width\\
%   \midrule
%   \endfirsthead
%   \caption{Sizes of named line widths (cont.)} \\
%   \toprule
%   Name & Width\\
%   \midrule
%   \endhead
%   \kvdesc{ultra-thin} & 0.1pt\\
%   \kvdesc{very-thin}  & 0.2pt\\
%   \kvdesc{thin}       & 0.4pt\\
%   \kvdesc{semithick}  & 0.6pt\\
%   \kvdesc{thick}      & 0.8pt\\
%   \kvdesc{very-thick} & 1.2pt\\
%   \kvdesc{ultra-thick} & 1.6pt\\
%   \bottomrule
% \end{longtable}
%
% \begin{multicols}{2}[\subsection{Repeated Rules}\label{sec:repeats}]
% \SetMCRule{line-style=dash-dot-dot,triple=2pt}
%  
% You can\stydsc{line-style= dash-dot-dot, triple=2pt} draw multiple,
% adjacent copies of any rule by setting the number of times to draw the rule
% with the \kvdesc{repeat} key. The space between copies is controlled with the
% \kvdesc{repeat-distance} key. Initially, this distance is set to
% \cs{columnseprule}.
%  
% The keys \kvdesc{single}, \kvdesc{double}, and \kvdesc{triple} are shorthand
% methods to set the number of repeats and the \kvdesc{repeat-distance} at the
% same time. If you use the key without a value \kvdesc{repeat-distance} is set
% to \cs{columnseprule}.
%
% There are no checks made to ensure that repeated rules will fit in the
% available space between columns, so you should be careful using these
% commands, especially with thicker rules.
% \end{multicols}
%
%\begin{multicols}{2}[\subsection{Extended Rules}\label{sec:extend}]
% \SetMCRule{line-style=dashed,extend-top=-16pt,extend-bot=-16pt}
%
% You\stydsc{line-style=dashed, extend-top=-16pt, extend-bot=-16pt} can specify
% an additional amount by which the top or bottom of the rule projects beyond
% the column's natural length with the keys \kvdesc{extend-top} and
% \kvdesc{extend-bot}, each of which can be set to a dimension expression.
% Extending the top of the rule with a positive dimension will push the columns
% down from any preceding material. A positive value for \kvdesc{extend-bot}
% does the same in the other direction when a column ends in the middle of a
% page, but the rule will extend into the the bottom margin if the column goes
% to the end of the page, and so you probably only want to use this in very
% limited situations where you need a special effect for one small
% \env{multicol} environment. Negative values for both keys may be more 
% generally useful, as they have the effect of shrinking the rule. This
% behavior is illustrated with the rule for this section.
%
% The \kvdesc{extend-fill} key is a boolean option that, when set to true, will
% extend the rule to occupy any space between the bottom of the columns and the
% end of the text area. Providing the key with no value is equivalent to
% |extend-fill=true|. This option has no effect unless the \pkg{multicol}
% package is loaded.
%
% If you want text below the \env{multicols} environment when using
% \kvdesc{extend-fill}, you can reserve space for it with
% \kvdesc{extend-reserve}, which takes a dimension expression specifying the
% vertical space to leave available after the rule. If the value is greater
% than zero, the height of the extended line will be reduced by the reserved
% amount plus the value of \cs{multicolsep}. In other words, you only have to
% specify the actual space you need for the text itself, not the space that 
% \pkg{multicol} adds automatically below the columns. Note that if the amount
% you request for reserved space is less than the amount actually available at
% the end of the page, the rule will not extend below the columns and you
% probably will find this material spilling onto the next page anyway.
% 
%\end{multicols}
%\end{documentation}
%
%\begin{implementation}
%
%\section{Implementation}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
%    \begin{macrocode}
%<@@=mcrule>
%    \end{macrocode}
%
%\subsection{Preliminaries}
%
%    \begin{macrocode}
\ProvidesExplPackage {multicolrule} {2018/12/21} {1.1}
  {Decorative~vertical~rules~between~columns}
%    \end{macrocode}
%
% We always need these packages.
%    \begin{macrocode}
\RequirePackage{l3keys2e}
\RequirePackage{xpatch}
\RequirePackage{xcolor}
\RequirePackage{scrlfile}
%    \end{macrocode}
%
% Define the messages we use.
%    \begin{macrocode}
\msg_new:nnn {multicolrule} {patch-success} {Patched~#1.}
\msg_new:nnn {multicolrule} {patch-failure} {Error~patching~#1.}
\msg_new:nnn {multicolrule} {tikz-required}
{The~'#1'~setting~requires~tikz~to~work.~Either~load~tikz~before~you~load~
  multicolrule~or~use~multicolrule's~'tikz'~package~option.}
\msg_new:nnn {multicolrule} {multicol-loaded} {You~are~using~the~'twocolumn'~
  option~with~multicol~already~loaded.~You~will~likely~run~into~problems.}
%    \end{macrocode}
%
%\begin{variable}{\g_@@_twocolumn_bool,\g_@@_use_tikz_bool}
% Flags for package options
%    \begin{macrocode}
\bool_new:N \g_@@_twocolumn_bool
\bool_new:N \g_@@_use_tikz_bool
%    \end{macrocode}
%\end{variable}
%
%\begin{variable}{\l_@@_repeat_int,\l_@@_repeat_distance_dim}
% Variables to support repeated copies of the rule.
%    \begin{macrocode}
\int_new:N  \l_@@_repeat_int
\int_set:Nn \l_@@_repeat_int {1}
\dim_new:N  \l_@@_repeat_distance_dim
%    \end{macrocode}
%\end{variable}
%
%\begin{variable}{\l_@@_extend_top_dim,
%  \l_@@_extend_bot_dim,
%  \l_@@_extend_fill_bool,
%  \l_@@_extend_reserve_dim}
% Variables to control the distance to extend the rule above and below the
% natural column height.
%    \begin{macrocode}
\dim_new:N  \l_@@_extend_top_dim
\dim_new:N  \l_@@_extend_bot_dim
\bool_new:N \l_@@_extend_fill_bool
\dim_new:N  \l_@@_extend_reserve_dim
%    \end{macrocode}
%\end{variable}
%
%\begin{variable}{\l_@@_color_name_tl,\l_@@_color_model_tl}
% Keep name and color model so we can set them separately while retaining
% the value of the other one.
%    \begin{macrocode}
\tl_new:N \l_@@_color_name_tl
\tl_new:N \l_@@_color_model_tl
%    \end{macrocode}
%\end{variable}
%
% If \pkg{tikz} is already loaded, enable \pkg{tikz}-sensitive line styles
% unless the user explicitly disables them. If \pkg{tikz} is not already
% loaded, these functions are disabled unless they are explicitly loaded.
%
%    \begin{macrocode}
\@ifpackageloaded{tikz}
{
  \bool_gset_true:N \g_@@_use_tikz_bool
}{}
%    \end{macrocode}
%
% Set up the keys for package options and process them.
%
%    \begin{macrocode}
\keys_define:nn {mcrule-opts}
{
  twocolumn .bool_gset:N = \g_@@_twocolumn_bool,
  tikz      .bool_gset:N = \g_@@_use_tikz_bool,
  tikz      .default:n   = true,
}
\ProcessKeysOptions{mcrule-opts}
%    \end{macrocode}
%
% \subsection{Patching Output Routines}
%
%\begin{function}{\@@_column_height:,\@@_column_depth:}
%
% Get the height and depth of the box appropriate to the supported mode.
%
%    \begin{macrocode}
\cs_new:Npn \@@_column_height: {}
\cs_new:Npn \@@_column_depth: {}
%    \end{macrocode}
%\end{function}
%
% Now that we know what mode we're going to run in, we patch the output
% routine(s) to substitute our custom rule for the vanilla one. Since
% \pkg{multicol} doesn't fully support twocolumn mode, we patch one or the
% other, but not both.
%
%\begin{function}{\@@_patch_mcol_output:N}
%    \begin{macrocode}
\cs_new_protected:Npn \@@_patch_mcol_output:N #1
{
  \xpatchcmd{#1} {\vrule\@width\columnseprule} {\mcruledivider}
  {\msg_info:nnn {multicolrule} {patch-success} {#1}}
  {\msg_info:nnn {multicolrule} {patch-failure} {#1}}
}
%    \end{macrocode}
%\end{function}
%
%\begin{function}{\@@_patch_twocol_output:N}
%    \begin{macrocode}
\cs_new_protected:Npn \@@_patch_twocol_output:N #1
{
  \xpatchcmd{#1} {\normalcolor\vrule\@width\columnseprule}
  {\columnseprulecolor\mcruledivider}
  {\msg_info:nnn {multicolrule} {patch-success} {#1}}
  {\msg_info:nnn {multicolrule} {patch-failure} {#1}}
}
%    \end{macrocode}
%\end{function}
%
%    \begin{macrocode}
\bool_if:NTF \g_@@_twocolumn_bool
{
  \@ifpackageloaded{multicol}
  {\msg_warning:nn {multicolrule} {multicol-loaded}}{}
%    \end{macrocode}
% Provide the column-color macro from \pkg{multicol}.
%    \begin{macrocode}
  \cs_gset:Npn \columnseprulecolor {\normalcolor}
  \cs_gset:Npn \@@_column_height: {\box_ht:N \@outputbox}
  \cs_gset:Npn \@@_column_depth: {\box_dp:N \@outputbox}
  \@@_patch_twocol_output:N \@outputdblcol
%    \end{macrocode}
%
% Now patch the relevant code in |\@outputdblcol|, replacing the hard-coded
% rule with a macro that we can overwrite.
%
%    \begin{macrocode}
  \@@_patch_twocol_output:N \@outputdblcol
%    \end{macrocode}
%
% \pkg{bidi} has two output routines to patch, and it insists on being loaded
% after \pkg{xcolor}, \pkg{tikz}, \emph{and} \pkg{multicol}, so it must always
% be loaded after us. We use \cs{AfterPackage} from \pkg{scrlfile} to insert
% the patch if \pkg{bidi} is loaded later on.
%
%    \begin{macrocode}
  \AfterPackage!{bidi}
  {
    \@@_patch_twocol_output:N \RTL@outputdblcol
    \@@_patch_twocol_output:N \LTR@outputdblcol
  }
}
%    \end{macrocode}
%
% Now patch for \pkg{multicol}.
%
%    \begin{macrocode}
{
  \RequirePackage{multicol}
  \@@_patch_mcol_output:N \LR@column@boxes
  \@@_patch_mcol_output:N \RL@column@boxes
%    \end{macrocode}
%
% Although taking the height of \cmd{\mult@rightbox} is a reliable way
% to get the column height, the same isn't true for the depth, so we
% use |\dimen\tw@|, which \pkg{multicol} uses to hold the maximum
% depth of all the columns, instead.
%
%    \begin{macrocode}
  \cs_gset:Npn \@@_column_height: {\box_ht:N \mult@rightbox}
  \cs_gset:Npn \@@_column_depth: {\dimen\tw@}
%    \end{macrocode}
%
% We need to reissue \cs{LRmulticolcolumns} to update the actual code in
% \cmd{\mc@align@columns}.
%
%    \begin{macrocode}
    \LRmulticolcolumns
%    \end{macrocode}
%
% The \pkg{bidi} package supplies its own versions of most core
% \pkg{multicol} functions, including the output boxes. Much of this is
% unnecessary, as current versions of \pkg{multicol} support printing the
% columns in right-to-left order, and the effect is to leave the original
% \pkg{multicol} definitions loaded but unused. As a result, after these
% changes, the \pkg{multicol} commands \cs{LRmulticolcolumns} and
% \cs{RLmulticolcolumns} have no visible effect. But as \pkg{bidi} also
% reworks the footnotes extensively, it's easier just to patch the equivalent
% output routines rather than rewrite it properly.
%
%    \begin{macrocode}
  \AfterPackage!{bidi}
  {
    \cs_gset_eq:NN \LTR@column@boxes \LR@column@boxes
    \cs_gset_eq:NN \RTL@column@boxes \RL@column@boxes
%    \end{macrocode}
%
% While we're at it, we also redefine \cs{LRmulticolcolumns} and
% \cs{RLmulticolcolumns} so they work the way people expect them to.
%
%    \begin{macrocode}
    \cs_gset_eq:NN \LRmulticolcolumns \LTRmulticolcolumns
    \cs_gset_eq:NN \RLmulticolcolumns \RTLmulticolcolumns
  }
}
%    \end{macrocode}
% 
%
% \subsection{Creating the Rules}
% Utility functions for different rule types
%
%\begin{macro}{\mcruledivider}
%
% This is the function directly called by the patched output routines. It's
% given a \LaTeX2 name so the user can redefine it if necessary. Its main
% function is to call the internal function \cs{_@@_divider:}, which contains
% the actual rule-typesetting instructions, the number of times specified in
% \cs{l_@@_repeat_int}. We only call \cs{_@@_divider:} if \cs{columnseprule}
% $>0$, so that all line styles can be turned off by setting it to 0, just as
% is the case with the vanilla rules.
%
%    \begin{macrocode}
\cs_new:Npn \mcruledivider
{
  \bool_lazy_and:nnT
  {\dim_compare_p:nNn {\columnseprule} > {0pt}}
  {\int_compare_p:nNn {\l_@@_repeat_int} > {0}}
  {
    \@@_divider:
    \prg_replicate:nn {\l_@@_repeat_int - 1}
    {
      \hspace{\l_@@_repeat_distance_dim}
      \@@_divider:
    }
  }
}
%    \end{macrocode}
%\end{macro}
%
%\begin{function}{\@@_column_total_height:,\@@_column_total_depth:}
%
% Get column height and depth with any explicit alterations.
%
%    \begin{macrocode}
\cs_new:Npn \@@_column_total_height:
{
  \dim_eval:n {\@@_column_height: + \@@_column_depth: + 
    \@@_extend_column_top: + \@@_extend_column_bottom:}
}
\cs_new:Npn \@@_column_total_depth:
{
  \dim_eval:n {\@@_column_depth: + \@@_extend_column_bottom:}
}
%    \end{macrocode}
%\end{function}
%
%\begin{function}{\@@_extend_column_top:}
%
% Currently, the extend amount for the top is just the 
% |\l_@@_extend_top_dim| distance. In the future we may allow more complex
% criteria, such as by odd or even page, or on a particular page. Although
% these might theoretically be useful, I'm not going to implement them until
% someone comes along with a use-case for it.
%
%    \begin{macrocode}
\cs_new:Npn \@@_extend_column_top:
{
  \l_@@_extend_top_dim
}
%    \end{macrocode}
%\end{function}
%
%\begin{function}{\@@_extend_column_bottom:}
%
% The |extend-fill| option, which is only applicable with \pkg{multicol},
% extends the rule from the bottom of the column to the end of the text area,
% minus whatever reserved space the user specifies. If there's less space
% available than requested, we give everything we can.
%
%    \begin{macrocode}
\cs_new:Npn \@@_extend_column_bottom:
{
  \bool_lazy_and:nnTF
  {\bool_if_p:n {\l_@@_extend_fill_bool}}
  {\bool_not_p:n {\g_@@_twocolumn_bool}}
  {
    \dim_compare:nNnTF 
    {\@colroom - \@@_column_height: - \@@_extend_reserve:} > {0pt}
    {\@colroom - \@@_column_height: - \@@_extend_reserve:}
    {0pt}
  }
  {\l_@@_extend_bot_dim}
}
%    \end{macrocode}
%\end{function}
%
%\begin{function}{\@@_extend_reserve:}
%
% The reserved space is the amount of user-provided space we want, but we also
% have to account for the space added with \cs{multicolsep}.
%
%    \begin{macrocode}
\cs_new:Npn \@@_extend_reserve:
{
  \dim_compare:nNnTF {\l_@@_extend_reserve_dim} > {0pt}
  {\dim_eval:n {\l_@@_extend_reserve_dim + \multicolsep}}
  {0pt}
}
%    \end{macrocode}
%\end{function}
%
%\begin{function}{\@@_divider:}
% This is the internal routine that contains the instructions to draw one copy
% of rule between columns. The default is identical to the original definition
% used by \pkg{multicol}. It will be reset each time the user calls
% \cs{MCSetRule}.
%
%    \begin{macrocode}
\cs_new:Npn \@@_divider: {\vrule\@width\columnseprule}
%    \end{macrocode}
%\end{function}
%
%\begin{function}{\@@_pattern:nnn}
%  \begin{syntax}
%    |\__mcrule_pattern:nnn| \Arg{pattern} \Arg{space above} \Arg{space below}
%  \end{syntax}
% Typesets a single copy of a pattern, vertically centered, in a vertical
% box that is the height of the current column. The pattern must be
% something that can go in a horizontal box. The spaces above and below
% must be fixed dimensions. 
% 
%    \begin{macrocode}
\cs_new_nopar:Npn \@@_pattern:nnn #1#2#3
{
  \box_move_down:nn {\@@_column_total_depth:}
  {
    \vbox_to_ht:nn {\@@_column_total_height:}
    {
      \vfill
      \kern #2 \hbox:n{#1} \kern #3
      \vfill
    }
  }
}
%    \end{macrocode}
%\end{function}
%
%\begin{function}{\@@_tile_pattern:nnn}
%  \begin{syntax}
%    |\__mcrule_tile_pattern:nnn| \Arg{pattern} \Arg{space above} \Arg{space below}
%  \end{syntax}
% Typesets multiple copies of pattern, tiled so as to occupy a vertical box
% that is the height of the current column. The pattern must be something
% that can go in a horizontal box. The spaces above and below must be fixed
% dimensions. 
%    \begin{macrocode}
\cs_new_nopar:Npn \@@_tile_pattern:nnn #1#2#3
{
  \box_move_down:nn {\@@_column_total_depth:}
  {
    \vbox_to_ht:nn {\@@_column_total_height:}
    {
      \cleaders \vbox:n
      {
        \kern #2 \hbox:n{#1} \kern #3
      }
    \vfill
    }
  }
}
%    \end{macrocode}
%\end{function}
%
%\begin{function}{\@@_line_pattern:nnnn}
%  \begin{syntax}
%    |\__mcrule_line_pattern:nnnn| \Arg{tikz-name} \Arg{height} \Arg{space above}
%      \Arg{space below}
%  \end{syntax}
% This function can draw a line pattern using either a \pkg{tikz} name or
% directly (as a tiled pattern). The latter case is currently limited to line
% patterns that can be described in terms of a solid line of length
% \meta{height} separated by spaces above and/or below the line.
%    \begin{macrocode}
\cs_new:Npn \@@_line_pattern:nnnn #1#2#3#4
{
  \bool_if:NTF \g_@@_use_tikz_bool
  {
    \@@_pattern_line:n {#1}
  } 
  {
    \@@_tile_pattern:nnn {\rule{\columnseprule}{#2}}{#3}{#4}
  }
}
%    \end{macrocode}
%\end{function}
%
%\begin{function}{\@@_solid_line:}
% Unlike the default solid line, which is created with a simple \tn{vrule},
% this version allows us to extend the line beyond the natural space of the
% column.
%    \begin{macrocode}
\cs_new:Npn \@@_solid_line:
{
  \rule[-\@@_column_total_depth:]{\columnseprule}{\@@_column_total_height:}
}
%    \end{macrocode}
%\end{function}
%
% \subsubsection{Tikz-only Routines}
%
% If we're supporting \pkg{tikz}, make sure it's loaded and redefine the
% relevant functions. We turn off |expl3| syntax to load the package because
% \pkg{tikz} relies on 2e catcodes, especially for spaces.
%
%    \begin{macrocode}
\bool_if:NTF \g_@@_use_tikz_bool
{
  \ExplSyntaxOff
  \RequirePackage{tikz}
  \ExplSyntaxOn  
%    \end{macrocode}
% 
%\begin{function}{\@@_tikz_picture:n}
%  \begin{syntax}
%    |\__mcrule_tikz_picture:n| \Arg{draw function}
%  \end{syntax}
% Set up the \env{tikzpicture} environment and declare two nodes, named |(TOP)|
% and |(BOT)|. This way we can pass a \cs{draw} routine directly,
% without worrying about the line's coordinates.
%
%    \begin{macrocode}
\cs_set:Npn \@@_tikz_picture:n #1
{
  \begin{tikzpicture}[x=1pt,y=1pt,inner~sep=0pt,outer~sep=0pt,
    baseline={([yshift=\@@_column_total_depth:]current~bounding~box.south)}]
  \node (TOP) at (0,\@@_column_total_height:) {};
  \node (BOT) at (0,0) {};
  #1
    \end{tikzpicture}
}
%    \end{macrocode}
%\end{function}
%
%\begin{function}{\@@_pattern_line:n}
%  \begin{syntax}
%    |\__mcrule_pattern_line:n| \Arg{tikz pattern}
%  \end{syntax}
% For the \pkg{tikz} versions of the predefined lines, we just draw
% a line the length of the column box. \meta{tikz pattern} should 
% contain the name of a line style that \pkg{tikz} recognizes.
%
%    \begin{macrocode}
\cs_set:Npn \@@_pattern_line:n #1
{
  \begin{tikzpicture}[x=1pt,y=1pt,inner~sep=0pt,outer~sep=0pt,
    baseline={([yshift=\@@_column_total_depth:]current~bounding~box.south)}]
  \draw[line~width=\columnseprule,#1] (0,\@@_column_total_height:) -- (0,0);
  \end{tikzpicture}
}
%    \end{macrocode}
%\end{function}
%
%\begin{function}{\@@_circle:}
% Draw a hollow circle with a diameter equal to |\columnseprule|. This will be
% used as a tile pattern.
%
%    \begin{macrocode}
  \cs_set:Npn \@@_circle: 
  {
    \begin{tikzpicture}[x=1pt,y=1pt,inner~sep=0pt,outer~sep=0pt]
    \draw (0,0) circle[radius=.5\columnseprule];
    \end{tikzpicture}
  }
%    \end{macrocode}
%\end{function}
%
%\begin{function}{\@@_solid_circle:}
% Draw a filled circle with a diameter equal to |\columnseprule|. This will be
% used as a tile pattern.
%
%    \begin{macrocode} 
  \cs_set:Npn \@@_solid_circle: 
  {
    \begin{tikzpicture}[x=1pt,y=1pt,inner~sep=0pt,outer~sep=0pt]
    \fill (0,0) circle[radius=.5\columnseprule];
    \end{tikzpicture}
  } 
}
%    \end{macrocode}
%\end{function}
%
% In case \pkg{tikz} functions are not active, we provide stubs
% that issue error messages.
%
%    \begin{macrocode}
{
  \cs_set:Npn \@@_tikz_picture:n #1
    {\msg_error:nnn {multicolrule} {tikz-required} {#1}}
  \cs_new:Npn \@@_pattern_line:n #1
    {\msg_error:nnn {multicolrule} {tikz-required} {#1}}
  \cs_new:Npn \@@_circle: 
    {\msg_error:nnn {multicolrule} {tikz-required} {circles}}
  \cs_new:Npn \@@_solid_circle: 
    {\msg_error:nnn {multicolrule} {tikz-required} {solid-circles}}
}
%    \end{macrocode}
%
% \subsection{Color}
%\begin{function}{\@@_set_rule_color:}
% Reset color definition in \cs{columnseprulecolor} by name or
% by model and color specification.
%
%    \begin{macrocode}
\cs_new_protected:Npn \@@_set_rule_color:
{
  \tl_if_empty:NT \l_@@_color_name_tl
  {
    \tl_set:Nn \l_@@_color_name_tl {black}
  }
  \tl_if_empty:NTF \l_@@_color_model_tl
  {
    \cs_set:Npn \columnseprulecolor {\color{\l_@@_color_name_tl}}
  }
  {
    \cs_set:Npn \columnseprulecolor 
    {\color[\l_@@_color_model_tl]{\l_@@_color_name_tl}}
  }
}
%    \end{macrocode}
%\end{function}
%
% \subsection{Key-Values}
% Set up all the key definitions. For the line styles, this involves
% resetting \cs{_@@_divider:} to an appropriate value.
%
%    \begin{macrocode}
\keys_define:nn {mcrule}
{
  extend-top                       .dim_set:N  = \l_@@_extend_top_dim,
  extend-bot                       .dim_set:N  = \l_@@_extend_bot_dim,
  extend-fill                      .bool_set:N = \l_@@_extend_fill_bool,
  extend-fill                      .default:n = true,
  extend-reserve                   .dim_set:N  = \l_@@_extend_reserve_dim,
  line-style                       .choice:,
  line-style / default             .code:n = \cs_set:Npn \@@_divider: 
    {\vrule\@width\columnseprule},
  line-style / solid               .code:n = \cs_set:Npn \@@_divider: 
    {\@@_solid_line:},
  line-style / dots                .code:n = \cs_set:Npn \@@_divider:
    {\@@_tile_pattern:nnn {.}{1pt}{1pt}},
  line-style / dense-dots          .code:n = \cs_set:Npn \@@_divider: 
    {\@@_tile_pattern:nnn {.}{1pt}{0pt}},
  line-style / loose-dots          .code:n = \cs_set:Npn \@@_divider:
    {\@@_tile_pattern:nnn {.}{2pt}{2pt}},
  line-style / circles             .code:n = \cs_set:Npn \@@_divider: 
    {\@@_tile_pattern:nnn {\@@_circle:}{1pt}{1pt}},
  line-style / dense-circles       .code:n = \cs_set:Npn \@@_divider:
    {\@@_tile_pattern:nnn {\@@_circle:}{1pt}{0pt}},
  line-style / loose-circles       .code:n = \cs_set:Npn \@@_divider: 
    {\@@_tile_pattern:nnn {\@@_circle:}{2pt}{2pt}},
  line-style / solid-circles       .code:n = \cs_set:Npn \@@_divider: 
    {\@@_tile_pattern:nnn {\@@_solid_circle:}{1pt}{1pt}},
  line-style / dense-solid-circles .code:n = \cs_set:Npn \@@_divider:
    {\@@_tile_pattern:nnn {\@@_solid_circle:}{1pt}{0pt}},
  line-style / loose-solid-circles .code:n = \cs_set:Npn \@@_divider:
    {\@@_tile_pattern:nnn {\@@_solid_circle:}{2pt}{2pt}},
  line-style / dotted              .code:n = \cs_set:Npn \@@_divider: 
    {\@@_line_pattern:nnnn {dotted}{\columnseprule}{1pt}{1pt}},
  line-style / densely-dotted      .code:n = \cs_set:Npn \@@_divider:
    {\@@_line_pattern:nnnn {densely~dotted}{\columnseprule}{1pt}{0pt}},
  line-style / loosely-dotted      .code:n = \cs_set:Npn \@@_divider:
    {\@@_line_pattern:nnnn {loosely~dotted}{\columnseprule}{2pt}{2pt}},
  line-style / dashed              .code:n = \cs_set:Npn \@@_divider:
    {\@@_line_pattern:nnnn {dashed}{3pt}{1.5pt}{1.5pt}},
  line-style / densely-dashed      .code:n = \cs_set:Npn \@@_divider:
    {\@@_line_pattern:nnnn {densely~dashed}{3pt}{1pt}{1pt}},
  line-style / loosely-dashed      .code:n = \cs_set:Npn \@@_divider: 
    {\@@_line_pattern:nnnn {loosely~dashed}{3pt}{3pt}{3pt}},
  line-style / dash-dot            .code:n = \cs_set:Npn \@@_divider:
    {\@@_pattern_line:n{dash~dot}},
  line-style / densely-dash-dot    .code:n = \cs_set:Npn \@@_divider: 
    {\@@_pattern_line:n{densely~dash~dot}},
  line-style / loosely-dash-dot    .code:n = \cs_set:Npn \@@_divider:
    {\@@_pattern_line:n{loosely~dash~dot}},
  line-style / dash-dot-dot         .code:n = \cs_set:Npn \@@_divider:
    {\@@_pattern_line:n{dash~dot~dot}},
  line-style / densely-dash-dot-dot .code:n = \cs_set:Npn \@@_divider:
    {\@@_pattern_line:n{densely~dash~dot~dot}},
  line-style / loosely-dash-dot-dot .code:n = \cs_set:Npn \@@_divider:
    {\@@_pattern_line:n{loosely~dash~dot~dot}},
  color                             .code:n = {
    \tl_set:Nn \l_@@_color_name_tl {#1}
    \@@_set_rule_color:
  },
  color-model                       .code:n = {
    \tl_set:Nn \l_@@_color_model_tl {#1}
    \@@_set_rule_color:
  },
  custom-line         .code:n = \cs_set:Npn \@@_divider:
    {\@@_tikz_picture:n {#1}},
  custom-pattern      .code:n = \cs_set:Npn \@@_divider:
    {\@@_pattern:nnn #1},
  custom-tile         .code:n = \cs_set:Npn \@@_divider:
    {\@@_tile_pattern:nnn #1},
  width               .choice:,
  width / ultra-thin  .code:n = \dim_set:Nn \columnseprule {0.1pt},
  width / very-thin   .code:n = \dim_set:Nn \columnseprule {0.2pt},
  width / thin        .code:n = \dim_set:Nn \columnseprule {0.4pt},
  width / semithick   .code:n = \dim_set:Nn \columnseprule {0.6pt},
  width / thick       .code:n = \dim_set:Nn \columnseprule {0.8pt},
  width / very-thick  .code:n = \dim_set:Nn \columnseprule {1.2pt},
  width / ultra-thick .code:n = \dim_set:Nn \columnseprule {1.6pt},
  width / unknown     .code:n = {\dim_set:Nn \columnseprule {#1}},
  repeat              .int_set:N = \l_@@_repeat_int,
  repeat-distance     .dim_set:N = \l_@@_repeat_distance_dim,
  single              .meta:n = {
    repeat = 1,
    repeat-distance = #1
  },
  single              .default:n = \columnseprule,
  double              .meta:n = {
    repeat = 2,
    repeat-distance = #1
  },
  double              .default:n = \columnseprule,
  triple              .meta:n = {
    repeat = 3,
    repeat-distance = #1
  },
  triple              .default:n = \columnseprule,
}
%    \end{macrocode}
%
% \subsection{User Interface}
% With only one command, this section is short. All we do is set whatever keys
% the user passes. All the real work is done in the definitions above.
%
%\begin{macro}{\SetMCRule}
%\begin{syntax}
%  |\SetMCRule| \marg{key-value list}
%\end{syntax}
%    \begin{macrocode}
\NewDocumentCommand{\SetMCRule}{m}
{
  \keys_set:nn {mcrule} {#1}
}
%    \end{macrocode}
%\end{macro}
%
%\end{implementation}
%
% \PrintChanges
%
% \newpage
%
% \PrintIndex