# How can we swap columns in two-column regime preserving hyperlinks?

Please save your time and energy on this question, some solutions exist.

I have been helping with Arabic-English (right-to-left typesetting) and English-Arabic (left-to-right typesetting) indices typesetted in one document, see more in Switch twocolumn between right-to-left and left-to-right with the package multiind in polyglossia. How to rearrange columns to have the first column on right side and the second column on left side in two-column regime preserving clickable cross-references and index page numbers?

I enclose a basic scheme, it runs on all major latex engines.

% run: *latex mal-cols.tex
\documentclass[a4paper]{article}
\parindent=0pt
\newcount\maltemp
\usepackage{multicol}
\usepackage{kantlipsum}
\def\textbonus{{\normalsize\kant[1-5]}}
\begin{document}
\columnseprule=3pt
Regular page in one-column regime...
\newpage
\begin{multicols}{2}
\textbonus
\loop
\the\maltemp\par
\ifnum\maltemp<130\repeat
\end{multicols}
\end{document}


• shouldn't the built in \beginR \endR primitives swap the columns without you having to move columns "by hand" ? – David Carlisle Apr 17 '14 at 12:53
• @David Carlisle It wasn't working for me in two-column regime as Arabic typesetting rules were loaded in the preamble. But it is likely I've overlooked and I am still missing some feature. – Malipivo Apr 17 '14 at 12:56
• It looks that the bidi package (luabidi, perhaps too?) is offering a solution out of the box (untested). – Malipivo Apr 24 '14 at 18:09

This question and its answers might help (I didn't study it in detail). I was lucky in this question because OP didn't want to have index page numbers in index at all, but how to do that in case she would? Technically we typesetted small dictionaries of terms, not two independent indices.

There is a proposal to use the flowfram package and my solution which uses two separate documents which are combined together later. This solution wouldn't work in case of clickable index page numbers. The hyperlinks would be gone if we used \includepdf (that's a command from the pdfpages package) or \includegraphics (that's a command from the graphicx package).

I was thinking to save current position in the document (\pdfsavepos from pdfTeX) of every index entry by wrapping the \item command at a xindy level. After that it would be possible to decide if to typeset index entry shifted to right or left side or even jump to some other location on the current page (it's just a theoretical situation when shifting and swapping 3+ columns), e.g. by using the \makebox command. It would be possible but not effective.

I started to think about moving the columns as they are. When I used \oddsidemargin, and \evensidemargin eventually, shifted by \columnwidth+\columnsep, it moved the left columns to the right position. Then I changed the \columnsep dimension (right columns moved in front of the left columns) and I've got a solution with one remaining problem: we needed to fix header and footer which were also shifted. It could be done. I continued in my experiments and I used \leftskip and \rightskip instead of \oddsidemargin. I believe this is a solution but I haven't tested that in practice, yet. The two columns are swapped and if there were hyperlinks they would have worked.

I enclose an example and a preview of 5+5 pages: 5 pages with common two-column regime (the first row of pictures), the other 5 pages with swapped columns (the second row of pictures).

% run: *latex mal-columns.tex
\documentclass[a4paper]{article}
%\pagestyle{empty}
\parindent=0pt
\usepackage{multicol}
%\newdimen\oldoddsidemargin
%\oldoddsidemargin=\oddsidemargin
\newdimen\oldcolumnsep
\oldcolumnsep=\columnsep
\newcount\maltemp
\newdimen\dimtemp
\usepackage{kantlipsum}
\def\textbonus{{\normalsize\kant[1-5]}}
\columnseprule=3pt

\begin{document}
Regular page in one-column regime...

\newpage
%This is a common typesetting...
\begin{multicols}{2}
%\typeout{\the\columnwidth,\the\columnsep}%
\textbonus
\loop
\the\maltemp\par
\ifnum\maltemp<130\repeat
%\columnbreak
\end{multicols}
% Measuring dimensions...
\newpage
\begin{multicols}{2}
%\typeout{\the\columnwidth, \the\columnsep}%
\dimtemp=\columnwidth
\global\leftskip=\dimtemp
\global\rightskip=\dimtemp
\end{multicols}

% Columns reversed...
\columnsep=-2\textwidth
\maltemp=0
\begin{multicols}{2}
\textbonus
\loop