code: def tidy_nlm_references(document):
      
  
      def strip_preceding(text):
          stext = text.rstrip()
          if stext.endswith('[') or stext.endswith('('):
              #log.debug('%s -> %s' % (text, stext[:-1]))
              return stext[:-1]
          return text
  
      def strip_between(text):
          stext = text.strip()
          if stext in {',', '-', '\u2013', '\u2212'}:
              #log.debug('%s -> %s' % (text, ''))
              return ''
          return text
  
      def strip_following(text):
          stext = text.lstrip()
          if stext.startswith(']') or stext.startswith(')'):
              #log.debug('%s -> %s' % (text, stext[1:]))
              return stext[1:]
          return text
  
      for ref in document.xpath('.//xref[@ref-type="bibr"]'):
          parent = ref.getparent()
          previous = ref.getprevious()
          next = ref.getnext()
          if previous is None:
              parent.text = strip_preceding(parent.text or '')
          else:
              previous.tail = strip_preceding(previous.tail or '')
          if next is not None and next.tag == 'xref' and next.get('ref-type') == 'bibr':
              ref.tail = strip_between(ref.tail or '')
          ref.tail = strip_following(ref.tail or '')
      return document
docs: Remove punctuation around references like brackets, commas, hyphens.