INNER CODE UNIT · Python
format_text_with_latex
RQLuo/MixTeX-Latex-OCR · mixtex_data_gen/gen.py:83
def format_text_with_latex(words, formulas, lines):
output = ''
count = 0
for char in tqdm(words):
count += 1
if len(char) >= 2 and random.random() < 0.01:
if random.random() < 0.5:
output += ' \\textbf{' + char + '} '
else:
output += ' \\textit{' + char + '} '
else:
output += char
if count % 100 == 0:
output += '\n \\newpage \n'
if random.random() < 0.5:
if random.random() < 0.03:
formula = random.sample(formulas, 1)[0]
if random.random() < 0.03: