4

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

Wynne
  • 1,526
  • 9
  • 14
  • 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 Feb 26 '17 at 18:14
  • 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. Feb 26 '17 at 18:29
  • @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 Feb 26 '17 at 20:18
  • @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. Feb 26 '17 at 20:45

1 Answers1

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
  • 234,956
  • 30
  • 623
  • 1,263