# Why does this patch to multicol have no effect?

Update 19/12/18: I've now turned this into a full package to manage decorative rules, called multicolrule.

I was trying to extend the solutions here and here, which replace the ordinary rule between multicolumn text with a dotted line, in order to substitute arbitrary patterns for the line, whether that's a solid rule, a dotted line, or something else. Although I have a working solution to this, my first attempt did not work, and I would like to understand why.

My first attempt was to use xpatch to rewrite \LR@column@boxes and \RL@column@boxes like this:

\xpatchcmd{\LR@column@boxes}
{\vrule\@width\columnseprule}
{\multicoldivider}
{\typeout{Patched \string\LR@column@boxes}}{\typeout{Error patching \string\LR@column@boxes}}

My intention was to replace the part where the rule is typeset with my own function, leaving \columnseprulecolor intact. Although the log indicates that the patch was successful, and \show\LR@column@boxes shows that revised macro has the right code, this change, no effect. If \columnseprule is set to a non-zero value, an ordinary solid rule appears. I tried a similar patch on \@outputdblcol for the twocolumn setting without multicol, and that worked just fine.

I achieved the end-result I wanted by adapting the method David Carlisle used in his answer to this question, but I am mystified as to why xpatch did nothing here.

The MWE shows both the working and non-working attempts.

\documentclass{article}
%\documentclass[twocolumn]{article}
\usepackage{multicol}
\usepackage{xpatch}
\usepackage{lipsum}
\usepackage{xcolor}

\newcommand*{\myrulecolor}{\color{red}}
\makeatletter

\newcommand*{\multicoldivider}{\myrulecolor\myrule}

\newcommand*{\dottedline}{%
}

\newcommand*{\myrule}{\dottedline}

\newcommand*{\solidline}{\vrule\@width .5pt}

\newcommand*{\setruletype}[1]{%
\renewcommand*{\myrule}{#1}
}

% This patch works for default twocolumn mode
\xpatchcmd{\@outputdblcol}
{\vrule\@width\columnseprule}
{\multicoldivider}
{\typeout{Patched \string\@outputdblcol}}{\typeout{Error patching \string\@outputdblcol}}

% This redefinition works for multicol
\newcommand*{\ruleredef}{%
\def\columnseprulecolor\vrule\@width\columnseprule{\multicoldivider}%
}

% These patches to multicol have no effect
\xpatchcmd{\LR@column@boxes}
{\columnseprulecolor\vrule\@width\columnseprule}
{\multicoldivider}
{\typeout{Patched \string\LR@column@boxes}}{\typeout{Error patching \string\LR@column@boxes}}

\xpatchcmd{\RL@column@boxes}
{\columnseprulecolor\vrule\@width\columnseprule}
{\multicoldivider}
{\typeout{Patched \string\RL@column@boxes}}{\typeout{Error patching \string\RL@column@boxes}}

\makeatother

\begin{document}

% Patched but no dotted rule
\begin{multicols}{2}
\lipsum[1]
\end{multicols}

\ruleredef
\begin{multicols}{2}
\lipsum[1]
\end{multicols}

\renewcommand*{\myrulecolor}{\color{green}}
\setruletype{\solidline}
\begin{multicols}{2}
\lipsum[1]
\end{multicols}
\end{document}

Output:

• moral of the story, always do what I say? – David Carlisle Dec 12 '18 at 20:38

multicol.sty does

\newcommand\RLmulticolcolumns
{\let\mc@align@columns
\RL@column@boxes}
\newcommand\LRmulticolcolumns
{\let\mc@align@columns
\LR@column@boxes}
\LRmulticolcolumns

so you have to reissue \LRmulticolcolumna:

\documentclass{article}
\usepackage{multicol}
\usepackage{xpatch}
\usepackage{lipsum}
\usepackage{xcolor}

\newcommand*{\myrulecolor}{\color{red}}

\makeatletter
\newcommand*{\multicoldivider}{\myrulecolor\myrule}
\newcommand*{\dottedline}{%
}
\newcommand*{\myrule}{\dottedline}
\newcommand*{\solidline}{\vrule\@width .5pt}
\newcommand*{\setruletype}[1]{%
\renewcommand*{\myrule}{#1}
}
\xpatchcmd{\LR@column@boxes}
{\columnseprulecolor\vrule\@width\columnseprule}
{\multicoldivider}
{}{}
\xpatchcmd{\RL@column@boxes}
{\columnseprulecolor\vrule\@width\columnseprule}
{\multicoldivider}
{}{}
\LRmulticolcolumns
\makeatother

\begin{document}

\begin{multicols}{2}
\lipsum[1]
\end{multicols}

\end{document}