3

In my code, I change to '2 columns' mode typing:

\twocolumn[{

I'm trying to simplify this code, by creating a new command:

\renewcommand{\twocolumn}{\twocolumn[{}

Is this possible to insert a bracket and a brace in this new command? I'm getting a lot of errors doing this.

  • 3
    My only question: Why do you want to do this? It looks weird ;-) – user31729 Jul 29 '15 at 16:43
  • 1
    Why do you use \twocolumn[{...}] instead of \twocolumn[...]? – user2478 Jul 29 '15 at 16:44
  • 2
    @ChristianHupfer +1. An answer seems to be beyond my imagination. :-) – Przemysław Scherwentke Jul 29 '15 at 16:46
  • 1
    @PrzemysławScherwentke: It could be possible with Plain TeX or with xparse approach, but I still don't know why this should be useful. Thanks ;-) – user31729 Jul 29 '15 at 16:48
  • 1
    @Herbert Perhaps there's an optional argument inside the [] pair: as already noted, xparse would help with that. – Joseph Wright Jul 29 '15 at 16:49
9

The sequence

\renewcommand{\twocolumn}{\twocolumn[{}

would define a commmand \twocolumn that - among other things - would call itself. You would get some sort of recursive loop where compilation might terminate with an error message TeX capacity exceeded or the like when during recursion too many opening brackets and opening braces got accumulated.

Besides this \twocolumn is a macro that might be used within macro-packages and the like. Redefining it might lead to problems with (package-)code where it is relied on the original meaning of \twocolumn.

Perhaps defining your own macro for calling \twocolumn might be an option:

\makeatletter
\newcommand\calltwocolumn{%
  \expandafter\twocolumn
  \expandafter[%
  \expandafter{%
  \romannumeral0\expandafter\@gobble\string} %
}%
\makeatother

The command \calltwocolumn would yield the following tokens:

  \expandafter\twocolumn
  \expandafter[%
  \expandafter{%
  \romannumeral0\expandafter\@gobble\string} %

The \expandafter-chain would turn on \romannumeral-expansion before \twocolumn would get carried out. \romannumeral-expansion in turn would lead to stringifying and gobbling the closing brace before terminating without delivering any token.

Some people are reluctant when it comes to using \makeatletter. You can avoid that using \csname:

\newcommand\calltwocolumn{%
  \expandafter\twocolumn
  \expandafter[%
  \expandafter{%
  \romannumeral0\csname @gobble\expandafter\endcsname\string} %
}%

You can as well avoid that using \iffalse as suggested by Gustavo Mezzetti:

\newcommand\calltwocolumn{%
  \expandafter\twocolumn
  \expandafter[%
  \expandafter{%
  \iffalse}\fi
}%
  • 2
    Clever trick; but the classic \iffalse }\fi (cf. The TeXbook, exercise 20.17) could be used instead of \romannumeral0…, couldn’t it? – GuM Jul 29 '15 at 22:32
  • Is there a tip to simplify }]\endtwocolumn assuming that \endtwocolumn is already defined? – Fabricio Pio Jul 30 '15 at 2:13
  • Well, in this case (1) \iffalse is properly paired with its \fi, and (2) the whole pair is buried inside a macro, which is either expanded or not (tertium non datur :-) . – GuM Jul 30 '15 at 10:01
  • @UlrichDiez: can you provide a solution do the tail of the code? How can I do }]/endtwocolumn eliminating the braces and brackets? – Fabricio Pio Jul 31 '15 at 21:03

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.