WordCloud out of Images or TeX

4

3

Is it possible to use the WordCloud function to create a word cloud out of LaTeX expressions or images (with transparencies) representing equations?

Wynne

Posted 2017-02-26T17:44:39.253

Reputation: 986

would this suit you? its not quite what you asked for exp = Integrate[1/(1 - x^32), x] // Expand; exp = List @@ exp; WordCloud[ToString[HoldForm[exp // Release]], ColorFunction -> ColorData["GrayTones"]] – chris – 2017-02-26T18:14:05.770

1

If the question is "how to create a word cloud out of LaTeX expressions or images?" then the answer can be found here. You can turn LaTeX expressions into images using MaTeX.

– C. E. – 2017-02-26T18:29:12.610

@C.E. According to the documentation (under Details), since v11 WordCloud should work with any expression, including graphics. However, I can't get it to produce reasonable output when given MaTeX-generated stuff. Of course, Heike's implementation (that you linked to) will still work. – Szabolcs – 2017-02-26T20:18:18.000

@Szabolcs Sorry, I don't know why I got that wrong. I can't get it to work with the expressions either, but rasterizing seems to help: WordCloud[ Table[Rasterize[ MaTeX["x^{" <> ToString[n] <> "}", Magnification -> 5], RasterSize -> 200], {n, 20}]] – C. E. – 2017-02-26T20:45:33.667

Answers

2

WordCloud should work with any expression, but in practice some expressions, in particular Graphics containing FilledCurve, cause it to fail.

Here's a way around this.

Let's compile some TeX using MaTeX:

Needs["MaTeX`"]

letterGraphics = MaTeX@CharacterRange["a", "z"]

enter image description here

This fails:

WordCloud[letterGraphics]

enter image description here

But now let us convert those special graphics primitives to pure Polygons.

WordCloud[
 BoundaryDiscretizeGraphics[#, MaxCellMeasure -> 0.01] & /@ 
  letterGraphics]

enter image description here

If setting the MaxCellMeasure to a low enough value, it works.

I tested this in Mathematica 11.2. Earlier versions may not do so well.

Szabolcs

Posted 2017-02-26T17:44:39.253

Reputation: 213 047