Unwanted breaking of punctuation: display mode & inline

99 views
Skip to first unread message

Peter Cao

unread,
Jan 30, 2011, 10:54:09 AM1/30/11
to MathJax Users
Unwanted breaking of punctuation occurs on two different occasions:

INLINE:
(1) when a unit of math text is typed immediately after and before
plain html text (especially punctuation characters), they are not
treated as a a coherent word, and automatic line breaking at the end
of the line breaks them up.
The most notable example is when math is wrapped in inverted commas,
at the end of a line, the inverted commas get separated from the math,
as in Specimen 1 at:

http://www.mathannotated.com/tests/unwanted-line-breaking.html

If you are writing instructional content, this problem is encountered
more often then you would think.

DISPLAY:
(2) The second instance describes more the impossibility of having
punctuation immediately after a display item without breaking. I
mean, if you're writing material of a publishable standard, this isn't
trivial. See Specimen 2 at

http://www.mathannotated.com/tests/unwanted-line-breaking.html

Davide P. Cervone

unread,
Jan 30, 2011, 4:27:55 PM1/30/11
to mathja...@googlegroups.com
For (1), this is really a browser issue more than a MathJax one. What
the browser thinks is a valid breakpoint for line breaks is not up to
MathJax. You may want to try putting

<span style="white-space:nowrap">...</span>

around the material that should not be broken. It would probably be
possible to write a preprocessor that would insert such spans
automatically, but one is not currently in the plans.

For (2), that is simply how display math works. The mathematics is
typeset on its own line, separated from the material around it. As I
recall, you are using TeX, and that is certainly how TeX works; you
must include the punctuation within the displayed math itself, e.g.,

"the variable $x$ appears once in the fraction $${1\over 1+x}.$$ "

That is not elegant, but that is what TeX users have been doing for
more than 30 years.

Davide

Peter Cao

unread,
Jan 31, 2011, 12:02:06 AM1/31/11
to MathJax Users
Thanks for those suggestions Davide.

Solution for (1) works for me.

Solution (2) still has the problem of the punctuation not imitating
the text formatting outside of the math environment. In my case, the
math text formatting is bigger and in a different font from the rest
of the text. As such, there is some ambiguity about the meaning and
placement of a period here, for example. Since its formatting is
different from the surrounding plain text, but consistent with the
math, it might be misinterpreted as having mathematical significance.
Do you know a way to fix this, so the period's formatting is
consistent with that of the surrounding text?

Davide P. Cervone

unread,
Feb 1, 2011, 12:32:28 PM2/1/11
to mathja...@googlegroups.com
Your point about the font is well taken.  Here is one approach to overcome the problem.

Use the following as part of your configuration:

MathJax.Hub.Config({ .
.
. styles: { ".MathJax .normal": { "font-family": "font-name ! important" } }, TeX: { Macros: { normaltext: ["\\class{normal}{\\text{#1}}",1] } } });

where font-name is the name of the font you are using as the main font for your document (or a list of fonts). You can specify size and other attributes if you need to as well. Note that the "! important" is critical, and must be part of the style.

Then, in your document, use

The variable $x$ appears only once in $${1\over 1+x}\normaltext{.}$$

when you want some normal text to appear within the displayed math.

Hope that helps.

Davide

Peter Cao

unread,
Feb 1, 2011, 11:38:17 PM2/1/11
to mathja...@googlegroups.com
Thank you Davide for that helpful solution as usual.

One other issue as far as punctuation goes is that quotation marks do not seem to be supported in text mode.  In particular, I was attempting inverted commas the way that is usually recommended `` ''; this works in the general latex environment but apparently not inside text mode inside math mode.

Example: \( \text{``} \alpha \text{''} \).

Any ideas?

Thanks again,
Peter.

Peter Cao

unread,
Feb 1, 2011, 11:42:46 PM2/1/11
to mathja...@googlegroups.com
Bad example, since quotation marks for the inline instance can easily be achieved in html outside of math mode.  However, quotation marks inside text mode inside math mode becomes necessary for display math:

Example: $$ \text{``} \alpha \text{''} $$.

Peter.

Davide P. Cervone

unread,
Feb 2, 2011, 7:50:19 AM2/2/11
to mathja...@googlegroups.com
MathJax doesn't process macros (or ligatures or other TeX constructs) within text mode, so it doesn't convert `` to the open quote character.  You will have to insert that character yourself.  One way is to use

$$ \normaltext{&#x201C;} \alpha \normaltext{&#x201D;} $$

You could also use the actual encoded characters at these points, but I usually like to use the numeric entities instead, because there is no encoding issue that you have to worry about.

Davide

Peter Cao

unread,
Feb 2, 2011, 11:16:38 AM2/2/11
to mathja...@googlegroups.com
Thanks Davide; I will use this next time I come across this problem.

Keep up the good work with MathJax.

Regards,
Peter.
Reply all
Reply to author
Forward
0 new messages