[Tex/LaTex] How to create a set in LateX

math-operators

I am very lost. I haven't been liking LaTeX as it's quite hard for me to get the hang of it, so I've decided to practice on my own during the summer, but I am already stuck on something that seems very basic.

I want to write sets. How do I create the brackets {}?
You know, say {2,4,6,8…} or {x|x is positive and even}. I tried ${2,4,6...}$ But this ignores the brackets.

I was searching if there is a specific command to create that say
\Set{2,4,6...} or something similar. But no, it's an error and I cannot find such information.

I have given up, how do I create a set notation nicely??? Really simple things seem very… obscure to me with LaTeX and requires great hassle.
Is there any where good, a website, for me to learn this? Had a hard time in university last year, some people got easily okay with it but this is just not my cup of tea…. Seems to unnecessarily complicate something that could be done simpler…. Help is greatly appreciated! Thanks in advance.

Best Answer

To answer your specific question:

To quote from Leslie Lamport's "LaTeX: A Document Preparation System" (Leslie Lamport initially developed LaTeX):

The ten special characters

# $ % & ~ _ ^ \ { }

are used only in LaTeX commands.

...

Seven of those symbols can be produced by typing a \ in front of the corresponding character.

$ & % # _ { } are easy to produce.

In other words, to get { and } you must type \{ and \}. This is because { and } mean something very special to LaTeX. They are used to delimit arguments. So with something like \emph{Hi}, the emphasis starts at the { and finishes at the } (\emph is a command which is used to emphasise text; the standard behaviour is for it to italicise it). In other words, everything enclosed within the braces is emphasised.

As such, if you want to print the symbols { and }, you can't just type the plain symbol. Instead you must "escape" it. The \ is the escape character and it basically tells LaTeX to pay attention. emph is just a word like any other to LaTeX. But \emph is a command to LaTeX. What escaping a { does is cause LaTeX to print a { character.

So to get {2,4,6,8...}, all you need to do is type:

$\{2, 4, 6, 8\dots\}$

enter image description here

To get {x|x is positive and even}, you can do:

$\{x \mid x \text{ is positive and even}\}$

enter image description here

As raised in the comments - this relies on the amsmath package. Instead, you can do:

$\{x \mid x \mbox{ is positive and even}\}$

For most purposes, this has the same effect, but there are minor differences:

Difference between various methods for producing text in math mode

For really nice spacing, follow Hagen von Eitzen's advice and use:

$\{\,x \mid x \text{ is positive and even}\,\}$

enter image description here

As you can see, \, inserts a thin space. There are other commands for inserting space in LaTeX. However, \, is one of only two that can be used outside of math-mode.


But, really, it's important that you gain an understanding of the basic operating principles of LaTeX before you go further and start worrying about how to do specific things; otherwise you're gonna be completely at sea and everything's gonna seem like black magic and nonsense. So I really recommend you have a little look through some basic introductions before diving right in there.

However I learned by doing - I learned by trying it out, I learned by using LaTeX and looking things up whenever I wanted to do something I didn't yet know how to do. That's a very fulfilling, very enjoyable and very practical way to learn - although there are massive holes in my knowledge and, because my approach was very light on theory, I'm only just starting to learn about bad habits I've developed and principles I may have overlooked.

But still, as good as it is to dive in there and get your hands dirty, you have to, have to get a basic idea of what LaTeX is and how it works or you'll probably continue to have a pretty miserable time. It's no wonder you don't like it and everything seems arcane and difficult and a complete pain in the posterior to you!

Related Question