helper.path_accepted_string

from pathvalidate import validate_filename

source

latex_to_path_accepted_string

 latex_to_path_accepted_string (latex:str)

Convert a latex string to a path accepted string

The latex_to_path_accepted_string function “cleans” a latex str into a path-valid string for the purposes of making files.

sample_1 = r'\mathcal{O}_X'
output_1 = latex_to_path_accepted_string(sample_1)
print(output_1)
assert 'O' in output_1 and 'X' in output_1
validate_filename(output_1)

sample_2 = r'\operatorname{Gal}(L/K)'
output_2 = latex_to_path_accepted_string(sample_2)
print(output_2)
assert 'Gal' in output_2 and 'L' in output_2 and 'K' in output_2
validate_filename(output_2)

# Example found in https://arxiv.org/abs/1607.04471
sample_3 = r'\begin{equation} \label{escape rate}   G_{F_t}(z,w) = \lim_{n\to\infty} \frac{1}{d^n} \log \| F_t^n(z,w) \|, \end{equation}'
output_3 = latex_to_path_accepted_string(sample_3)
print(output_3)
validate_filename(output_3)
O_X
Gal_L_K
label_escape_rate_G_F_t_z_w_lim_n_to_infty_frac_1_d_n_log_F_t_n_z_w