docs: def _replace_tex_math(node, mml_url, mc_client=None, retry=0):
      """call mml-api service to replace TeX math in body of node with mathml"""
  
      math = node.attrib['data-math'] or node.text
      if math is None:
          return None
  
      eq = {}
      if mc_client:
          math_key = hashlib.md5(math.encode('utf-8')).hexdigest()
          eq = json.loads(mc_client.get(math_key) or '{}')
  
      if not eq:
          res = requests.post(mml_url, {'math': math.encode('utf-8'),
                                        'mathType': 'TeX',
                                        'mml': 'true'})
          if res:  # Non-error response from requests
              eq = res.json()
              if mc_client:
                  mc_client.set(math_key, res.text)
  
      if 'components' in eq and len(eq['components']) > 0:
          for component in eq['components']:
              if component['format'] == 'mml':
                  mml = etree.fromstring(component['source'])
          if node.tag.endswith('span'):
              mml.set('display', 'inline')
          elif node.tag.endswith('div'):
              mml.set('display', 'block')
          mml.tail = node.tail
          return mml
      else:
          logger.warning('Retrying math TeX conversion: '
                         '{}'.format(json.dumps(eq, indent=4)))
          retry += 1
          if retry < 2:
              return _replace_tex_math(node, mml_url, mc_client, retry)
  
      return None