title: How to use m4 with Python and dealing with indendentation and whitespace
body: <p>Is there a good general strategy for using m4 with Python?  Specifically, Python's whitespace requirements make using m4 somewhat awkward.  For example, the following program:</p>
  
  <pre class="lang-m4 prettyprint-override"><code>def foo():
      pushdef(`X',`    $1 = $2')
      include(test01.def)
      popdef(`X')
  
  foo()
  </code></pre>
  
  <p>with <code>test01.def</code> as</p>
  
  <pre><code>X(x,1)
  X(y,2)
  X(z,3)
  </code></pre>
  
  <p>Generates the python program:</p>
  
  <pre class="lang-python prettyprint-override"><code>def foo():
  
          x = 1
      y = 2
      z = 3
  
  
  
  foo()
  </code></pre>
  
  <p>As such, the indentation is off.  Certainly, we can fix this with</p>
  
  <pre class="lang-m4 prettyprint-override"><code>def foo():
  pushdef(`X',`    $1 = $2')
  include(test01.def)
  popdef(`X')
  
  foo()
  </code></pre>
  
  <p>However, then I feel the file that we edit becomes ugly because it's harder to track the indentation in our code organization.  Really, what I'd like the ability to do is to use the first program and have m4 eat the leading whitespace before the include.  I'm not sure if it's possible for m4 to eat the leading whitespace.</p>
  
  <p>In addition, I'm aware that that there are Python specific macro utilities.  However, I am <strong>not</strong> interested in using these.  I need to use these X macros in a number of different languages such as in C and LaTeX and it is my intention to use m4 in each of these cases since it's readily available and language agnostic.  As such, I'm really looking for an m4 solution if one is possible.</p>