Example #1
0
def set_latex():
    """
    Enables LaTeX for matplotlib based on the `with_latex` option and `dvipng` availability.

    Returns
    -------
    bool
        True for LaTeX on, False for off
    """

    if find_executable('dvipng'):
        mpl.rc('text', usetex=True)

        no_warn_file = os.path.join(get_dot_andes_path(), '.no_warn_latex')
        if not os.path.isfile(no_warn_file):
            print('Using LaTeX for rendering. If an error occurs:')
            print(
                'a) If you are using `andes plot`, disable with option "-d",')
            print('b) If you are using `plot()`, set "latex=False".')

            try:
                with open(os.path.join(get_dot_andes_path(), '.no_warn_latex'),
                          'w') as f:
                    f.write('0')
            except OSError:
                pass

        return True

    return False
Example #2
0
def set_latex(enable=True):
    """
    Enables LaTeX for matplotlib based on the `with_latex` option and `dvipng` availability.

    Parameters
    ----------
    enable : bool, optional
        True for latex on and False for off

    Returns
    -------
    bool
        True for LaTeX on, False for off
    """

    has_dvipng = find_executable('dvipng')

    if has_dvipng and enable:
        mpl.rc('text', usetex=True)

        no_warn_file = os.path.join(get_dot_andes_path(), '.no_warn_latex')
        if not os.path.isfile(no_warn_file):
            logger.info('Info:')
            logger.info('Using LaTeX for rendering. If an error occurs:')
            logger.info(
                'a) If you are using `andes plot`, disable with option "-d",')
            logger.info('b) If you are using `plot()`, set "latex=False".')

            try:
                with open(os.path.join(get_dot_andes_path(), '.no_warn_latex'),
                          'w'):
                    pass
            except OSError:
                pass

        return True

    else:
        mpl.rc('text', usetex=False)
        return False