#!/usr/bin/env awk
#
# Escape the string 's' to make it LaTeX compatible
#
# Examples:
#   - tawk '{ print texscape($0) }' file.txt

function texscape(s) {
    gsub(/\\"/, "\"", s)
    gsub(/\\/, "\\textbackslash{}", s)
    gsub(/_/, "\\_", s)
    gsub(/&/, "\\\\&", s)
    gsub(/%/, "\\%", s)
    gsub(/\#/, "\\#", s)
    gsub(/\$/, "\\$", s)
    gsub(/\^/, "\\textasciicircum{}", s)
    gsub(/~/, "\\textasciitilde{}", s)
    return s
}
