Okay, brand new to LaTeX.
Starting with a super simple example.
What's up with the arbitrary whitespace placement, and what can be done to fix it? enter image description here


Find the value of: M=x(\neg{y}+yz), if (x, y, z)=(1, 0, 0)


To illustrate:

  • Yellow - Normal spacing.
  • Magenta - Normal non-spacing.
  • Green - Forced spacing.
  • Blue - Forced non-spacing. enter image description here

No linebreaks:

This is what it looks like when I try to add a \\, \newline, \linebreak, etc. enter image description here


Find the value of: \\
M=x(\neg{y}+yz), if (x,y,z)=(1,0,0)

  • 3
    You are not using the standalone class as it should be used. To allow line breaks in standalone you can use the varwidth option: \documentclass[border=10mm,varwidth]{standalone}. – Phelype Oleinik Jun 30 '18 at 20:59
  • 7
    You should get an error from this code about missing $. As long as your document compiles with errors, there is no point in looking at the output. Suggestion: Find the value of: $M=x(\neg{y}+yz)$, if $(x, y, z)=(1, 0, 0)$ – user36296 Jun 30 '18 at 20:59
  • 5
    never ignore error messages, after an error message tex does not try to make reasonable pdf output, if you scroll past the error it just recovers enough to syntax check more of the document. – David Carlisle Jun 30 '18 at 21:49

To typeset your example more beautifully, I recommend the following approach:


Find the value of:
\[ M = x (\neg{y} + yz) \text{, if } (x, y, z) = (1, 0, 0) \]


\text{} originates from the amsmath package. It allows you to typeset normal flowtext within a mathematics environment. The mathematics environment is begun with \[ and ends with \]. Credit for recommending varwidth goes to @Phelype Oleinik's comment.

rendered example code

Another way is to use $ to begin and stop the mathematics environment. As it does not introduce a new line, I left the linebreak \\ on the previous line:


Find the value of:
$M = x (\neg{y} + yz)$, if $(x, y, z) = (1, 0, 0)$


rendered display-style example code

  • 1
    perhaps a bit simpler to avoid display mode, as per @samcarter 's comment above? – Thruston Jun 30 '18 at 21:55
  • @Thruston I extended my answer - thx. – meisterluk Jun 30 '18 at 22:21
  • 1
    Hmmm, I'd drop the \text and go with two sets of $ marks, as in the original comment above. – Thruston Jun 30 '18 at 22:27
  • 2
    Using \\ to insert a line break is wrong except in special environments, such as tabular and array. Definitely not something to teach newbies. – cfr Jun 30 '18 at 22:42
  • @Thruston Totally true. I was still in the mindset of the previous example, thx. – meisterluk Jun 30 '18 at 23:32

What's up with the arbitrary whitespace placement

I'll have a go at this one.

LaTeX has three modes - at least as far as the user is concerned.

We are concerned with math mode and text mode (of which there are two types, but it's not important).

Math mode is designed for typesetting maths beautifully. And it's wonderful. It takes care of this sort of thing. It puts the correct typographical spaces around + signs and = signs and so on. It gives you a real minus sign (with the correct spacing) instead of a dash. It typesets letters, for example x, in italics by default, as would be expected for variables. It typesets a string of letters, such as ax, with spacing appropriate for the product of two variables, which is what we want. Because it takes care of the spacing, it ignores spaces in the code allowing you to add spacing in the code to make the code more readable. The reason it does this though is because it would be quite hard for you to input all the different amounts of space in all the right places. So it does it. It does everything it can to make our lives easy and to produce the optimal results for us, without us having to do anything. It's wonderful if what you want is maths. It is much less good if what you want is text.

What's happened with you is you have said


Without entering math mode, and so it is typeset as though it were text and the nice spacing hasn't been added around the = sign for you and your letters aren't italic and the rules for good mathematical typography haven't been observed.

What you've then done is used the command \neg. Now \neg can only be used in math mode. So when you've run LaTeX on your code, it's found an error. You've not entered math mode (see the other answer for how to do this), but you've used a command that can only be used in math mode. Problem! So LaTeX has tried to solve this and it tells you what it's done in the error message:

! Missing $ inserted.
<inserted text> 
l.4 Find the value of: M=x(\neg
                               {y}+yz), if (x, y, z)=(1, 0, 0)

It's added a $ for you, which puts you in math mode. Now you can use \neg and the code works. But LaTeX doesn't know when it's time to end math mode, so the whole rest of the line ends up in math mode and the closing $ can't be added until the end because how does LaTeX know where it should go?

So now you've got the nice correct spacing around the + sign and the = sign and the nice no spacing around your commas. Which is good. But you've got text in there. You've got the word "if" in there. And that's not maths. But LaTeX has put it in math mode. So it gets treated as maths and the spaces around the word "if" get ignored and the word "if" is not treated as the word "if", but as the product of two variables i and f.

  • 1
    I agree the original had more rhetorical flourish, but I really did spend a long time thinking that the spacing must always be right in maths mode, whatever I thought, and that I should never adjust it. So maybe I took the claims a bit too literally :(. – cfr Jul 1 '18 at 3:50

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.