Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#30445 closed defect (bug) (fixed)

Math formulas displaying oddly

Reported by: pczatdalton's profile PCZatDalton Owned by:
Milestone: 4.1 Priority: high
Severity: normal Version: 4.0
Component: Formatting Keywords: has-patch
Focuses: Cc:

Description

Mathematical formulas in the form of <numeral>x-<numeral> don't display properly in posts. The x becomes small and superscripted. When included in a LaTeX block, it causes the formula to be unrenderable.

For example: 2x-1 and $latex 2x-1 $ both exhibit this bug.

Confirmed in 4.0 and 4.0.1, with a fresh installation and no plugins, and the default theme.

Attachments (2)

30445.diff (712 bytes) - added by rmccue 10 years ago.
Change regex to not include -
30445.2.diff (1.2 KB) - added by rmccue 10 years ago.
Include unit tests

Download all attachments as: .zip

Change History (23)

#1 @SergeyBiryukov
10 years ago

  • Component changed from General to Formatting

#2 follow-up: @nacin
10 years ago

How do you use LaTeX in your posts? With a shortcode from a plugin?

#3 @nacin
10 years ago

  • Version changed from 4.0.1 to 4.0

#4 in reply to: ↑ 2 @PCZatDalton
10 years ago

Replying to nacin:

How do you use LaTeX in your posts? With a shortcode from a plugin?

We're using the WP Latex plugin like so: $latex <theformula>$

However, the problem crops up even when writing straight text w/o passing it through LaTeX. But when we do render it with LaTeX, it causes the rendering to fail.

#5 follow-up: @miqrogroove
10 years ago

Example page? Screenshot? Any other helpful info?

#6 @miqrogroove
10 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

Found the patch here:

https://plugins.trac.wordpress.org/changeset/982453/

You will need to contact the plugin author about getting that next version released so that it will be an easy update.

#7 in reply to: ↑ 5 @PCZatDalton
10 years ago

Replying to miqrogroove:

Example page? Screenshot? Any other helpful info?

It's extremely easy to reproduce. Just type, for example, "2x-1" into a post. See what happens to the x? Now type "$latex 2x-1$" into a post. See how it doesn't render?

Changing the "x" to, say, a "y" doesn't exhibit the problem. Nor does changing the minus to a plus or putting a space between the "x" and the minus sign. See the examples in the screen shot, below:

http://www.lugal.com/files/misc/WPrenderingBug.png

Note that once the problem was noticed on our school blog, I made a new installation of WP on my testing server, and the problem persists there. I didn't install WP Latex or test LaTeX rendering on that test server, however, because the plain jane installation already exhibited the weird behavior wherein it changed the x to a small raised x--and this seems to be the problem that's interfering with the LaTeX rendering.

#8 @PCZatDalton
10 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

#9 follow-up: @miqrogroove
10 years ago

  • Resolution set to worksforme
  • Status changed from reopened to closed

Please contact the plugin author about this.

#10 in reply to: ↑ 9 ; follow-up: @PCZatDalton
10 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

Replying to miqrogroove:

Please contact the plugin author about this.

Miqrogroove-

I'm sorry to be rude about this, but you're clearly not reading my comments. The problem PRECEDES the WP Latex plugin. It's a problem in the core, that renders incorrectly in the core, and causes a fatal error in the WP Latex plugin.

This is a problem for our math teachers, whether or not they use Latex, so please stop marking this case closed. It is not. Ok?

Last edited 10 years ago by PCZatDalton (previous) (diff)

#11 in reply to: ↑ 10 @rmccue
10 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 4.1

Hi PCZatDalton, thanks for the bug report here.

Here's what seems to be happening with the issue. wptexturize takes care of changing certain characters, such as -- to an en dash. One of the things it handles here is changing the `x` in 9x9 to a real multiplication symbol. (For example, something like 1024x768)

This was changed in r28719 (#19308) to also include negative numbers, but it looks like it might be an issue, since x is also a valid variable name. While the LaTeX plugin could be fixing this, it'd really be a workaround.

I'd suggest we remove the - from the regex, so that it only matches 9x9 not also 9x-9, which is ambiguous.

#12 follow-ups: @miqrogroove
10 years ago

PCZatDalton, I suggest installing the Jetpack version of latex. While rmccue is correct that we could hack the core code to change the behavior of minus signs, it would not fix the underlying bug in the plugin.

#13 in reply to: ↑ 12 @PCZatDalton
10 years ago

Replying to miqrogroove:

PCZatDalton, I suggest installing the Jetpack version of latex. While rmccue is correct that we could hack the core code to change the behavior of minus signs, it would not fix the underlying bug in the plugin.

The problem is, as rmccue points out, that wptexturize is overly aggressive. This means that, even if the formula is not processed as LaTeX, it still displays incorrectly.

Our use case is such that this behavior (turning 'x' into the multiplication symbol) is rarely, if ever, desired--but I can see how others may see it as the more common approach. If the consensus opinion is that it is currently behaving correctly, then I'll suggest to the WP Latex maintainers to implement the patch that you found, and I'll tell my math teachers to update their usage accordingly.

#14 in reply to: ↑ 12 @rmccue
10 years ago

Replying to miqrogroove:

While rmccue is correct that we could hack the core code to change the behavior of minus signs, it would not fix the underlying bug in the plugin.

The plugin should be updated to run before texturize for sure, but the core behaviour here is absolutely wrong, and we should fix it regardless. :)

This ticket was mentioned in Slack in #core by miqrogroove. View the logs.


10 years ago

#16 @helen
10 years ago

  • Milestone changed from 4.1 to Future Release

We're on the late side for addressing this in 4.1, let's get a patch going here and do 4.2.

#17 @nacin
10 years ago

  • Milestone changed from Future Release to 4.1
  • Priority changed from normal to high

This is a 4.0 regression and would be an easy regex fix, so bringing this back to 4.1.

@rmccue
10 years ago

Change regex to not include -

@rmccue
10 years ago

Include unit tests

#18 @rmccue
10 years ago

Added patch and tests.

#19 @miqrogroove
10 years ago

  • Keywords has-patch added; needs-patch removed

Patch looks good.

The allowance for negative signs came from a 3-year-old patch at https://core.trac.wordpress.org/attachment/ticket/19308/19308.patch and it wasn't considered a regression until now.

This ticket was mentioned in Slack in #core by miqrogroove. View the logs.


10 years ago

#21 @markjaquith
10 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

Bot failure?

In [30752]:

Revert [28719] and no longer math-process multiplication of negative numbers
see #19308
fixes #30445
props rmccue

Note: See TracTickets for help on using tickets.