3

I want to write a switch that puts my Document into "landscape-mode". If active I want to redefine the multicols environment to do nothing, but I also don't want to loose it for good, since I want to put the whole document in a "persistent" multicols environment..

\documentclass{article}
\usepackage[a5paper, landscape, left=1cm, right=1cm, top=2cm, bottom=2cm]{geometry}
\usepackage{xparse}
\usepackage{lipsum}
\usepackage{multicol}

\let\persistentMulticols\multicols
\let\endpersistentMulticols\endmulticols

% let multicols do nothing
\RenewDocumentEnvironment{multicols}{ m }{}{}

\begin{document}
    \begin{persistentMulticols}{2}
        \lipsum[66]
        \begin{multicols}{2}
            \lipsum[67]
        \end{multicols}
        \lipsum[1-2]
    \end{persistentMulticols}
\end{document}
josh
  • 174
  • I've looked at this answer, didn't help. I'm confused why the above MWE gives me \begin{persistentMulticols} on input line 14 ended by \end{multicols}. – josh Jun 06 '20 at 14:57
  • I know I could define an environment for the "inner" multicols which I could "turn off", but I want to try the other way first before changing a lot of my code. – josh Jun 06 '20 at 15:02

1 Answers1

2

The (original) \endmulticols contains \@checkend{multicols}, which is the cause of your problem. You need to patch \endpersistentMulticols so it uses the new name.

\documentclass{article}
\usepackage[a5paper, landscape, left=1cm, right=1cm, top=2cm, bottom=2cm]{geometry}
\usepackage{xparse}
\usepackage{lipsum}
\usepackage{multicol,xpatch}

\let\persistentMulticols\multicols
\let\endpersistentMulticols\endmulticols
\makeatletter
\xpatchcmd{\endpersistentMulticols}
  {\@checkend{multicols}}
  {\@checkend{persistentMulticols}}
  {}{}
\makeatother

% let multicols do nothing
\renewenvironment{multicols}[2][]{\ignorespaces}{\ignorespacesafterend}

\begin{document}
    \begin{persistentMulticols}{2}
        \lipsum[66]
        \begin{multicols}{2}
            \lipsum[67]
        \end{multicols}
        \lipsum[1-2]
    \end{persistentMulticols}
\end{document}
egreg
  • 1,121,712
  • Ah, so I have to look at each environments definition if i want to copy it successfully, how can I do that? – josh Jun 06 '20 at 15:33
  • 1
    @josh This check is not done by most environments, but multicols has to do a few devious things in order to work. – egreg Jun 06 '20 at 15:40