def sphinx_encode(string: str) -> str:
    """Replace tilde, hyphen and single quotes with their LaTeX commands."""
    return (
        string.replace("~", "\\textasciitilde{}")
        .replace("-", "\\sphinxhyphen{}")
        .replace("'", "\\textquotesingle{}")
    )