@@ -174,9 +174,6 @@ def sync_namespaces(local_ns):
174174#%%
175175def process_line (calc_line , local_ns ):
176176
177- # Ampersand symbols will mess with latex table formatting unless they have a `\` in front of them
178- calc_line = calc_line .replace ('&' , r'&' )
179-
180177 # Break up the line into components: `description`, `variable`, `equation`, `value` and `reference`
181178 # Split `reference` off from the rest of the line
182179 if '#' in calc_line :
@@ -307,6 +304,8 @@ def compute_value(expression, target_unit, target_precision):
307304
308305 # Format the description
309306 if description != '' :
307+ # Escape ampersand symbols for latex table formatting
308+ description = description .replace ('&' , r'\&' )
310309 description = description + ': '
311310
312311 # Format the variable to be Python friendly
@@ -355,6 +354,8 @@ def compute_value(expression, target_unit, target_precision):
355354
356355 # Format the reference
357356 reference = reference .strip ()
357+ # Escape ampersand symbols for latex table formatting
358+ reference = reference .replace ('&' , r'\&' )
358359
359360 # Return the line formatted in all its glory
360361 latex_text = linebreaks (description , 'text' ) + '&' + linebreaks (latex_variable + latex_equation + latex_value , 'math' ) + '&' + linebreaks (reference , 'text' ) + '\\ \\ \n '
@@ -689,8 +690,8 @@ def funit(value, precision=None):
689690 # Step through each character in the value
690691 for i , char in enumerate (latex_value ):
691692
692- # Find the first non-numeric non-decimal character
693- if not latex_value [i ].isnumeric () and latex_value [i ] != '.' :
693+ # Find the first non-numeric non-decimal character, excluding the minus sign for negative numbers
694+ if not latex_value [i ].isnumeric () and latex_value [i ] != '.' and latex_value [ i ] != '-' :
694695
695696 # Add a space between the value and the units
696697 latex_value = latex_value [0 :i ] + ' \\ ' + latex_value [i :len (latex_value )]
0 commit comments