#!/usr/bin env python3 import os import matplotlib.pyplot as plt import numpy as np import math import scipy as scp if __name__ == "__main__": # make relative imports work as described here: https://peps.python.org/pep-0366/#proposed-change if __package__ is None: __package__ = "formulasheet" import sys filepath = os.path.realpath(os.path.abspath(__file__)) sys.path.insert(0, os.path.dirname(os.path.dirname(filepath))) from util.mpl_colorscheme import set_mpl_colorscheme import util.colorschemes as cs # SET THE COLORSCHEME # hard white and black # cs.p_gruvbox["fg0"] = "#000000" # cs.p_gruvbox["bg0"] = "#ffffff" COLORSCHEME = cs.gruvbox_dark() # print(COLORSCHEME) # COLORSCHEME = cs.GRUVBOX_DARK tex_src_path = "../src/" img_out_dir = os.path.join(tex_src_path, "img") filetype = ".pdf" skipasserts = False full = 8 size_half_half = (full/2, full/2) size_third_half = (full/3, full/2) size_half_third = (full/2, full/3) def assert_directory(): if not skipasserts: assert os.path.abspath(".").endswith("scripts"), "Please run from the `scripts` directory" def texvar(var, val, math=True): s = "$" if math else "" s += f"\\{var} = {val}" if math: s += "$" return s def export(fig, name, notightlayout=False): assert_directory() filename = os.path.join(img_out_dir, name + filetype) if not notightlayout: fig.tight_layout() fig.savefig(filename) #, bbox_inches="tight") @np.vectorize def smooth_step(x: float, left_edge: float, right_edge: float): x = (x - left_edge) / (right_edge - left_edge) if x <= 0: return 0. elif x >= 1: return 1. else: return 3*(x*2) - 2*(x**3) # run even when imported set_mpl_colorscheme(COLORSCHEME) if __name__ == "__main__": assert_directory() s = \ """% This file was generated by scripts/formulasheet.py\n% Do not edit it directly, changes will be overwritten\n""" + cs.generate_latex_colorscheme(COLORSCHEME) filename = os.path.join(tex_src_path, "util/colorscheme.tex") print(f"Writing tex colorscheme to {filename}") with open(filename, "w") as file: file.write(s)