index.js
function sanitize(str) {
  const symbolMap = {
    '\'': '\\textquotesingle{}',
    '"': '\\textquotedbl{}',
    '`': '\\textasciigrave{}',
    '^': '\\textasciicircum{}',
    '~': '\\textasciitilde{}',
    '<': '\\textless{}',
    '>': '\\textgreater{}',
    '|': '\\textbar{}',
    '\\': '\\textbackslash{}',
    '{': '\\{',
    '}': '\\}',
    '$': '\\$',
    '&': '\\&',
    '#': '\\#',
    '_': '\\_',
    '%': '\\%'
  }

  return Array.from(str)
    .map(char => symbolMap[char] || char)
    .join('')
}
function sanitize(str) {
  const symbolMap = {
    '\'': '\\textquotesingle{}',
    '"': '\\textquotedbl{}',
    '`': '\\textasciigrave{}',
    '^': '\\textasciicircum{}',
    '~': '\\textasciitilde{}',
    '<': '\\textless{}',
    '>': '\\textgreater{}',
    '|': '\\textbar{}',
    '\\': '\\textbackslash{}',
    '{': '\\{',
    '}': '\\}',
    '$': '\\$',
    '&': '\\&',
    '#': '\\#',
    '_': '\\_',
    '%': '\\%'
  }

  return Array.from(str)
    .map(char => symbolMap[char] || char)
    .join('')
}
Sanitizes a string by replacing all hazardous LaTeX symbols with their descriptive names.

@param str {string} - The string to be normalized.

@return {string}