Closed Thread
Results 1 to 14 of 14

Thread: How to use Math tags

  1. #1
    Beep
    Points: 63,942, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardCommunity AwardFrequent PosterActivity Award
    Dason's Avatar
    Location
    Ames, IA
    Posts
    11,367
    Thanks
    268
    Thanked 2,211 Times in 1,889 Posts

    How to use Math tags




    A previous thread covered this topic (found here) but I figured a more detailed explanation could be given to help some people out.

    Contents
    1. How do I use math tags?
    2. Symbols
    3. Subscript/Superscript/Other Modifiers
    4. Fractions/Integration/Summation/Limits
    5. Tables
    6. Misc.

    0.5) Why math tags? Why not tex tags?

    The forum has both math and tex tags. However, the tex tags seem broken and don't properly render a lot
    of stuff so we *highly* suggest using math tags instead of trying to get tex tags to work.

    1) How do I use math tags?

    The forum includes typesetting using LaTex through the use of two special tags:
    [math] and [/math].

    A quick example - The following code:

    [math]Y_i = \mu_i + \epsilon_i[/math]

    produces the following result: Y_i = \mu_i + \epsilon_i

    There are various ways to see the code somebody else used to produce their mathematical typesetting. If you have javascript enabled you can click on their typesetting and a popup will display the code they used. If that doesn't work you can always 'quote' the post of interest and examine their post directly to see how they formatted it.

    2) Symbols

    There are many symbols that can be produced through the use of LaTeX. There are many guides on the internet that will show you the thousands of symbols that can be created. However, for a quick guide you can refer here or just browse other member's posts. It's not that bad and you can learn quickly. For a quick list of the more commonly used symbols you can refer below:

    \begin{tabular}{|l|c|}\hlineCode & Result \\\hlinealpha & $\alpha$ \\beta & $\beta$ \\epsilon & $\epsilon$ \\lambda & $\lambda$ \\mu & $\mu$ \\sigma & $\sigma$ \\theta & $\theta$ \\chi & $\chi$ \\\hline\end{tabular}
    \begin{tabular}{|l|c|}\hlineCode & Result \\\hlinecap & $\cap$ \\cup & $\cup$ \\cdot & $\cdot$ \\cdots & $\cdots$ \\ldots & $\ldots$ \\\hline\end{tabular}
    \begin{tabular}{|l|c|}\hlineCode & Result \\\hlineleq & $\leq$ \\geq & $\geq$ \\neq & $\neq$ \\subset & $\subset$ \\sim & $\sim$ \\equiv & $\equiv$ \\propto & $\propto$ \\\hline\end{tabular}
    \begin{tabular}{|l|c|}\hlineCode & Results \\\hlineexists & $\exists$ \\forall & $\forall$ \\infty & $\infty$ \\mathbb\{R\} & $\mathbb{R}$ \\mathbb\{N\} & $\mathbb{N}$ \\mathbb\{Z\} & $\mathbb{Z}$ \\\hline\end{tabular}

    and there are lots more. Note that you would need to add "\" to the front of any of that 'code' to produce the actual symbol inside of a math tag. That should give you a good start though. Note that you don't need a symbol to to a 'less-than' or 'greater-than' because you already have '<' and '>' on your keyboards.

    3) Subscript/Superscript/Other Modifiers

    If you want to add a superscript or subscript LaTeX makes it easy. The superscript operator is '^' and the subscript operator is '_'. For example
    HTML Code: 
    [math]x^2[/math]
    Produces x^2
    and
    HTML Code: 
    [math]x_i[/math]
    Produces x_i. It's possible to have both.
    HTML Code: 
    [math]x^2_i[/math]
    Produces x^2_i. If you want to have more than one character as part of your superscript or subscript you need to enclose the entire phrase in curly braces i.e.
    HTML Code: 
    [math]y^{3x - 5}_{max}[/math]
    Produces y^{3x - 5}_{max}.

    There are also other useful modifications one could want to make to symbols. A few of which are adding a bar, a hat, or making something bold. For example:

    HTML Code: 
    [math]\bar{x}[/math]
    Produces \bar{x}

    HTML Code: 
    [math]\hat{y}[/math]
    Produces \hat{y}

    and for when you work with vectors a lot of times you want to make something bold to let people know that it's a vector. We can do something like that by using \mathbf{}. For example:
    HTML Code: 
    [math]f(\mathbf{y} | \theta) = \prod_{i=1}^n f(y_i | \theta) [/math]
    gives f(\mathbf{y} | \theta) = \prod_{i=1}^n f(y_i | \theta)

    4) Fractions/Integration/Summation/Limits

    Fractions

    In LaTeX fractions have the same general form:
    HTML Code: 
    [math]\frac{numerator}{denominator} [/math]
    A few examples:
    HTML Code: 
    [math]\frac{7!}{2!(7-2)!}[/math]
    Produces \frac{7!}{2!(7-2)!}

    HTML Code: 
    [math] \frac{\beta^{\alpha}}{\Gamma (\alpha)} [/math]
    Produces \frac{\beta^{\alpha}}{\Gamma (\alpha)}

    Integration

    If you want to write out some formulas involving integration then \int is your friend.
    HTML Code: 
    [math] \int x^2 dx = \frac{1}{3}x^3 [/math]
    Produces \int x^2 dx = \frac{1}{3}x^3. It's easy enough to add limits to the integration using the superscript and subscripts we used before. For example:

    HTML Code: 
    [math] \int_{-\infty}^{\infty} \frac{1}{\sqrt{2 \pi}}e^{-\frac{x^2}{2}} dx = 1 [/math]
    Produces \int_{-\infty}^{\infty} \frac{1}{\sqrt{2 \pi}}e^{-\frac{x^2}{2}} dx = 1

    Summation

    Our example will involve the binomial distribution:
    HTML Code: 
     [math] \sum_{x = 0}^n {n \choose{x}} p^x (1-p)^{n-x}  [/math]
    Produces \sum_{x = 0}^n {n \choose{x}} p^x (1-p)^{n-x}

    Limits
    Limits get their own subsection for the sole reason that not everybody realizes that \lim is a latex command. Notice the difference between the following two examples

    HTML Code: 
     [math] lim_{x \rightarrow \infty}[/math]
    [math] \lim_{x \rightarrow \infty}[/math]
    The first looks like this: lim_{x \rightarrow \infty} while the second looks much better: \lim_{x \rightarrow \infty}

    5) Tables

    When presenting data a lot of times it will look much nicer in tabular form. An example table:
    HTML Code: 
    [math]
    \begin{tabular}{|l|cr|}
    \hline
    ID & Age & Weight \\
    \hline
    Ted & 25 & 180 \\
    Frank & 52 & 169 \\
    Sue & 32 & 125 \\
    \hline
    \end{tabular}
    [/math]
    Which will produce:
    \begin{tabular}{|l|cr|}\hlineID & Age & Weight \\\hlineTed & 25 & 180 \\Frank & 52 & 169 \\Sue & 32 & 125 \\\hline\end{tabular}

    You must start a table with the \begin{tabular} command. The portion directly after that (it looks like {|l|cr|} ) is quite customizable. What that part does is control how many columns the table will have, where you will have vertical lines, and how each column is justified. By adding the pipe character (it looks like '|' and is obtained by holding shift and hitting the key above 'enter') you add a vertical line to separate columns. The different letters (l, c, r) stand for "left", "center", and "right" justified. The command \hline tells the table when to add a horizontal line. Once you get to the portion of the table where you're actually adding data you separate the data between columns with the '&' character. You tell the table that you are finished with a row by ending it with two backslashes ("\\"). When you're finished with the table you need the \end{tabular} command.

    Another example:
    HTML Code: 
    [math]
      \begin{tabular}{|c|c|c|}
        \hline
        Parameter &  Point Estimate & 95\% Interval Estimate \\
        \hline
        $\beta_0$ & .503752 & (0.35280, 0.65470) \\
        $\beta_1$ & .002229 & (0.00191, 0.00254) \\
        $\beta_2$ & -1.286 & (-2.5331, -.038942) \\
        \hline
      \end{tabular}
    [/math]
    \begin{tabular}{|c|c|c|}    \hline    Parameter &  Point Estimate & 95\% Interval Estimate \\    \hline    $\beta_0$ & .503752 & (0.35280, 0.65470) \\    $\beta_1$ & .002229 & (0.00191, 0.00254) \\    $\beta_2$ & -1.286 & (-2.5331, -.038942) \\    \hline  \end{tabular}

    If you use R and want to create a table from some data you might be interested in the xtable package. It will automatically generate the latex code to create a table from your data which can save you lots of time copying/pasting and inserting various symbols.

    End Remarks


    There is a lot more you can do with LaTeX that went unmentioned. Hopefully you have a decent understand how to use some of the basic math typesetting available to you here.

    Other references on how to use LaTeX:
    http://www.artofproblemsolving.com/W.../LaTeX:Symbols
    http://www.physicsforums.com/misc/howtolatex.pdf

    It should be noted that not all features of LaTeX are enabled in this web environment but you should be able to do almost anything you would want to post. If you have questions feel free to ask.
    Last edited by Dason; 04-27-2014 at 11:45 AM. Reason: Added: xbar, yhat, bold, and links!

  2. The Following 9 Users Say Thank You to Dason For This Useful Post:

    GretaGarbo (04-15-2012), hlsmith (10-03-2012), ledzep (12-10-2011), Matthew18342 (02-15-2013), Psycho_Coder (06-30-2014), SiBorg (07-21-2012), soxi (04-04-2013), TheEcologist (06-17-2011), trinker (02-06-2012)

  3. #2
    Points: 3,992, Level: 40
    Level completed: 21%, Points required for next Level: 158

    Posts
    73
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Thumbs up Re: Suggest Sticky: How to use Math tags

    Nice job Dason
    Adding a little more, I think these two links will be useful too http://www.artofproblemsolving.com/W.../LaTeX:Symbolsand http://www.physicsforums.com/misc/howtolatex.pdf

  4. #3
    Beep
    Points: 63,942, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardCommunity AwardFrequent PosterActivity Award
    Dason's Avatar
    Location
    Ames, IA
    Posts
    11,367
    Thanks
    268
    Thanked 2,211 Times in 1,889 Posts

    Re: Suggest Sticky: How to use Math tags

    Comments? Suggestions? I can completely change the layout or add/remove sections. I just want to know what everybody thinks.

  5. #4
    Ninja say what!?!
    Points: 8,297, Level: 61
    Level completed: 49%, Points required for next Level: 153
    Link's Avatar
    Posts
    1,165
    Thanks
    37
    Thanked 84 Times in 76 Posts

    Re: Suggest Sticky: How to use Math tags

    Very impressive Dason. I'm glad that you took the time to post this. Maybe this should be a sticky for the forums.

  6. #5
    TS Contributor
    Points: 11,500, Level: 70
    Level completed: 63%, Points required for next Level: 150
    CowboyBear's Avatar
    Location
    New Zealand
    Posts
    1,580
    Thanks
    69
    Thanked 278 Times in 207 Posts

    Re: Suggest Sticky: How to use Math tags

    Quote Originally Posted by Dason View Post
    Comments? Suggestions? I can completely change the layout or add/remove sections. I just want to know what everybody thinks.
    It looks pretty great to me - I've already found it useful. You seem to have the basics well covered, and the layout is very sensible. It might be nice to include the code for \bar{x} in the symbols section, since it's probably one that is used a fair bit, although it's easy enough for us to look up symbols like this in the link Sambit posted.

    Thanks heaps for putting this together, it's definitely helped to get me started! Now, how do I start persuading people in psych that LaTeX beats Word?

  7. #6
    Admin
    Points: 16,262, Level: 81
    Level completed: 83%, Points required for next Level: 88
    quark's Avatar
    Location
    Canada
    Posts
    472
    Thanks
    23
    Thanked 172 Times in 67 Posts

    Re: Suggest Sticky: How to use Math tags

    Very nice. I think this would be great for the first two forum categories. We can also make it an announcement so it goes sitewide. What do you guys think?

  8. #7
    Points: 3,992, Level: 40
    Level completed: 21%, Points required for next Level: 158

    Posts
    73
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Red face Re: Suggest Sticky: How to use Math tags

    i think we all should thank Dason for the time and effort he gave for writing this thread by making it sticky.

  9. #8
    R purist
    Points: 21,565, Level: 92
    Level completed: 22%, Points required for next Level: 785
    TheEcologist's Avatar
    Location
    The Netherlands.
    Posts
    1,704
    Thanks
    231
    Thanked 451 Times in 258 Posts

    Re: Suggest Sticky: How to use Math tags

    Great, its here! Nicely done and very useful.
    The true ideals of great philosophies always seem to get lost somewhere along the road..

  10. #9
    Beep
    Points: 63,942, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardCommunity AwardFrequent PosterActivity Award
    Dason's Avatar
    Location
    Ames, IA
    Posts
    11,367
    Thanks
    268
    Thanked 2,211 Times in 1,889 Posts

    Re: Suggest Sticky: How to use Math tags

    Ok. So I added a small part on creating things like: \bar{x}, \hat{y}, \mathbf{y} and I added some links at the bottom. If there aren't any more comments or suggestions I think we could probably put this up as a sticky/announcement soon.

  11. #10
    ggplot2orBust
    Points: 36,866, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,014
    Thanks
    1,418
    Thanked 781 Times in 694 Posts

    Re: Suggest Sticky: How to use Math tags

    I didn't know this existed. I'll reference posters to here for formatting things like math tags from now on.
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  12. #11
    Beep
    Points: 63,942, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardCommunity AwardFrequent PosterActivity Award
    Dason's Avatar
    Location
    Ames, IA
    Posts
    11,367
    Thanks
    268
    Thanked 2,211 Times in 1,889 Posts

    Re: Suggest Sticky: How to use Math tags

    I always forget where this thread is located. I should clean it up and actually put it as a sticky somewhere...

  13. The Following User Says Thank You to Dason For This Useful Post:

    trinker (02-06-2012)

  14. #12
    R purist
    Points: 21,565, Level: 92
    Level completed: 22%, Points required for next Level: 785
    TheEcologist's Avatar
    Location
    The Netherlands.
    Posts
    1,704
    Thanks
    231
    Thanked 451 Times in 258 Posts

    Re: Suggest Sticky: How to use Math tags

    Quote Originally Posted by Dason View Post
    I always forget where this thread is located. I should clean it up and actually put it as a sticky somewhere...
    You do realize that it is accessible from the Latex button at the forum's top bar?
    The true ideals of great philosophies always seem to get lost somewhere along the road..

  15. #13
    Beep
    Points: 63,942, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardCommunity AwardFrequent PosterActivity Award
    Dason's Avatar
    Location
    Ames, IA
    Posts
    11,367
    Thanks
    268
    Thanked 2,211 Times in 1,889 Posts

    Re: Suggest Sticky: How to use Math tags

    Quote Originally Posted by TheEcologist View Post
    You do realize that it is accessible from the Latex button at the forum's top bar?
    I know that. But there wasn't a Latex button when I posted that.
    Morte a tutti i raptors
    001100010010011110100001101101110011

  16. #14
    Beep
    Points: 63,942, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardCommunity AwardFrequent PosterActivity Award
    Dason's Avatar
    Location
    Ames, IA
    Posts
    11,367
    Thanks
    268
    Thanked 2,211 Times in 1,889 Posts

    Re: How to use Math tags


    This thread is apparently a spammers paradise so I'm going to lock it. If you have questions about this material please start a new thread in the forum feedback section.
    Morte a tutti i raptors
    001100010010011110100001101101110011

Closed Thread

           




Similar Threads

  1. Replies: 21
    Last Post: 06-09-2014, 06:47 AM
  2. Solved and Workaround tags
    By TheEcologist in forum Forum Feedback
    Replies: 14
    Last Post: 01-03-2012, 06:19 PM
  3. Best way to do a 'how-to' about Math tags
    By Dason in forum Forum Feedback
    Replies: 3
    Last Post: 09-15-2010, 04:22 PM
  4. Can somebody suggest which analysis to use?
    By sophie2cu2 in forum Psychology Statistics
    Replies: 1
    Last Post: 08-09-2010, 08:52 AM
  5. Suggest method of analysis
    By Sunil Neelam in forum Statistics
    Replies: 6
    Last Post: 10-02-2008, 09:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats