jasondavies / d3-cloud

Create word clouds in JavaScript.
https://www.jasondavies.com/wordcloud/
Other
3.82k stars 1.08k forks source link

Using d3 from Latex #181

Closed dedalozzo closed 1 year ago

dedalozzo commented 1 year ago

Is it possible to generate a word cloud calling d3 from LuaLaTex? I know it is possible to call a JavaScript function using the package js:

\usepackage{js}

Can I just copy the d3.layout.cloud.js in the tex project directory, and do something like this?

\documentclass{article}
\usepackage{filecontents}
\usepackage{svg}

\begin{filecontents*}{d3.layout.cloud.js}
% Contents of the `d3.layout.cloud.js` file here
\end{filecontents*}

\begin{document}

\begin{script}
  \input{d3.layout.cloud.js}
  \newcommand{\wordcloud}{\includesvg[width=\linewidth]{wordcloud.svg}}
  % Generate the word cloud
  \directlua{
    local cloud = createCloud("This is some sample text")
    local file = io.open("wordcloud.svg", "w")
    file:write(cloud)
    file:close()
  }
  % Insert the word cloud into the document
  \wordcloud
\end{script}

\end{document}
jasondavies commented 1 year ago

Sorry, I have no idea. This sounds like a LuaTex question. Maybe try StackOverflow?

dedalozzo commented 1 year ago

What I would to know is the minimum requirement to run the function. Forget about Latex. Let's suppose I have an embedded JavaScript engine, and I want to generate a word cloud, what file do I need to include and what function of the llibrary I need to execute? I can figure it out the rest.