Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2009-10-31 23:09:04

betterthangauss
Member
Registered: 2009-10-31
Posts: 11

LaTeX question about making command to write sets like {x | x^2 > 0}

I would like to make a command to write sets with constraints, so in my LaTeX I could write something like

\SetWithConstraint{x}{x^2 > 0}

Instead of having to manually do

\left{x | x^2 > 0 \right}

Here is the initial command definition I put in my preamble:

\newcommand{\SetWithContraint}[2]{\left\{#1\,|\,#2\right\}}

It seemed to work pretty well at first, for example this comes out looking pretty good:

57273546.png

However, I would like a way to have the size of the | in the middle match the size of the braces enclosing the set definition. My results here using that command look horrible:

badn.png

Does anyone know a good way to accomplish this? I'd really prefer my TeX files weren't cluttered with garbage regarding explicit layouts of individual characters. Thanks!

Offline

#2 2009-10-31 23:47:37

mathsyperson
Moderator
Registered: 2005-06-22
Posts: 4,900

Re: LaTeX question about making command to write sets like {x | x^2 > 0}

You could cheat and use "\left|" to get a | that changes its length according to what it needs to be. You'd also need to match it with a null brace (?), by putting "\right." somewhere.


Why did the vector cross the road?
It wanted to be normal.

Offline

#3 2009-11-01 00:09:10

betterthangauss
Member
Registered: 2009-10-31
Posts: 11

Re: LaTeX question about making command to write sets like {x | x^2 > 0}

Thanks. I completely forgot about being able to use the "." character in \left, \right commands as you suggested. It still doesn't look great like that, but it does match what I was asking for.. lol

Now the bar definitely looks too tall though, since it matched the size of the outer brace. I guess I should have asked if it's possible to make it the next size down from the size of the brace. Does anyone have a better idea for how to do this that doesn't have the limitations this command does?

\newcommand{\SetWithContraint}[2]{\left\{#1\,\left|\,#2\right.\right\}}

Is there a way to do this that wouldn't be considered cheating? Sorry if it's a noob question whose correct answer is "RTFM", but I haven't seen a good example of how to do this cleanly yet. Thanks again for the help, mathstyperson!

Offline

#4 2009-11-01 00:31:14

betterthangauss
Member
Registered: 2009-10-31
Posts: 11

Re: LaTeX question about making command to write sets like {x | x^2 > 0}

math. Using \left to line up the | doesn't look right when the right side is small and the left side big

i.e., here's the code for the command:

\newcommand{\SetWithContraint}[2]{\left\{\,#1\ \left|\ #2\,\right.\right\}}

And if I use it like this:

\[
   \Defined
      {B_N}
      {\SetWithContraint
         {
            \SetMember
               {
                  \FiniteSum{a_i z^{n-i}}{i}{0}{n}
               }
               {
                  \Polynomials{\ComplexNumbers}{z}
            }
         }
         {
            FOO!
      }
   }
\]

I get

food.png

where \SetMember, \Defined, etc. are commands I made up to try to decouple the logic of the markup from the characters used to  display it.

Offline

#5 2009-11-01 06:06:34

Ricky
Moderator
Registered: 2005-12-04
Posts: 3,791

Re: LaTeX question about making command to write sets like {x | x^2 > 0}

It's a good command to have, but with a pretty long name.  Reminds me of Java.  I would recommend:

SetC

Personally in commands, the more lowercase the better so I would actually make it

setc

It's all about reducing the number of keystrokes (whilst maintaining readability).


"In the real world, this would be a problem.  But in mathematics, we can just define a place where this problem doesn't exist.  So we'll go ahead and do that now..."

Offline

#6 2009-11-01 10:08:03

betterthangauss
Member
Registered: 2009-10-31
Posts: 11

Re: LaTeX question about making command to write sets like {x | x^2 > 0}

Ricky wrote:

It's a good command to have, but with a pretty long name.  Reminds me of Java.  I would recommend:

SetC

Personally in commands, the more lowercase the better so I would actually make it

setc

It's all about reducing the number of keystrokes (whilst maintaining readability).

When I'm coding something in any language, I only like to use short variable names for names defined in small scopes. For something global that's going to be used a lot to express the semantics of my paper, I'd much rather be as explicit as possible in my naming. I feel like if I stop writing a document and then come back a year later to make corrections or changes, I'll understand \SetWithConstraint more quickly than I will \SetC (maybe I'd think \SetC was a command for the set of complex numbers, for instance).  I use the camel-case with uppercase first letters to try to keep my defined names from conflicting with the symbols AMS defines.

Offline

Board footer

Powered by FluxBB