0

I'm still on my way to my key:value table, and this time, I'm trying to alias [\normalbaselineskip] to \\. I still want to use the standard \\. What I want is to consider \\ as [\normalbaselineskip] only if it follows directly (without space) another \\. Typically, if I type \\\\ in the tabularx environment below, the first needs to be interpreted as a standard \\ and the second as [\normalbaselineskip]. Where things goes tricky is that I want, if possible, to restrict the scope of that \\\\ alias only to this tabularx (keyvalue) environment.

\documentclass{report}
\usepackage[margin=2cm]{geometry}
\linespread{1.2}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{float}
\newenvironment{keyvalue}
{\tabularx{\textwidth}{X@{ : }X}}
{\endtabularx}
\begin{document}
\begin{keyvalue}
    Foo bar lorem ipsum           & Lorem ipusm que \\
    Some number                   & 12 3456 789  8  \\
    \multicolumn{2}{l}{This is some comment}        \\[\normalbaselineskip]
    Yet some number               & 987 65432 1     \\
    Foo bar                       & 163883495778    \\[\normalbaselineskip]
    Bar lorem ipsum               & 2013-04-12      \\
\end{keyvalue}
\end{document}

Thanks in advance for your help.

wget
  • 782
  • The main intent here is to avoid the printing of :, correct? – Werner Feb 09 '15 at 00:09
  • Sounds confusing to me. Why not just use a macro? That's what they're for, after all. Something like \newcommand{\wget}{\\[\normalbaselineskip]}.... – jon Feb 09 '15 at 00:09
  • \newcommand{\wgetbreak}{\addlinespace[\normalbaselineskip]} and add \wgetbreak after \\ where you want more space. – egreg Feb 09 '15 at 00:14
  • @Werner This isn't the subject of this question, but yes, one of the intend of \multicolumn{2}{l}{This is some comment} is to avoid the colon : to be printed when there is only one element in the row. – wget Feb 09 '15 at 07:50
  • @jon @egreg Creating an alias/macro is the purpose of this question ;-) If you read correctly, I don't want to have a new command like \wget or \wgetbreak which I could have defined by myself, but \\ instead which doesn't conflict with the existing \\ meaning. – wget Feb 09 '15 at 07:55
  • I understand the 'want', but I don't get the 'why'? For fun? Or will it actually do anything that a macro cannot? – jon Feb 09 '15 at 08:56
  • @jon: the 'why' is just because it is more convenient for the user who will use my class file. I tried with \renewcommand{\\}{\[\normalbaselineskip]} but I've got unexpected errors: Undefined control sequence. \renewcommand{\\} TeX capacity exceeded, sorry [input stack size=5000]. \renewcommand{\\} I even tried with \let to avoid loops. But no result. – wget Feb 09 '15 at 09:04
  • 1
    a command may consist only of one escape character (ordinarily \\) and either (a) any number of letters, or (b) only one non-letter. since you can't redefine \ to be a letter, trying to redefine \\\\ is simply impossible. – barbara beeton Feb 09 '15 at 13:21
  • Aside from the impossibility, you might consider whether it is a good coding practice. Tastes differ, of course, but (to me) what you would gain in 'convenience' does not compensate for the lost readability of the input file. If a user thinks she can write \\ or \\\\, then might she not then want \\\\\\? (or, why not: \\\\\?) Macros can have relatvely intuitive and meaningful names like booktabs' \addlinespace -- which is also useful when you revisit a file several years later because \addlinespace has a pretty unambiguous meaning that your collection of slashes mostly lacks. – jon Feb 10 '15 at 03:31

1 Answers1

1

As mentioned in the comments to the question, defining a new command as \\\\ is impossible, because redefining \ conflicts with the existing meaning of \ used as an escape sequence.

Even if \\\\ seems to be more convenient to type instead of \\[\normalbaselineskip], this is not a good coding practise (loss of readability). Use cases like adding more backslashes should have been handled with care too, increasing the risk to have an infinite loop, like I experienced.

A compromise I made was to use a macro, like proposed, but a shorter one: \x.

Here is the new definition of the keyvalue environnement I have:

\newenvironment{keyvalue}
{%
    \newcommand{\x}{\\[\normalbaselineskip]}%
    \begin{longtabu} to \textwidth {X@{ : }X}%
}
{\end{longtabu}}

Yes, in the meantime, I migrated from tabularx to tabu allowing long tables (like the package longtable, but with way more features to it).

wget
  • 782