Skip to content
Snippets Groups Projects

Fix: Break line properly into latex when next line starts with `_`

Merged Karim Ahmed requested to merge fix/break_line_properly_into_latex into master
1 unresolved thread
1 file
+ 20
0
Compare changes
  • Side-by-side
  • Inline
@@ -493,10 +493,30 @@ def make_par_table(parms):
# Add space in long strings without line breakers ` ,-/` to
# wrap them in latex
def split_len(seq, length):
"""
Splits a sequence into smaller segments of a specified length,
concatenates them, and adds line-breaking characters
to ensure proper line breaks in LaTeX.
Args:
seq (str): The sequence to be split.
length (int): The desired length of each segment.
Returns:
str: The concatenated line with line-breaking characters.
Examples:
>>> split_len("slurm_prof_230711_095647.832671_0", 10)
'slurm\_prof\_230711\\-\_095647.832671\_0\-'
"""
lbc = set(' ,-/')
line = ''
for i in range(0, len(seq), length):
sub_line = seq[i:i + length]
# Ensure proper line break if the
# start of the new line begins with `_`
if sub_line[0] == '_' and line[-1] == "-":
line += '\\'
line += sub_line.replace('/', '/\-')
if not any(c in lbc for c in sub_line):
line += '\-'
Loading