code: def write_algorithms_reference():
      """Write all files necessary to have a complete algorithms reference in the sphinx doc.
      That includes:
       - write the _templates/algorithms_reference.html template
       - write each separate algo doc as an html template in the _templates/reference folder
       - write a essentia_reference.py file that contains a list of those (to be included in conf.py)
       - write the templates for both std & streaming algos to have the full list of algos as a sidebar
      """
  
      # folder for storing HTMLs
      try:
          os.mkdir("_templates/reference")
      except:
          pass
  
      # folder for storing RSTs for sphinx search index
      try:
          os.mkdir("reference")
      except:
          pass
  
      # write the algorithms reference organized by categories
      # generate html documentation for each algorithm and create an overall list of algorithms
      algos = {}
      for algoname in std_algo_list:
          algos.setdefault(algoname, {})
          algos[algoname]["standard"] = getattr(
              essentia.standard, algoname
          ).__struct__
          # __struct__ does not contain mode (perhaps it should),
          # therefore, doing a workaround so that doc2rst can know the mode
          algos[algoname]["standard"]["mode"] = "standard mode"
  
          # Ugly patch for MusicExtractor and FreesoundExtractor to add links to
          # their detailed documentation.
          if algoname == "MusicExtractor":
              algos[algoname]["standard"]["description"] = algos[
                  algoname
              ]["standard"]["description"].replace(
                  "essentia_streaming_extractor_music",
                  "`essentia_streaming_extractor_music <../streaming_extractor_music.html>`__",
              )
  
          elif algoname == "FreesoundExtractor":
              algos[algoname]["standard"]["description"] = algos[
                  algoname
              ]["standard"]["description"].replace(
                  "essentia_streaming_extractor_freesound",
                  "`essentia_streaming_extractor_freesound <../freesound_extractor.html>`__",
              )
  
          print(
              "generating doc for standard algorithm: %s ..." % algoname
          )
          write_doc(
              "reference/std_" + algoname + ".rst",
              algos[algoname]["standard"],
          )
          write_html_doc(
              "_templates/reference/std_" + algoname + ".html",
              algos[algoname]["standard"],
              layout_type="std",
          )
  
      for algoname in streaming_algo_list:
          algos.setdefault(algoname, {})
          algos[algoname]["streaming"] = getattr(
              essentia.streaming, algoname
          ).__struct__
          algos[algoname]["streaming"]["mode"] = "streaming mode"
  
          print(
              "generating doc for streaming algorithm: %s ..."
              % algoname
          )
          write_doc(
              "reference/streaming_" + algoname + ".rst",
              algos[algoname]["streaming"],
          )
          write_html_doc(
              "_templates/reference/streaming_" + algoname + ".html",
              algos[algoname]["streaming"],
              layout_type="streaming",
          )
  
      # write the template for the std algorithms
      html = """
  {% extends "layout.html" %}
  {% block body %}
  
  <div class="algo-description-container">
  {% block algo_description %}
  {% endblock %}
  </div>
  <div class="algo-list">
      <h4><strong>Standard algorithms</strong></h4>
  """
  
      links = [
          '<a href="std_%s.html">%s</a>' % (algoname, algoname)
          for algoname in std_algo_list
      ]
      html += " | ".join(links)
  
      html += """
  </div>
  
  {% endblock %}
  """
      open("_templates/algo_description_layout_std.html", "w").write(
          html
      )
  
      # write the template for the streaming algorithms
      html = """
  {% extends "layout.html" %}
  {% block body %}
  
  <div class="algo-description-container">
  {% block algo_description %}
  {% endblock %}
  </div>
  
  <div class="algo-list">
      <h4><strong>Streaming algorithms</strong></h4>
  
  """
  
      links = [
          '<a href="streaming_%s.html">%s</a>' % (algoname, algoname)
          for algoname in streaming_algo_list
      ]
      html += " | ".join(links)
  
      html += """
  </div>
  
  {% endblock %}
  """
      open(
          "_templates/algo_description_layout_streaming.html", "w"
      ).write(html)
  
      # write the essentia_reference.py file (to be included in conf.py)
      with open("essentia_reference.py", "w") as algo_ref:
          algo_ref.write(
              """
  standard_algorithms = {
  """
          )
          for algo in std_algo_list:
              algo_ref.write(
                  "  'reference/std_%s': 'reference/std_%s.html',\n"
                  % (algo, algo)
              )
  
          algo_ref.write(
              """  }
  
  streaming_algorithms = {
  """
          )
  
          for algo in streaming_algo_list:
              algo_ref.write(
                  "  'reference/streaming_%s': 'reference/streaming_%s.html',\n"
                  % (algo, algo)
              )
  
          algo_ref.write(
              """  }
  
  essentia_algorithms = {}
  essentia_algorithms.update(standard_algorithms)
  essentia_algorithms.update(streaming_algorithms)
  
  """
          )
  
      # write the algorithms_reference.html file (main ref file)
      algo_categories_html = {}
      for algoname in algos:
          std_algo = None
          streaming_algo = None
          if "standard" in algos[algoname]:
              std_algo = algos[algoname]["standard"]
          if "streaming" in algos[algoname]:
              streaming_algo = algos[algoname]["streaming"]
  
          if std_algo and streaming_algo:
              # both standard and streaming mode exist
              if std_algo["category"] == streaming_algo["category"]:
                  category = std_algo["category"]
              else:
                  print(
                      "WARNING: %s categories differ for standard (%s) and streaming (%s) modes"
                      % (
                          algoname,
                          std_algo["category"],
                          streaming_algo["category"],
                      )
                  )
                  sys.exit()
  
              if (
                  std_algo["description"]
                  == streaming_algo["description"]
              ):
                  description = std_algo["description"].split(".")[0]
              else:
                  print(
                      "WARNING: %s description differ for standard (%s) and streaming (%s) modes"
                      % (
                          algoname,
                          std_algo["description"],
                          streaming_algo["description"],
                      )
                  )
                  sys.exit()
  
          if std_algo:
              category = std_algo["category"]
              description = std_algo["description"].split(".")[0]
          else:
              category = streaming_algo["category"]
              description = streaming_algo["description"].split(".")[0]
  
          # Description for many algorithms starts with "This algorithm..." and we do not want to show that
          description = description.replace("This algorithm ", "")
          if len(description):
              description = (
                  description[0].capitalize() + description[1:]
              )
  
          links = []
          if std_algo:
              links.append(
                  '<a class="reference internal" href="reference/std_'
                  + algoname
                  + '.html"><em>standard</em></a>'
              )
          if streaming_algo:
              links.append(
                  '<a class="reference internal" href="reference/streaming_'
                  + algoname
                  + '.html"><em>streaming</em></a>'
              )
          algo_html = (
              '<div class="algo-info">'
              + "<header><h3>"
              + algoname
              + "</h3></header>"
              + "<span>("
              + ", ".join(links)
              + ")</span>"
              + "<div>"
              + description
              + "</div></div>"
          )
          algo_categories_html.setdefault(category, [])
          algo_categories_html[category].append(algo_html)
  
      html = """
  {% extends "layout.html" %}
  {% set title = "Algorithms reference" %}
  {% block body %}
  
    <div class="section" id="algorithms-reference">
  <h1>Algorithms reference<a class="headerlink" href="#algorithms-reference" title="Permalink to this headline">¶</a></h1>
  <p>Here is the complete list of algorithms which you can access from the Python interface.</p>
  <p>The C++ interface allows access to the same algorithms, and also some more which are templated
  and hence are not available in python.</p>
  
  <div class="section" id="algorithms">
  """
      for category in algo_categories_html:
          category_id = re.sub("[^0-9a-zA-Z]+", "", category.lower())
          html += (
              "<section><h2 id="
              + category_id
              + ">"
              + category
              + "</h2>"
          )
          html += "\n".join(sorted(algo_categories_html[category]))
          html += "</section>"
      html += """
  </div>
  
  </div>
  
  {% endblock %}
  """
  
      open("_templates/algorithms_reference.html", "w").write(html)
  
file_path: essentia/doc/sphinxdoc/generate_reference.py
imports: import essentia.standard
  import essentia.streaming
  import os, re, subprocess
  import sys
label_desc: Use image node_id 10 for calling a global function with example usage: write_algorithms_reference() without return types