<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                        wordcloud                           %%
%%                    drawing wordclouds                      %%
%%                   with METAPOST and Lua                    %%
%%                chupin@ceremade.dauphine.fr                 %%
%%                Version 0.2 (septembre    2023)             %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3c of this license
% or (at your option) any later version.  The latest version of this
% license is in http://www.latex-project.org/lppl.txt
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}%
\def\PackageName{wordcloud}%
\def\fileversion{v0.2}%
\def\filedate{2023/07/26}%
\ProvidesPackage{wordcloud}[\filedate\space\fileversion]%
%
% package to load
\RequirePackage{luamplib}%
\mplibtextextlabel{enable} % to allow LaTeX in list of words inside LaTeX document
%
% load the lua code
\directlua{require("wordcloud.lua")}%

\ExplSyntaxOn

% variable globale
\tl_new:N \g__wc_wordcloud_scale_tl
\tl_new:N \g__wc_wordcloud_rotate_tl
\tl_new:N \g__wc_wordcloud_margin_tl

% definitions des clÃ©s/valeurs pour la commande \wordcloud
\keys_define:nn{wc/wordcloud}{%
  scale .tl_gset:N = \g__wc_wordcloud_scale_tl,
  scale .value_required:n = true,
  rotate .tl_gset:N = \g__wc_wordcloud_rotate_tl,
  rotate .value_required:n = true,
  margin .tl_gset:N = \g__wc_wordcloud_margin_tl,
  margin .value_required:n = true,
  usecolor .bool_set:N = \g__wc_wordcloud_usecolor_bool,
  colors .clist_set:N = \g__wc_wordcloud_colors_clist, % list of LaTeX colors
  colors .value_required:n = true,
%  usecolor .default:n = true,
}

% local variable to stock metapost colors list
\tl_new:N \l_colors_list_tl%

% function to build a wordcloud from a list of the form :
% (word1,weight1);(word2,weight2);etc.
\NewDocumentCommand\wordcloud{ o m }{%
  % mandatory argument : list (word1,weight1);(word2,weight2);etc.
  % optional arguments :
  % scale=&lt;value&gt; (default 1)
  % rotate=&lt;value&gt; (default 0)
  % margin=&lt;value&gt; (default 0.3pt)
  % usecolor=true/false (default false)
  % colors={color1,color2,etc}
  % pour les clÃ©s Ã&nbsp; valeur par dÃ©faut
  \keys_set:nn { wc/wordcloud } { scale=1 } %
  \keys_set:nn { wc/wordcloud } { rotate=0 } %
  \keys_set:nn { wc/wordcloud } { margin=0.3pt } %
  \keys_set:nn { wc/wordcloud } { colors={} } %
  \keys_set:nn { wc/wordcloud } { usecolor=false } %

  \tl_clear:N \l_colors_list_tl%
  \IfNoValueF {#1}
  {
      \keys_set:nn { wc/wordcloud } { #1 }
  }

  % parse the list to build a list of rgb colors for metapost code

  \clist_map_variable:NNn \g__wc_wordcloud_colors_clist \l_onecolor_tl {% 
    \extractcolorspecs{\tl_use:N
    \l_onecolor_tl}{\wc_onecolor_type}{\wc_onecolor_values}
    % get the type and values of color (see xcolor doc)
    \convertcolorspec{\wc_onecolor_type}{\wc_onecolor_values}{rgb}\wc_rgb_values
    % convert to rgb (see xcolor loc)
    \tl_gput_right:Nx \l_colors_list_tl {(\wc_rgb_values);} % add value with
    %parenthesis 
  }%


  %\show {coucous}
  \directlua{%
    %tex.sprint("test")
    wc_build_wordcloud("\luaescapestring{\unexpanded{#2}}",\tl_use:N \g__wc_wordcloud_rotate_tl,\tl_use:N \g__wc_wordcloud_scale_tl,"\tl_use:N \g__wc_wordcloud_margin_tl",\bool_if:NTF \g__wc_wordcloud_usecolor_bool{"true"}{"false"},"\tl_use:N \l_colors_list_tl")
  }%
}


% function to build a wordcloud from a text file :
\NewDocumentCommand\wordcloudFile{ o m m}{%
  % two mandatory arguments : name of the file and number of words for the
  % wordcloud 
  % optional arguments :
  % scale=&lt;value&gt; (default 1)
  % rotate=&lt;value&gt; (default 0)
  % margin=&lt;value&gt; (default 0.3pt)
  % usecolor=true/false (default false)
  % colors={color1,color2,etc}

  % pour les clÃ©s Ã&nbsp; valeur par dÃ©faut
  \keys_set:nn { wc/wordcloud } { scale=1 } %
  \keys_set:nn { wc/wordcloud } { rotate=0 } %
  \keys_set:nn { wc/wordcloud } { margin=0.3pt } %
  \keys_set:nn { wc/wordcloud } { colors={} } %
  \keys_set:nn { wc/wordcloud } { usecolor=false } %
  \tl_clear:N \l_colors_list_tl%

  \IfNoValueF {#1}
  {
      \keys_set:nn { wc/wordcloud } { #1 }
  }

  % parse the list to build a list of rgb colors for metapost code
  
  \clist_map_variable:NNn \g__wc_wordcloud_colors_clist \l_onecolor_tl {% 
    \extractcolorspecs{\tl_use:N
    \l_onecolor_tl}{\wc_onecolor_type}{\wc_onecolor_values}
    % get the type and values of color (see xcolor doc)
    \convertcolorspec{\wc_onecolor_type}{\wc_onecolor_values}{rgb}\wc_rgb_values
    % convert to rgb (see xcolor loc)
    \tl_gput_right:Nx \l_colors_list_tl {(\wc_rgb_values);} % add value with
    %parenthesis 
  }%

  %\show {coucous}
  \directlua{%
    wc_build_wordcloud_file("#2",#3,\tl_use:N \g__wc_wordcloud_rotate_tl,\tl_use:N \g__wc_wordcloud_scale_tl,"\tl_use:N \g__wc_wordcloud_margin_tl",\bool_if:NTF \g__wc_wordcloud_usecolor_bool{"true"}{"false"},"\tl_use:N \l_colors_list_tl")
  }%
}

% function to add words to ignor when a wordcloud is build from a text file
\NewDocumentCommand\wordcloudIgnoreWords{m}{%
  % mandatory argument : list of words separated by commas 
  % word1, word2, word3, etc.
  \directlua{%
    tab=wc_string_to_tab("#1")
    wc_add_ignored_words(tab)
  }%
}


\ExplSyntaxOff
</pre></body></html>