I asked a question, titled https://chemistry.stackexchange.com/questions/636/reactions-of-metals-with-cehcl-ceh2so4-cehno3, and noticed that the formulas had 'ce' prepended to them in the url: reactions-of-metals-with-cehcl-ceh2so4-cehno3.

This doesn't make sense to me; looks like a bug in slug generation, which should be taken care of?

  • 23
    $\begingroup$ Everything needs more cerium. $\endgroup$
    – Aesin
    Commented Sep 24, 2012 at 20:00

4 Answers 4


This is an unavoidable side-effect of putting LaTeX-formatted equations in titles.

If part of a title is important enough that you want folks to be able to search for it, don't format it using LaTeX.

  • 2
    $\begingroup$ Issue is, if we don't use LaTeX, it looks ugly on the main page. If we use LaTeX, it looks ugly on Google (and trips up search). IMO a simple .replace(/\$\\ce\{([^}]+)\}/ig,"$1") in the <title> generator (and slug generator) ought to do the trick (though it may break for nested braces). Though I don't know if it's possible to make such site-only changes, especially for beta sites. $\endgroup$ Commented Jun 18, 2012 at 15:31
  • 9
    $\begingroup$ You have to remember, titles are considered to be straight-up text just about everywhere - it's not just Google or the <title>, anywhere that title is displayed that isn't explicitly MathJax enabled (or filtered) will look odd. That includes your SE.com profile, SE.com filters, the "hot" list on other sites, SEDE / data-dump clients, email notifications, newsletters, and probably other places I'm not thinking of right now. The handful of places where titles with LaTeX don't look odd are the real anomaly here - keep that in mind... $\endgroup$
    – Shog9
    Commented Jun 18, 2012 at 17:16
  • 2
    $\begingroup$ (As for the feasibility of custom filtering for mhchem expressions, that's probably not going to happen; it'd be easier to just block them entirely. I'd prefer to put that decision in the hands of the editors here, to be made on a case-by-case basis, but...) $\endgroup$
    – Shog9
    Commented Jun 18, 2012 at 17:17
  • $\begingroup$ @Shog9 I feel implementing html in titles would be better. I doubt if that has the same effect as MathJax does, but maybe it could fix this issue, and make the title look "cleaner". $\endgroup$ Commented May 22, 2017 at 2:39
  • 3
    $\begingroup$ The titles we feed Google (or your browser, or anything else) cannot be HTML, @Pritt. To fix the artifact, we'd have to selectively discard parts of the formula in order to convert it to text; I'm not sure this is possible without also being misleading in some cases. $\endgroup$
    – Shog9
    Commented May 22, 2017 at 2:50

The slug strips out all special characters and replaces spaces with en dashes. The title used MathJax for formatting (raw text: Reactions of metals with $\ce{HCl}$, $\ce{H2SO4}$, $\ce{HNO3}$?), so you can see where the ce came from.

I'm not as concerned about the URL slug{*} as I am about the displayed title in Google/etc. Google shows the mathjax dollar signs, etc, which looks ugly.

enter image description here

One fix for this would be to limit mhchem in titles. This can be done either forcibly (i.e, make the devs block it), or by just discouraging it.

We can discourage it by:

  • Editing it out of titles
  • Letting users know by comments ("Please do not use mathjax in titles, it is discouraged [linky link]")
  • Ask the devs to put a little popup when mhchem is detected in titles ("Mhchem is discouraged in titles, are you sure you want to use it?")

Note that I'm fine with mathjax in titles, just not the use of \ce.

*That may be just me--I generally don't find any need for the slug. But I can see how others may find it useful.


Interesting alternative: Use Unicode!

F'x tried it out here: Why do H₂ and O₂ create H₂O?, and it's come out pretty nice. Nuances:

  • Shows up properly (in Chrome atleast) wrt the page <title> and the header.
  • Searching for the title sans unicode doesn't work on Google
  • But the Unicode shows up if you're looking for the body
  • The URL slug is still dead: https://chemistry.stackexchange.com/questions/1164/why-do-h-and-o-create-ho
  • $\begingroup$ I just made an edit replacing a unicode "∆" with "\Delta" after viewing the question on the Stack Exchange for Android app, and seeing that the app didn't render the unicode delta character in the question, but did render the MathJax delta character in one of the answers. So this might be another nuance to list. Compatibility with the official app is definitely a worthy goal. $\endgroup$ Commented Sep 15, 2015 at 13:40

In my opinion, forbidding or discouraging MathJax/LaTeX in titles is the wrong thing to do; there ought to be a programmatical solution to this. Maybe the titles should be stored as is, but output in the following format:

  Reactions of metals with <span class="mathjax" data-mathjax="$\ce{HCl}$">HCl</span>...

Then the JavaScript parser would replace the contents of the spans with the parsed code. This way, we have a "normal" title for search engines, screen readers, JS-disabled browsers, etc., and don't lose the important capability of having nicely formated formulas in our titles.

As for the slugs, stripping LaTeX from the title before generation would actually be fairly simple IMO.


You must log in to answer this question.

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