renderer: allow users to make bold or italic text normal (#45)

This commit is contained in:
Sina Atalay 2024-03-21 18:58:14 +01:00
parent 846725814a
commit d956fe8d84
1 changed files with 16 additions and 0 deletions

View File

@ -180,6 +180,22 @@ class LaTeXFile(TemplatedFile):
section_title, section_title,
is_first_entry, is_first_entry,
) )
# If there is nested \textbf, \textit, or \underline commands, replace the inner
# ones with \textnormal:
# Find all the nested commands:
nested_commands = re.findall(r"\\textbf{.*?(\\textbf{.*?})", result)
nested_commands += re.findall(r"\\textit{.*?(\\textit{.*?})", result)
nested_commands += re.findall(r"\\underline{.*?(\\underline{.*?})", result)
# Replace the inner commands with \textnormal:
for nested_command in nested_commands:
new_command = nested_command.replace("textbf", "textnormal")
new_command = new_command.replace("textit", "textnormal")
new_command = new_command.replace("underline", "textnormal")
result = result.replace(nested_command, new_command)
return result return result
def get_latex_code(self): def get_latex_code(self):