as-com / wp-katex

Integrates the fast KaTeX LaTeX typesetter with WordPress
https://andrewsun.com/projects/wp-katex/
GNU General Public License v2.0
9 stars 5 forks source link

Spurious <br> tags rendered #7

Open delip opened 8 years ago

delip commented 8 years ago

I have a simple expression:

[latex display="true"]
\sum_{i=1}^n x_i^2
[/latex]

This renders with spurious line break tags as: image

If I look at the generated code I see:

<script type="text/katex" display="true"><br />
\sum_{i=1}^n x_i^2<br />
</script>

Why is this happening? I'm using Version 1.5.1 (installed today on a fresh WP instance and I have not enabled the default wp latex).

as-com commented 8 years ago

Hi,

This is happening because you have line breaks within the shortcode. WordPress automatically converts line breaks into <br />'s, so you will need to make sure your equation is on one line.

I will add code to handle these situations in a future release.

delip commented 8 years ago

That was the problem. Removing the linebreaks removed the <br/>s, for longer equations such as this, it would be nice to write the latex out on a seperate line.

[latex display="true"]\int_S \bigl| f(x)g(x)\bigr| \,\mathrm{d}x \le\biggl(\int_S |f(x)|^p\,\mathrm{d}x\biggr)^{\frac{1}{p}} \biggl(\int_S |g(x)|^q\,\mathrm{d}x\biggr)^{\frac{1}{q}}.[/latex]

Agree this is now an enhancement. Thanks!

fdeitelhoff commented 7 years ago

Is a solution maybe (my WordPress plugin development skills are somewhat rusty) to create a handler and strip out the changed line breaks (the HTML?). Or is WordPress the last one changing those snippets?

as-com commented 7 years ago

@fdeitelhoff There are a number of possible solutions (stripping the tags in the shortcode processor, this thing, this thing, and this thing), but they all look like ugly hacks to me.

fdeitelhoff commented 7 years ago

@as-com Okay, I see. Then we need to decide if the hack is worth preventing the problem?

I think it is an important feature to have multi-line LaTeX short-codes. Especially because LaTeX needs them in some scenarios.

Rabelaiss commented 4 years ago

A workaround for this is removing htmlspecialchars from $enc = htmlspecialchars( html_entity_decode( $content ) ); in the file frontend.php. But I don't know what are the possible bad consequences of this.