def latex_var(name,value,desc=None,xspace=True):
    """Create a variable NAME with a given VALUE.
    Primarily for output to LaTeX.
    Returns a string."""
    xspace_str = r"\xspace" if xspace else ""
    return "".join(['\\newcommand{\\',str(name),'}{',str(value),xspace_str,'}'] + ([' % ',desc] if desc else []) + ['\n'])