code: def label_to_latex(text):
      # pylint: disable=anomalous-backslash-in-string
      r
      if text is None:
          return ''
      out = []
      x = None
      # loop over matches in reverse order and replace
      for m in re_latex_control.finditer(text):
          a, b = m.span()
          char = m.group()[0]
          out.append(text[x:a])
          out.append(r'\%s' % char)
          x = b
      if not x:  # no match
          return text
      # append prefix and return joined components
      out.append(text[b:])
      return ''.join(out)
docs: r"""Convert text into a latex-passable representation.
  
      This method just escapes the following reserved LaTeX characters:
      % \ _ ~ &, whilst trying to avoid doubly-escaping already escaped
      characters
  
      Parameters
      ----------
      text : `str`
          input text to convert
  
      Returns
      -------
      tex : `str`
          a modified version of the input text with all unescaped reserved
          latex characters escaped
  
      Examples
      --------
      >>> from gwpy.plot.tex import label_to_latex
      >>> label_to_latex('normal text')
      'normal text'
      >>> label_to_latex('$1 + 2 = 3$')
      '$1 + 2 = 3$'
      >>> label_to_latex('H1:ABC-DEF_GHI')
      'H1:ABC-DEF\\_GHI'
      >>> label_to_latex('H1:ABC-DEF\_GHI')
      'H1:ABC-DEF\\_GHI'