How to display en-dash using MathJax?

1,885 views
Skip to first unread message

Lone Learner

unread,
Feb 25, 2012, 8:02:45 AM2/25/12
to MathJax Users
In LaTeX, a sequence of two consecutive hyphens (--) is automatically
rendered as an en-dash (-). I am unable to do this on MathJax.

For example, \(1--9\) in MathJax would end up displaying 1--9 instead.
The hyphens are rendered as minus signs. Here is a demonstration:
http://jsfiddle.net/ABDBG/

How can I correctly display an en-dash in MathJax?

Davide P. Cervone

unread,
Feb 25, 2012, 10:11:22 AM2/25/12
to mathja...@googlegroups.com

MathJax does not do ligatures (as they are for text-mode rather than
math-mode, in general), and that is how the en-dash is generated from
-- by TeX.

I'm not quite sure of you ruse case, as a page reference like 1--9
would be in text mode not math mode, so I would expect to do
1–9 or just insert the en-dash directly, 1–9. MathJax will
process either one of these, if you really need it in math mode, or
you can do \(1\unicode{x2013}0\) if needed. You can \def\-
#1{\unicode{x2013}} if you want to be able to do \(1\--9\) instead.

But it sounds to me like you are trying to use MathJax to handle
something as math that is better treated as text.

Davide

jea...@gmail.com

unread,
Feb 28, 2018, 4:17:41 PM2/28/18
to MathJax Users
An example could be representing arcs in undirected graphs, i.e., one would write "$u$--$v$" in LaTeX, or, a bit uglier but in one math environment: $u\text{--}v$. Does one really need to resort to unicode to get the same effect in MathJax?

David Farmer

unread,
Feb 28, 2018, 4:22:39 PM2/28/18
to MathJax Users

If edges in graphs is really your use case, then write it
as $u \edge v$. The meaning is clear, and you can define the
macro in whatever way makes it look right (presumably unicode,
but there may be other options).

If that was a made-up example, then please describe your actual
use case and we can try to make a useful suggestion.
> --
> You received this message because you are subscribed to the Google Groups "MathJax Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> mathjax-user...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>

Davide Cervone

unread,
Mar 1, 2018, 12:58:58 PM3/1/18
to mathja...@googlegroups.com
Does one really need to resort to unicode to get the same effect in MathJax?

Yes.  The -- ligature in TeX is a text-mode feature, not a math-mode one (e.g., $u--v$ will not produce the same thing as $u$--$v$ in TeX).  MathJax does not process any macros in text-mode, including those within \text{}, and that is not likely to change (though I have pointed out in the past several ways that you can extend MathJax's text-handing abilities (e.g., https://github.com/mathjax/MathJax/issues/1236#issuecomment-129222235 or https://groups.google.com/forum/#!topic/mathjax-users/wSh6-hSIUpQ, or you could use a post filter on the TeX input jax to convert \text{--} to \unicode{x2013} internally), so if you are able to set the MathJax configuration, you would be able to get your example for $u\text{--}v$ to work if you wanted it bad enough.

But since your preferred markup is $u$--$v$, where the -- is outside of MathJax's processing entirely, you can, of course, use something like $u$–$v$ in an HTML page to get it, or even $u$–$v$ (if the page has the proper encoding).  These are the HTML ways of getting the result you are looking for (and since you are working an an HTML document, not a TeX one, that is how you need to proceed).

As I have mentioned in my earlier response in this thread, $u\unicode{x2013}v$ would get what you want in MathJax, and as demonstrated earlier, you can make a macro for that to make it easier.  If you want something more directly TeX-like, you can do $u\mathord{-}v$ which is pretty close, though not identical.

Davide

Reply all
Reply to author
Forward
0 new messages