def spnToLatex(spname):
    """
  Utilitiy function to convert species names to proper latex math strings.
  
  The returned string can directly be embedded in a latex $ $ statement. 
  """
    name = str(spname)
    if str(spname) == 'HN2+':
        name = 'N2H+'
    if str(spname) == 'C18O':
        return 'C^{18}O'
    if str(spname) == '13CO':
        return '^{13}CO'
    if str(spname) == 'H13CO+':
        return 'H^{13}CO^+'
    newname = ''
    previous_char = None
    for c in name:
        if c.isdigit():
            newname += '_' + c
        elif c == '-' and not (previous_char == 'o' or previous_char == 'p'):
            newname += '^-'
        elif c == '+':
            newname += '^+'
        elif c == '#':
            newname += '\\#'
        else:
            newname += c
        previous_char = c
    if '_H' in newname:
        newname = newname.replace('_H', '\\_H')
    if '^+^+' in newname:
        newname = newname.replace('^+^+', '^{++}')
    return newname
