title: Macro to automatically generate section numbers
body: <p>I am struggling with creating a macro to automatically generate section number and subsection numbers. I had thought the snippet below would work but it is failing to assign the value if not already set. I am sure this is obvious but my lack of jinja experience is showing... or perhaps lack of Python experience... or both!</p>
  <p>I get this error.</p>
  <pre><code>{% set sectionnumber.value = sectionnumber.value + 1 %}
  jinja2.exceptions.TemplateRuntimeError: cannot assign attribute on non-namespace object
  </code></pre>
  <pre><code>
  {% macro getsectionnumber(type) -%}
  
    {% if subsectionnumber is none %}
      {% if sectionnumber is none  %}
        {% set sectionnumber = namespace(value=0) %}
      {% endif %}
      {% set subsectionnumber = namespace(value=0) %}
    {% endif %}
  
    {% if type == 'section' %}
      {% if sectionnumber is none  %}
        {% set sectionnumber = namespace(value=0) %}
      {% endif %}
      {% set sectionnumber.value = sectionnumber.value + 1 %}
      {{ sectionnumber.value }}
    {% endif %}
  
    {% if type == 'subsection' %}
      {% set subsectionnumber.value = subsectionnumber.value + 1 %}
      {{ sectionnumber.value }}.{{ subsectionnumber.value }}
    {% endif %}
  </code></pre>