20

I'm currently looking at various questions related to multicol and try giving answers to some of them. Often enough the answer would involve patching \balance@columns or similar macros and in that case \patchcmd from etoolbox fails because there are newline characters in the macro, e.g.,

       \message{^^JColumn
          \number\@tempcnta\space
           badness: \the\badness\space}%

Now, I can of course add the whole definition of \balance@columns to my answer, but this command has 165 lines, so I would rather like to avoid this.

Is there any easy way to patch nevertheless (or get rid of the ^^J from the outside) that I'm missing?

21

Not sure why ^^J is a problem, isn't it only special as \newlinechar when stuff is being used in \write ?

\documentclass{article}

\def\zz{aaa^^Jbbb \foo ccc}

\def\patchzz#1\foo#2\zzz{\def\zz{#1\bar#2}}

\show\zz
\expandafter\patchzz\zz\zzz

\show\zz



\stop

ah if \patchcmd uses \scantokens that is a write, so you probably just want to locally reset \newlinechar.

An example with etoolbox (From Joseph:-)

\documentclass{article}
\usepackage{etoolbox}
\tracingpatches
\usepackage{multicol}
\makeatletter
\show\balance@columns
\edef\reset@newlinechar{\newlinechar\the\newlinechar}
\newlinechar-1 %
\patchcmd{\balance@columns}
  {\ifshr@nking \vfill \fi}
  {\CHANGED}
  {}
  {}
\show\balance@columns
\reset@newlinechar
  • 8
    Cool; I know it should have been easy, so that is how you gain reputation, stealing from @JosephWright :-) – Frank Mittelbach Sep 1 '13 at 17:11
8

You can use regexpatch:

\documentclass{article}
\usepackage{regexpatch}
\tracingxpatches
\usepackage{multicol}
\makeatletter
\show\balance@columns
\xpatchcmd{\balance@columns}
  {\ifshr@nking \vfill \fi}
  {\CHANGED}
  {}
  {}
\show\balance@columns

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.