15
$\begingroup$

The point of this question is to give people a chance to draft their best MathJax tips for new users. Perhaps this question will stand alone as one of the places to go. Perhaps the material in the answers will be edited into an introductory article. Perhaps it will flop. Who knows? But the whole idea is to pool knowledge and experience to help those who are learning.


Table of Contents:

$\endgroup$
24
  • 5
    $\begingroup$ I think that the idea behind this questions is very good. I might alter the title a bit.Maybe something like "Short and helpful advice on using..." $\endgroup$ – quid Feb 19 at 19:13
  • 3
    $\begingroup$ @quid Thank you - I didn't think the title was right, but had to cook supper ... I don't mind so much if people don't think this is a question, except that I care a lot about how we make things easier for new users. I am an old hand now, but had never heard of MathJax when I first encountered the site, In those days I got help and direction from people who knew stuff. These days, competence is often assumed. It matters how we induct people more than how precious I am about my own reputation. $\endgroup$ – Mark Bennet Feb 19 at 19:43
  • $\begingroup$ Perhaps we just keep directing people to the existing Q&A on using MathJax, and expect them to make an effort in writing their own question instead of doing it all for them? $\endgroup$ – Nij Feb 19 at 20:42
  • 5
    $\begingroup$ @Nij For new people I think we need to be a little more welcoming that that - not so much "engage with Mathjax or else" as "Mathjax will format your question the way you want it" $\endgroup$ – Mark Bennet Feb 19 at 20:58
  • 1
    $\begingroup$ So add an introduction to the MathJax guide. Add a section that gives information on the 8-10 most frequently used codes. $\endgroup$ – Nij Feb 19 at 22:16
  • 8
    $\begingroup$ @Nij the MathJax guide is relatively big; depending on the device one uses rendering is an issue. A more lean version that exists separately would be better than adding to the large one. $\endgroup$ – quid Feb 19 at 22:50
  • 1
    $\begingroup$ there is already a very lean version here, (and I'll just link the full guide too,) but that doesn't look easy to change without mods or higher powers $\endgroup$ – Calvin Khor Feb 20 at 4:11
  • 5
    $\begingroup$ @Nij The MathJax guide on meta is something that needs to exist, and people should be linked to it, but it has problems. It is not very well organized, and (as quid points out) it can take a long time to render. If someone had the time, it would be really nice if that thread were to be massively edited for organization, and to better fit the Q&A style of the site--something more like the how to ask a good question topic. Barring some massive rewrites, it is not a great place for beginners. :\ $\endgroup$ – Xander Henderson Feb 20 at 4:49
  • 1
    $\begingroup$ Perhaps you should propose some small additions to How can I format mathematics here?, the existing brief introduction. $\endgroup$ – hardmath Feb 20 at 17:20
  • 3
    $\begingroup$ So I might understand closing this as a duplicate, but why are there 4 close votes as opinion based? Very puzzling. $\endgroup$ – Matt Samuel Feb 20 at 22:23
  • 2
    $\begingroup$ @XanderHenderson I am busy next week, but after that I can take up a project on revamping the MathJax page. I just need more moderators to agree that this is the right thing to do. $\endgroup$ – Teresa Lisbon Feb 21 at 6:37
  • 5
    $\begingroup$ I've began writing a tutorial that is aimed at covering the absolute basics. The most common pieces of syntax I'm going to cover are: numbers, arithmetic, basic operations, functions, limits, and integrals. If you think that there is something I have left out, please let me know. Do keep in mind however that I'm trying to cover the bare minimum needed to be competent in Mathjax. Aesthetic considerations such as how to align equations are unlikely to be covered, unless there is a strong consensus for me to include them in my answer. $\endgroup$ – Joe Feb 21 at 14:26
  • $\begingroup$ @Joe First off, thank you for taking the time and mind for this. Maybe elementary set theory or basic discrete mathematics shall be included too $\endgroup$ – Verónica Rmz. Feb 21 at 17:05
  • 3
    $\begingroup$ Since there seems to be a lot of interest in making the Mathjax tutorial more user friendly, I have voted to reopen. I can't understand why this post would be deemed 'opinion based'β€”it's just a list of which commands are the most frequently used on this site, organised in a way that would be helpful to new contributors. $\endgroup$ – Joe Feb 23 at 9:48
  • 1
    $\begingroup$ There should also be a well publicized set of MathJax and LaTeX tips for old user who've been using LaTeX daily for at least of a couple of decades and still fill every paragraph with lots of crude solecisms that they would avoid if they knew some basics. This probably includes more than 70% of professors of mathematics. $\endgroup$ – Michael Hardy Feb 25 at 15:07
23
$\begingroup$

The goal of this post is to outline the absolute basics of how to typeset mathematics using MathJax, without any prior knowledge assumed.


Introduction: when asking and answering questions, it makes your writing much clearer if you typeset the mathematical notation using the markup language MathJax. Compare how the quadratic formula reads with and without it: $$ \underbrace{x=\frac{-b\pm \sqrt{b^2-4ac}}{2a}}_{\text{With MathJax}} \quad \underbrace{\text{x=-b+-sqrt(b^2-4ac)/2a}}_{\text{Without MathJax}} $$ This tutorial serves as a brief introduction to how MathJax works, and how you can use it. A more comprehensive overview of the subject can be found here.

Table of contents:

  1. Getting started
  2. Understanding MathJax syntax
  3. Numbers and arithmetic
  4. Functions
  5. Chaining syntax together
  6. Miscellaneous commands

1. Getting started: in the body of your post, you can typeset formulas by putting two dollar signs $$ before the formula, and after the formula:

Typesetting mathematics in the body of post

Be careful not to leave an empty line between the formula and the dollar signs. In the above example, the formula is displayed on a new line. This is known as a 'block formula' or 'displayed formula'. It is possible to write out multiple lines of equations. Each time you want to go onto a new line, you have to indicate this by typing two back-slashes \\:

2x + 7 = 15 \\
2x = 8 \\
x = 4

Notice that the final line does not require two back-slashes. If you enclose the above code using dollar signs, then it renders as $$ 2x + 7 = 15 \\ 2x = 8 \\ x = 4 $$ It is also possible to display the formula on the same line as the text:

Inline formulas

This is known as an 'inline formula'. Rather than enclosing the formula with two dollar signs, you should only use a single $ at the start and end of the formula. You can also use inline formulas in the title of your post (but not block formulas).

2. Understanding MathJax syntax: since MathJax is a markup language, there is a syntax that you have to follow. Simply enclosing x=-b+-sqrt(b^2-4ac)/2a with dollar signs does not do the trick: $$ x=-b+-sqrt(b^2-4ac)/2a $$ Instead, there are a set of commands that have to followed in order to typeset the equations nicely. The rest of this post will focus on the most common ones; a more comprehensive list can be found in the main tutorial.

In general, if you want to see how a formula was rendered, then right-click on it, and press 'Show Math As', then 'TeX Commands':

See how a formula was rendered

If you're wondering how to type a specific symbol, then Detexify is the tool for you. It allows you to draw a symbol, and finds the closest matching command for it. (These commands are not guaranteed to work in MathJax, but they are likely to.)

Detexify

3. Numbers and arithmetic: to write out equations such as $4+7=11$, you simply have to enclose them using with dollar signs (no special commands are needed). Easy-peasy! 4+7=11 renders as $4+7=11$.

For multiplication and division, there are a number of options:

  • $5 \times 7 = 35$ is rendered using 5 \times 7 = 35. If you want to indicate multiplication using a dot, as in $5 \cdot 7 = 35$, you can write 5 \cdot 7 = 35.
  • $12 \div 6 = 2$ is rendered using 12 \div 6 = 2. It is more common to indicate division using fractions: $\frac{3x+7}{2}$ is produced by \frac{3x+7}{2}. Notice how the \frac command has to be accompanied by two sets of curly braces. The numerator goes in the first set of curly braces, and the denominator goes in the second set of curly braces. Finally, you can also indicate division simply by using a forward slash: 1/3 produces $1/3$.

For exponents, you have to use a superscript ^. For instance, $2^4=16$ is rendered using 2^4=16. If the exponent has more than one character, then you have to enclose it using curly braces. For instance, $2^{10}=1024$ is rendered using 2^{10}=1024, not 2^10=1024.

Square roots are typeset using the command \sqrt: $\sqrt{64}$ is produced by \sqrt{64}. Confusingly, cube roots can also be typeset using the \sqrt command: $\sqrt[3]{64}$ is produced by \sqrt[3]{64}. $n$-th roots can be handled similarly.

Inequalities such as $5>4$ can be written as 5>4. If you need to use a 'greater than or equal to' sign, then use \geq: $5 \geq 4$ is produced by 5 \geq 4$. The 'less than or equal to' sign is \leq. The 'not equal to' sign is \neq.

4. Functions: to write out a function such as $\sin(x)$, you have to use a backlash: \sin(x). You can also omit the parentheses by using curly braces instead: \sin{x} renders as $\sin{x}$. Alternatively, you can leave a space between the function and the argument: \sin x also renders as $\sin x$. Other functions such as $\ln x$ and $\arctan x$ can be typeset in much the same way. Again, if you are unsure about what the command for a function is, then right-click on it, and press 'Show Math As', then 'TeX Commands'. You can often guess the MathJax command for a function: it is no surprise that \exp renders as $\exp$.

To indicate the base of a logarithm, use an underscore _ and curly braces where needed. \log_{10}x renders as $\log_{10}x$. In general, the subscript of an expression can be typeset with _, and the superscript with ^. For instance, \sin^2 x produces $\sin^2{x}$ and x_1 produces $x_1$. You can even use both a _ and ^ in the same expression: x_1^2 produces $x_1^2$, although this can be written more cleanly using parentheses: (x_1)^2 produces $(x_1)^2$.

Finally, if you want to define a function yourself, then something like f(x)=2x+7 renders as $f(x)=2x+7$.

5. Chaining syntax together: more complicated-looking formulas in MathJax are often built from simpler ones. The formula $$ \frac{1}{x}\sqrt{\frac{1+x}{1-x}}\ln(\frac{2x^2+2x+1}{2x^2-2x+1}) $$ looks unpleasant to typeset, but is actually simply composed of three simple expressions:

\frac{1}{x}
\sqrt{\frac{1+x}{1-x}}
\ln (\frac{2x^2+2x+1}{2x^2-2x+1})

Notice that the MathJax editor has no problem with putting a fraction inside of a square root, for example. One aesthetic issue with the above formula is the odd sizing of the parentheses in $$ \ln(\frac{2x^2+2x+1}{2x^2-2x+1}) $$ This can be remedied by replacing ( with \left( and ) with \right). If we change the code to

\ln\left(\frac{2x^2+2x+1}{2x^2-2x+1}\right)

it displays as $$ \ln\left(\frac{2x^2+2x+1}{2x^2-2x+1}\right) $$ which is more pleasant to look at, though not strictly necessary. If you want to include text in formulas, then use \text. For instance,

\text{speed} = \frac{\text{distance}}{\text{time}}

renders as $$ \text{speed} = \frac{\text{distance}}{\text{time}} $$

6. Miscellaneous commands:

  • Greek letters: simply type the name of the Greek letter. \pi renders as $\pi$. If you want uppercase, then begin the command with a capital letter: \Gamma renders as $\Gamma$.
  • For set membership, the commands \mathbb and \in come in handy: $x \in \mathbb{R}$ is rendered by x \in \mathbb{R}. The complete list of fonts can be found in the main tutorial.
  • For logical implication, \implies and \iff are useful:

$$ x = 5 \implies x^2 = 25 \\ x^2 = 25 \iff x = 5 \text{ or } x = -5 $$ is rendered by

x = 5 \implies x^2 = 25 \\
x^2 = 25 \iff x = 5 \text{ or } x = -5
$\endgroup$
14
  • 3
    $\begingroup$ Helpful, +1. If there's a revamp of the MathJax tutorial page as we thought on a recent chat, I would consider your opinion worthy on any edits we make there, following this answer. Thank you. $\endgroup$ – Teresa Lisbon Feb 21 at 10:20
  • 1
    $\begingroup$ @TeresaLisbon: Thank you Teresa; I am very hopeful that the Mathjax tutorial will become more user-friendly for beginners. $\endgroup$ – Joe Feb 21 at 15:18
  • $\begingroup$ I am actually busy this week, but next week I am planning to start the revamp. I will.ask the moderators about this prior to doing so. I expect to merely "act" and not think since that is my strength, so I will need great guidance(orders?)from moderators and you. $\endgroup$ – Teresa Lisbon Feb 21 at 15:45
  • 4
    $\begingroup$ This is great. One thing I was wondering when I asked the question was whether it was better to do a few shorter posts of this kind on different topics, rather than longer and more comprehensive ones. This hits the kind of level I was thinking might be helpful. $\endgroup$ – Mark Bennet Feb 21 at 17:13
  • 1
    $\begingroup$ @MarkBennet: I was hoping that this post could stay as one, since the individual sections aren't really self-contained. So thanks for confirming that this was the right 'level'. It's still not exactly clear what will become of the Mathjax tutorial, but hopefully the end product will not be as messy as before. I do find it rather ironic that the 'basic tutorial' has pages upon pages about how to use the software. Perhaps this thread could be turned into the 'basic' tutorial, and the old one be turned into the 'comprehensive' tutorial. $\endgroup$ – Joe Feb 21 at 19:08
  • 2
    $\begingroup$ @MarkBennet My feeling is that the best format is a Q&A. The "question" should contain the basic idea "We use MathJax here... how does that work?", and each answer should contain some useful information which addresses a basic problem. The question should have an index of those answers. $\endgroup$ – Xander Henderson Feb 22 at 18:42
  • $\begingroup$ @XanderHenderson: Would you suggest then that this answer should be broken into smaller pieces? $\endgroup$ – Joe Feb 22 at 18:56
  • 2
    $\begingroup$ @Joe I am typically more of a "splitter" than a "lumper" (e.g. I would prefer to prove four or five short lemmata before getting to main theorem, rather than prove the main theorem all at once). As such, I generally err on the side of smaller, more digestible chunks. However, I don't have the time or energy to take on this project, so I am not sure that my opinion counts for very much (which won't prevent me from giving it, but...). $\endgroup$ – Xander Henderson Feb 22 at 19:28
  • $\begingroup$ I think the thing about "Show Math as" in point $2$ could also be extracted as a separate point (since the aim is pedagogical and basic I don't think repetition is too much of a problem). I seem to remember that I learned a lot by using this simple function on questions and topics that interested me to answer "well how did they do that then?" $\endgroup$ – Mark Bennet Feb 22 at 21:25
  • $\begingroup$ @MarkBennet: Where do you suggest the 'Show Math As' section should go? Do you mean I should post a separate answer with the same information, just so that it is impossible to miss? $\endgroup$ – Joe Feb 23 at 9:45
  • $\begingroup$ @Joe If there were several short articles a "How did they do that ..." or "How do I learn from what other people have done ..." piece as stand alone would work. Then with the other pieces there could be "as you get more engaged with the site you can explore how other people have formatted their posts" section near the beginning. I am just trying to think how people who are learning will best be helped. $\endgroup$ – Mark Bennet Feb 23 at 10:49
  • $\begingroup$ @MarkBennet: Sounds good. Perhaps if more people post answers it will be clearer how exactly to format things, but having a sort of directory with that information is a good idea. By the way, have you voted to reopen your own post? (Apparently you can do that.) $\endgroup$ – Joe Feb 23 at 21:43
  • $\begingroup$ @TeresaLisbon: Hi Teresa. Have you began the revamp of the Mathjax tutorial yet? $\endgroup$ – Joe Mar 4 at 19:57
  • $\begingroup$ @Joe No, some personal tasks have taken over my time on MSE a little bit, so I have not been able to dedicate to meta MSE, let alone the MathJax tutorial page. I cannot set a time frame, but I am actually working from home currently and will shift back to hostel in some time which gives me more time to work. So I will start this activity once I get back, hopefully next week. Thank you for asking! $\endgroup$ – Teresa Lisbon Mar 5 at 2:31
9
$\begingroup$

Some Dos and Don'ts based on a little time in the review queues

Do type each equation inside a single pair of dollar signs $...$, or $$...$$. This is both easier than the alternative, and correct: instead of $x$=$y$+$z$$x$=$y$+$z$, you should write $x=y+z$$x=y+z$.

Do type all mathematics inside Mathjax, even if you don't need a special symbol like $\aleph$ or $\beta$ e.g. $1 = 9 - 8$, instead of 1= 9-8.

Do check the preview to see if what you typed is indeed what you wanted to say!

  • If you do not catch the errors, then you may get answers to a question you didn't want to ask.

Do edit your current post to include Mathjax when someone sends you to this page, instead of asking a new question or posting a new answer.

  • Also make sure your question (if you are asking one) has context: using Mathjax is not enough to prevent close votes and downvotes.

Don't rely on Unicode characters!

  • They don't always 𝕑𝕝𝕒π•ͺ π•Ÿπ•šπ•”π•–. Mathjax is not only a way to put fancy symbols on the page. Mathjax is easy to read and consistent on any device.

Don't upload pictures of maths that can be easily typed!

  • See discussion here. It's more understandable if you are sharing a larger part of a document, but do consider if you really need to share it as less people will read long posts!

Don't use \dfrac,\limits and \displaystyle too often.

  • It makes your post messy and unprofessional. If you need to make mathematics on the site appear bigger to you, you can adjust your Mathjax preferences (see instructions here). Also, using them in titles makes them much larger than other titles, which is discouraged.
$\endgroup$
8
  • $\begingroup$ Not sure if this is what you're going for, but lets see the votes I get on this...suggestions welcome of course $\endgroup$ – Calvin Khor Feb 27 at 8:57
  • $\begingroup$ I hadn't thought about the learning from reviewing angle - but since the goal would be to help people when they need it most, that is a very useful perspective. I also like the way you have put it as Dos and Don'ts - there is something about inducting people into the culture of these things as well as the technical aspects - and that arises not so much from the questions of the learner, but from sometimes mysterious and unstated conventions. Thank you! $\endgroup$ – Mark Bennet Feb 27 at 9:39
  • $\begingroup$ Nice answer. I have added it to the table of contents. $\endgroup$ – Joe Feb 27 at 10:55
  • $\begingroup$ +1 nice idea. Perhaps the existence of the MathJax chatroom should be mentioned too, in case someone have doubts about how to type. $\endgroup$ – Verónica Rmz. Feb 27 at 16:15
  • $\begingroup$ @veronika That’s very good to mention but I’m not sure it is the most useful for absolute beginners as chat rooms in SE require you to have a little bit of rep first...! $\endgroup$ – Calvin Khor Feb 27 at 21:26
  • $\begingroup$ @CalvinKhor Yes, you need 20 of reputation. $\endgroup$ – Verónica Rmz. Feb 28 at 4:12
  • $\begingroup$ IIRC I think I once read a Martin's (post? or comment?) that the 20 of reputation can be from another site, so you could have zero of reputation (actually not even having an account! :) and yet, comment on chat. $\endgroup$ – Verónica Rmz. May 26 at 6:01
  • $\begingroup$ @VerónicaRmz. I believe you are right. This is why your reputation in chat is not the same as the reputation on Math.SE; it is the combined reputation on all SE sites (ie excluding SO, MO, and Meta.SE iirc) Still an issue for completely new users of SE, but not every new user of Math.SE $\endgroup$ – Calvin Khor May 26 at 6:23
7
$\begingroup$

This answer focuses on calculus notation. I have broken this section off from the beginners tutorial because I'm not convinced that it is essential for new contributors to be aware of the following commands. Personally, I have no issue with a beginner writing "how do I integrate $x^2$" as opposed to "evaluate $\int x^2 \, dx$".


Calculus notation: this section briefly covers some of the most commonly used notations in calculus, namely series, limits, derivatives, and integrals. To begin with, a series such as the one below can be written using the following commands:

1 + \frac{1}{2} + \frac{1}{3} + \frac{1}{4} + \dots = \infty

$$ 1 + \frac{1}{2} + \frac{1}{3} + \frac{1}{4} + \dots = \infty $$ The above line of code uses the commands \dots and \infty, which are both useful to be aware of. The same series can be written using sigma notation.

\sum_{n=0}^{\infty}\frac{1}{n} = \infty

$$ \sum_{n=1}^{\infty}\frac{1}{n} = \infty $$ This is another example of when you need to use both an underscore _ (for the lower bound) and a superscript ^ (for the upper bound) to properly format the sum. Integrals follow the same pattern:

\int_{0}^{\infty}\frac{\sin x}{x} \, dx = \frac{\pi}{2}

(It's good style to leave a thin space \, between the integrand and the $dx$, but again this is not necessary.) $$ \int_{0}^{\infty}\frac{\sin x}{x} \, dx = \frac{\pi}{2} $$ With both sums and integrals, you can also omit the upper and lower bounds:

\text{mean} = \frac{\sum x_i}{n} \\
\int \sec x \, dx = \log\left|\sec x + \tan x\right|+ C 

$$ \text{mean} = \frac{1}{n}\sum{x_i} \\ \int \sec x \, dx = \log\left|\sec x + \tan x\right|+ C $$ Derivatives are a lot easier to typeset than integrals. Leibnizian notation can be handled using \frac commands:

\frac{dy}{dx} = \frac{dy}{du} \cdot \frac{du}{dx}

$$ \frac{dy}{dx} = \frac{dy}{du} \cdot \frac{du}{dx} $$ Lagrange's prime notation can also be typeset fairly easily:

(f \circ g)'(x) = f'(g(x))g'(x)

The command \circ is sometimes used to indicate the composition of functions: $$ (f \circ g)'(x) = f'(g(x))g'(x) $$ To indicate that one number is approaching number, you can use \to. The sentence 'as $x \to \infty$, $\frac{\ln x}{x} \to 0$' is rendered by

as $x \to \infty$, $\frac{\ln x}{x} \to 0$

Limits can be typeset using \lim and are usually accompanied by an expression that indicates the value that is being approached. Again, you have to use an underscore so that things are positioned correctly.

\lim_{x \to 0}\frac{\sin x}{x}=1

renders as $$ \lim_{x \to 0}\frac{\sin x}{x}=1 $$

$\endgroup$
6
  • $\begingroup$ Notice the conspicuous typographical difference between $\log|\sec x + \tan x|$ and $\log\left|\sec x + \tan x\right|.$ $$ \begin{align} {} \\ & \log|\sec x + \tan x| \\ \text{versus} \\ & \log\left|\sec x + \tan x\right| \\ {} \end{align} $$ $\endgroup$ – Michael Hardy Feb 25 at 15:09
  • $\begingroup$ @MichaelHardy: would you suggest that I change it to \left| and \right| then? $\endgroup$ – Joe Feb 25 at 15:18
  • $\begingroup$ Yes. That's what I do when this happens. $\qquad$ $\endgroup$ – Michael Hardy Feb 25 at 18:22
  • $\begingroup$ @MichaelHardy: Okay, I've fixed it now. $\endgroup$ – Joe Feb 26 at 9:58
  • 1
    $\begingroup$ This is more like LaTeX 201 than LaTeX 101, but getting absolute value bars and norm double bars right (especially when they surround something large) are a massive pain-in-the-ass to get right (which I don't think I do.) If someone wrote up a short and sweet answer for that it would certainly help me. $\endgroup$ – JonathanZ supports MonicaC Feb 27 at 23:05
  • $\begingroup$ How about $\log \mid \sec x + \tan x \mid$. $\endgroup$ – steven gregory Mar 1 at 3:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .