Skip to content

Commit

Permalink
Fixed linebreaks in text
Browse files Browse the repository at this point in the history
  • Loading branch information
JWock82 authored and JWock82 committed Oct 29, 2024
1 parent 49e3576 commit f89f9af
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ipycalc/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ def process_line(calc_line, local_ns):
reference = reference.strip()

# Return the line formatted in all its glory
# latex_text = '\\small{\\textsf{' + description + '}} & \\small{' + latex_variable + latex_equation + latex_value + '} & \\begin{array}{@{}l@{}} {\\small{\\textsf{' + reference + '}}} \\end{array} \\\\ \n'
latex_text = linebreaks(description, 'text') + '&' + linebreaks(latex_variable + latex_equation + latex_value, 'math') + '&' + linebreaks(reference, 'text') + ' \\\\ \n'

# There will be a double equals sign if the equation is not being displayed
Expand Down Expand Up @@ -664,11 +663,16 @@ def funit(value, precision=None):

def linebreaks(text, format='text'):

# Handle manually inserted line breaks placed in the line by the user
# Normally in Latex a simple \\ will create a linebreak. However, MathJax in Jupyter applies the line break across the entire row of a table array, rather than just across the individual cell. To work around this, we'll use another table array within the table cell to contain the linebreak to just the cell.

# Note that \\ becomes \\\\ when formatted as a string in Python since \ is considered an escape character in Python.

# Format text with linebreaks
if format == 'text':
text = text.replace('\\\\', '}}} \\\\ {\\small{\\textsf{')
return '\\begin{array}{@{}l@{}} {\\small{\\textsf{' + text + '}}} \\end{array}'

# Format math equations differently
else:
text = text.replace('\\\\', '}} \\\\ {\\small{')
return '\\begin{array}{@{}l@{}} {\\small{' + text + '}} \\end{array}'
return '\\begin{array}{@{}l@{}} {\\small{' + text + '}} \\end{array}'

0 comments on commit f89f9af

Please sign in to comment.