16

If a post contains math expressions as plain text, would it be wise to edit that post to make formulas more comprehensible? For example, this answer:

https://stackoverflow.com/a/28444157/1542343

Are there any guidelines on math formulas formatting? Unfortunately SO doesn't support LaTeX, but should I probably wrap expressions in italics, or backticks for code, or place each formula into a separate paragraph?

Some posts advise to use Google Spreadsheets, and visually that is almost as good as LaTeX on math.stackexchange.com, but unfortunately that would be incredibly tedious.

4
  • 6
    Despite the OP's objections, that question does not appear to be about programming anyways. I'm sure someone would need this in a valid context though. Feb 11, 2015 at 18:49
  • 1
    Should I edit posts containing "formulas" to use "formulae", too? :)
    – rickster
    Feb 13, 2015 at 17:48
  • You could use code snippets.
    – AstroCB
    Feb 13, 2015 at 20:55
  • Unfortunately the page you take as an example is now a 404 :-( Feb 28, 2018 at 22:46

3 Answers 3

12

I don't see a problem with that answer; the formulas seem easy enough to follow. In some cases (lengthy or complicated formulas perhaps) you might wish to use code block formatting to make them easier to follow, but for simple formulas this usually shouldn't be necessary.

Resist the urge to use inline code formatting just for the heck of it. It works great for making actual code easier to read (less confusion between, say, O and 0) but otherwise just makes the text look busy.

14
  • 2
    While it's on your mind, what do you think the chances are of getting MathJax over here? It's used on Math.SE and CS.SE, and it makes life ever so much more pleasant.
    – dfeuer
    Feb 12, 2015 at 5:29
  • 3
    None. Waaay too heavy for SO
    – Shog9
    Feb 12, 2015 at 5:30
  • 2
    @dfeuer That's was discussed more than once, with a lot of proposals. You should probably read some of these questions: meta.stackoverflow.com/search?q=mathjax
    – Bakuriu
    Feb 12, 2015 at 12:28
  • 1
    There's a lot wrong with all the equations on that page. The tag is java, and x^y is bitwise-XOR. You can't get the desired curve using XOR no matter how hard you try.
    – Ben Voigt
    Feb 13, 2015 at 0:57
  • @BenVoigt He's probably using the mathematical notation
    – user4413591
    Feb 13, 2015 at 1:34
  • @Shog9 It took me a good while to figure out the difference between 0 and O
    – user4413591
    Feb 13, 2015 at 1:34
  • @Isaiah: I doubt it. In mathematical notation, ^ means logical intersection (AND, written in Java as &&). XOR is a plus inside a circle. And exponentiation uses a superscript. There's really no reason to use ^ as exponentation except in source code of a language such as MATLAB or BASIC that uses it that way.
    – Ben Voigt
    Feb 13, 2015 at 5:06
  • interpreting those formulas as Java makes very little sense, @Ben. Although now I'm somewhat curious to know if there's any usable way of constructing a function that works as an lvalue in Java.
    – Shog9
    Feb 13, 2015 at 5:15
  • 4
    @BenVoigt ^ for superscript is standard in TeX, and is also used when communicating math in plain text (partly as TeX influence, but also because Knuth did not pick the symbol ^ for superscript at random). The symbol for logical intersection, ∧, is different in that it stands on the baseline. I never saw ^ used in mathematical writing for logical AND.
    – user3717023
    Feb 13, 2015 at 5:29
  • @FamousBlueRaincoat: Of course \wedge is preferred, but this website doesn't do TeX or MathJax, and my keyboard doesn't have a wedge button. And yes, ^ is superscript in TeX, not exponentiation. A whole lot of other things use superscript too, from limits to atomic numbers/weights. So using ^ in the context of TeX for any of those is appropriate, because ^ means superscript in TeX. Using ^ in the context of Java to mean XOR is appropriate, because ^ means bitwise-XOR in Java.
    – Ben Voigt
    Feb 13, 2015 at 5:35
  • @BenVoigt Actually, ^ is used in some scientific and graphing calculators to indicate exponentation.
    – user4413591
    Feb 13, 2015 at 14:51
  • ASCIIfied wedge is almost always /\ instead of ^. Feb 13, 2015 at 20:41
  • @BenVoigt: ah, but of course HTML also has ∧! So there needs no compromise to be made here. (In general, if you know a LaTeX command that would give you some desired symbol, it's a good idea to just try it out as a HTML entity: many of them work just like that.) Feb 14, 2015 at 8:43
  • @Isaiah: Many scientific and graphing calculators run BASIC.
    – Ben Voigt
    Feb 14, 2015 at 16:44
12

Do not use code blocks or inline code formatting for maths expressions. However, “lightwight math-formatting” by a simple combination of markdown italics and html definitely makes such expressions more readable, like (from the linked post – though, as already said, such a mass of formulas isn't appropriate on SO):

If I understand what you're trying to do correctly, it seems you want your curve to match the blue linear function better until it crosses it. I would suggest adding a portion of the linear function to your curve. y = m·x and y = bx would yield y = bx + a·m·x where a is a value between 0 and 1, ie y = 3x + ⅓ · 2·x if b was 3 and m was 2. Then you'd be adding ⅓ the value of 2·x to the curve and effectively pushing the curve up toward the line generated by the function y = 2·x.

I'm sorry if that sounds rambling. My suggestion basically is to take your function for the blue line and add ¾ of it to the function that generates your curve. It looks to me like the function of the blue line is f(x) = y so I think
f(x) = 10((y × 0.00925)/77000)/0.00001 + ¾ · y
should give you about what you want.

Often, one can alternatively use unicode characters directly to achieve much the same effect. That gives a nicer view in the plaintext editor.

I recommend considering the following tweaks:

                 ┃ Plaintext  │ MD+html            │ Unicode
 ────────────────╂────────────┼────────────────────┼────────────
         Numbers ┃   7        │ 7                  │ 7
       Variables ┃   x        │ _x_                │ 𝑥
          Powers ┃   2^3      │ 2<sup>3</sup>      │ 2³
  Multiplication ┃   2x       │ 2&middot;_x_       │ 2·𝑥
                 ┃   4*7      | 4&times;7          │ 4×7
       Fractions ┃   3/4      | &frac34;           │ ¾
                 ┃   9/16     | <sup>9</sup>&frasl;│ ⁹⁄₁₁
     Subtraction ┃   5-3      │ 5 &minus; 3        │ 5 − 3
    Logical AND/ ┃   P&&Q     │ _P_&wedge;_Q_      │ 𝑃∧𝑄
   outer product ┃   dx^dy    │ d _x_&wedge;d _y_  │ d𝑥∧d𝑦
      Logical OR ┃   P||Q     │ _P_&vee;_Q_        │ 𝑃∨𝑄

I mostly use Vim digraphs for typing the Unicode versions.

Whether it's actually worth to apply these prettifications to an existing post depends of course on the content quality and on how much the readability suffers from the used unformatted-math.

5
  • As is the case with the linked post, every question or answer that needs such an amount of math formatting is probably off-topic for SO anyways...
    – l4mpi
    Feb 12, 2015 at 13:48
  • 2
    @I4mpi: Certainly. But two or three small maths expressions can often be very appropriate, and for such cases the simple html format is just right. Feb 12, 2015 at 13:52
  • Some programming is intensively mathematical; I don't see why questions (or answers) which involve mathematical descriptions would be considered off-topic. (This is particularly true of questions about correct or optimal computation of numerical formulas where loss of precision is a risk; that is definitely a programming problem.) Generally I like your format suggestions; I just wish there were a way to type them without so much keyboarding. _x_<sub>_i_</sub><sup>3</sup> is a lot of keystrokes compared with $x_i^3$.
    – rici
    Feb 14, 2015 at 2:09
  • @rici: true, the redundant closing HTML tag names are really a pain. I wonder if Pandoc or something can convert LaTeX to this format? Feb 14, 2015 at 8:49
  • But don't go prettifying the logical operations, use the operator appropriate to the language tag on the question.
    – Ben Voigt
    Feb 14, 2015 at 16:46
2

In the case you found, an emphatic YES!

Whenever you find usage (in descriptive text) of ^ to mean exponentiation in a tag where it doesn't (i.e. in , , , it means bitwise-XOR), replace it with a real superscript using <sup></sup> as leftroundabout mentioned.

If you find ^ used in a code block where exponentiation is intended, don't edit because that's a huge change to the meaning. Instead, leave a comment, and also downvote (if an answer) or vote to close as duplicate of the language-appropriate question about the meaning of ^ (if a question).

Do be aware, however, that MATLAB and some forms of BASIC do use ^ for exponentiation. Probably some others too.

2
  • "In the case you found, an emphatic YES!" - What exactly would be the use of editing an answer to an off-topic question that should be deleted, not answered?
    – l4mpi
    Feb 13, 2015 at 7:56
  • @l4mpi: It depends what characteristics we are using to define "in this case". I thought I was pretty clear that I'm talking about usage of ^, in C-like languages, with a meaning other than XOR.
    – Ben Voigt
    Feb 14, 2015 at 16:47

You must log in to answer this question.

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