I am new to MathJax. I copied some the code from the MathJax basic tutorial and quick reference


Then I edited it to get more rows for the matrix


Whilst my code got the job done, it is messier than the code I started with. Is any resource which outlines conventions or provides advice for typing MathJax formulas neatly? I am far more familiar with mathematical conventions than programming conventions!

  • 4
    $\begingroup$ What do you mean it is messier? (also, I think the $ signs are a typo) $\endgroup$ – AnalysisStudent0414 Dec 11 '15 at 12:04
  • 2
    $\begingroup$ You might find the \begin{bmatrix}...\end{bmatrix (for square brackets) and \begin{pmatrix}...\end{pmatrix} (for round brackets) environments simpler to use for actual matrices (rather than for tables/arrays). If it's an augmented matrix you wanted, you can create vertical separator entries in the matrix with \mid or simply |. $\endgroup$ – hardmath Dec 11 '15 at 16:22
  • $\begingroup$ @hardmath Thanks for that. $\endgroup$ – Bernard W Dec 13 '15 at 11:53
  • $\begingroup$ @AnalysisStudent0414 Yes, the $ were a typo. I mean it is messier in that the first code is nicely formatted (with indentations and so forth) wheras when I input matrices, I can't get the same formatting. $\endgroup$ – Bernard W Dec 13 '15 at 11:55
  • 3
    $\begingroup$ @BernardWojcik, just add some spaces in front of the line you added. $\endgroup$ – Antonio Vargas Dec 13 '15 at 12:24
  • $\begingroup$ @AntonioVargas hmmm I could swear I tried that and it didn't work before-which is why I got confused and asked this question! Maybe it was all an illusion... $\endgroup$ – Bernard W Dec 13 '15 at 12:43
  • $\begingroup$ Also, I am not sure why this was downvoted? Not to say that it shouldn't be. There seems to be many conventions on this site, so why not conventions regarding the formatting of code? It seems like a legitimate question, even if no is the answer. $\endgroup$ – Bernard W Dec 13 '15 at 12:44
  • $\begingroup$ I'm not a downvoter, but down voting on Meta has different connotations from how things work on Main. For one thing down voting has no effect on reputation (nor does up voting for that matter). Rather down voting is often a measure of agreement/disagreement with proposed ideas, and some may have taken your Question to essay that there should be conventions for MathJax (code) formatting and wanted to indicate disagreement with that idea. $\endgroup$ – hardmath Dec 13 '15 at 17:31
  • $\begingroup$ I think not few found your question simply unclear. I will try to write an answer. $\endgroup$ – quid Dec 13 '15 at 18:09

There are no specific guidelines on how to format the source of MathJax code on this site. I am not sure there exist any at all. The closest thing I am aware of are coding style guidelines for LaTeX. However, I think this is mainly relevant for larger documents.

Here is some general advice:

  • Use line breaks to highlight the structure. This is done in the example; one could in theory also write everything on one line. The double-backslash would take care of the line-break when compiled.
  • Use space. This is not really done in the example. Yet I'd find a & 0 & b & 2 easier to parse. It would also emphasize that the entries are in a way 'separated' by the ampersand.
  • You can use indentation (just type space several times) to highlight that something is inside an environment. But it is not a necessity either. (Be careful though that indentation for text will have a consequence on the formatting; it means that this is a code-block and will be formatted as such. But if it is inside dollar it should be fine.)
  • Finally, keep it simple. Try to avoid complicated constructs and rather break them up with some words. Moreover, it can make sense to use macros only sparsely as this can make editing by others harder and moreover there can be unwanted interferences.
  • 2
    $\begingroup$ Thanks, this is what I was after. $\endgroup$ – Bernard W Dec 13 '15 at 23:03

You must log in to answer this question.

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