Renders latex text into a jpeg.

    Whitespace that would have appeared in the PDF is removed, so the jpeg is
    cropped only the the relevant part.  This is ideal for figures that only
    take a single page.

    Args:
        input_text (?):
        dpath (str):  directory path(default = None)
        fname (str):  file name(default = None)
        preamb_extra (None): (default = None)
        verbose (int):  verbosity flag(default = 1)

    Returns:
        str: jpg_fpath -  file path string

    CommandLine:
        python -m utool.util_latex render_latex '$O(n^2)$' --fpath=~/slides/tmp.jpg

    Script:
        >>> # SCRIPT
        >>> from utool.util_latex import *  # NOQA
        >>> from os.path import split, expanduser
        >>> import utool as ut
        >>> input_text = ' '.join(ut.get_varargs()[1:])
        >>> dpath, fname = split(ut.argval('--fpath', ''))
        >>> dpath = expanduser(ut.argval('--dpath', dpath))
        >>> fname = ut.argval('--fname', fname)
        >>> kwargs = ut.dict_subset(ut.argparse_funckw(ut.convert_pdf_to_image), ['dpi', 'quality'])
        >>> jpg_fpath = render_latex(input_text, dpath, fname, **kwargs)
        >>> if ut.argflag('--diskshow'):
        >>>     ut.startfile(jpg_fpath)

def render_latex(input_text, dpath=None, fname=None, preamb_extra=None,
                 verbose=1, **kwargs):
    """
    Renders latex text into a jpeg.

    Whitespace that would have appeared in the PDF is removed, so the jpeg is
    cropped only the the relevant part.  This is ideal for figures that only
    take a single page.

    Args:
        input_text (?):
        dpath (str):  directory path(default = None)
        fname (str):  file name(default = None)
        preamb_extra (None): (default = None)
        verbose (int):  verbosity flag(default = 1)

    Returns:
        str: jpg_fpath -  file path string

    CommandLine:
        python -m utool.util_latex render_latex '$O(n^2)$' --fpath=~/slides/tmp.jpg

    Script:
        >>> # SCRIPT
        >>> from utool.util_latex import *  # NOQA
        >>> from os.path import split, expanduser
        >>> import utool as ut
        >>> input_text = ' '.join(ut.get_varargs()[1:])
        >>> dpath, fname = split(ut.argval('--fpath', ''))
        >>> dpath = expanduser(ut.argval('--dpath', dpath))
        >>> fname = ut.argval('--fname', fname)
        >>> kwargs = ut.dict_subset(ut.argparse_funckw(ut.convert_pdf_to_image), ['dpi', 'quality'])
        >>> jpg_fpath = render_latex(input_text, dpath, fname, **kwargs)
        >>> if ut.argflag('--diskshow'):
        >>>     ut.startfile(jpg_fpath)
    """
    import utool as ut
    import vtool as vt
    # turn off page numbers
    input_text_ = '\pagenumbering{gobble}\n' + input_text
    # fname, _ = splitext(fname)
    img_fname = ut.ensure_ext(fname, ['.jpg'] + list(ut.IMG_EXTENSIONS))
    img_fpath = join(dpath, img_fname)
    pdf_fpath = ut.compile_latex_text(
        input_text_, fname=fname, dpath=dpath, preamb_extra=preamb_extra,
        verbose=verbose, move=False)
    ext = splitext(img_fname)[1]
    fpath_in = ut.convert_pdf_to_image(pdf_fpath, ext=ext, verbose=verbose)
    # Clip of boundaries of the pdf imag
    vt.clipwhite_ondisk(fpath_in, fpath_out=img_fpath, verbose=verbose > 1)
    return img_fpath