# Weird error : use of [ ] in array [duplicate]

I was trying to use some commutators in an array when I found this error :

! Missing number, treated as zero. a l.9 [a] A number should have been here; I inserted '0'. (If you can't figure out why I needed to see a number, look up 'weird error' in the index to The TeXbook.)

! Illegal unit of measure (pt inserted). Dimensions can be in units of em, ex, in, pt, pc, cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one! I'll assume that you meant to say pt, for printer's points. To recover gracefully from this error, it's best to delete the erroneous units; e.g., type 2' to delete two letters. (See Chapter 27 of The TeXbook.)

! Missing = inserted for \ifdim. I was expecting to see '<', '=', or '>'. Didn't.

With the following code :

\documentclass{article}

\usepackage[english]{babel}

\begin{document}

$$\begin{array}{c} first ligne\\ [second ligne] \end{array}$$

\end{document}


The code creates a pdf with some text on the second page and some black space on the right of it. It does compute well when you remove the left bracket [, or when you use the brackets on the first ligne.

Is this related with a \\ [ on two consecutive lines ?

## marked as duplicate by Werner tables StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Mar 29 '18 at 0:18

• First of all: Don't use $$...$$. – user31729 Mar 29 '18 at 0:01

The

 \\
[second ligne]


is read as \$second ligne], which is then interpreted as length specification of additional vertical spacing, consisting of second ligne here, which is no length, of course. The main reason for this interpretation is that there is no real line break after \\ here. One possible solution: Insert an empty line between \\ and [, if the [...] is mandatory for your purpose. A better solution is to hide the [] pair in a macro, this would allow for logical markup in addition. Side note: Don't use ..., since that is deprecated syntax for almost 25 years now. Use \[...$ or $...$ instead.

\documentclass{article}

\usepackage[english]{babel}

\begin{document}

$\begin{array}{c} first ligne\\ [second ligne] \end{array}$

\end{document}


Better solution:

\documentclass{article}

\usepackage[english]{babel}

\newcommand{\bracketed}[1]{[#1]}

\begin{document}

$\begin{array}{c} x^{2}\\ \bracketed{x^{3}} \end{array}$

\end{document}


This happens because the command \\ can have an optional argument: \\[<dimen>], where <dimen> is the vertical space to be skipped.

And when the next line begins with [, TeX thinks that what comes after is a dimension, thus the Missing number, treated as zero.

You can tell the \\ command that it doesn't have an optional argument by telling it to \relax:

\documentclass{article}

\usepackage[english]{babel}

\begin{document}

$$\begin{array}{c} first ligne\\\relax [second ligne] \end{array}$$

\end{document}


egreg recently posted an answer on why xparse` doesn't accept optional arguments on a new line, an this is exactly the reason.

• This is basically the same solution as Christian Hupfer's, except that I use a different way to trick TeX. You should accept his answer. – Phelype Oleinik Mar 29 '18 at 0:13
• By refusing to get accepted you won't get to 8888 very soon :-P – user31729 Mar 29 '18 at 0:15
• Is this a challenge? I passed you in this month's ranking, hehe ;-) – Phelype Oleinik Mar 29 '18 at 0:19
• Well, I can't sit at my desk all the while (like many seem to do so here) when being in front of students and teaching them ;-) And I've lost some of my supporting voters, since they left TeX.SE... A challenge, no, it isn't. – user31729 Mar 29 '18 at 0:21
• Sorry, I was just kidding... – Phelype Oleinik Mar 29 '18 at 0:26