From d16708e70bf61d6a23298281b0e6ca3b84e6202e Mon Sep 17 00:00:00 2001 From: emmetfrancis Date: Tue, 2 Apr 2024 17:04:02 -0700 Subject: [PATCH] Fixes to latex table formatting - replace left quotes, escape underscores --- examples/example3/example3.ipynb | 2 +- smart/model_assembly.py | 32 +++++++++++++++++++------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/examples/example3/example3.ipynb b/examples/example3/example3.ipynb index ce177c46..0eb28dd0 100644 --- a/examples/example3/example3.ipynb +++ b/examples/example3/example3.ipynb @@ -366,7 +366,7 @@ "source": [ "# Base mesh\n", "# 0 in second argument corresponds to no inner sphere\n", - "domain, facet_markers, cell_markers = mesh_tools.create_spheres(curRadius, 0, hEdge=0.05, hInnerEdge=0.05)\n", + "domain, facet_markers, cell_markers = mesh_tools.create_spheres(curRadius, 0, hEdge=0.2)\n", "visualization.plot_dolfin_mesh(domain, cell_markers, facet_markers)" ] }, diff --git a/smart/model_assembly.py b/smart/model_assembly.py index ef6f5093..d7a4651d 100644 --- a/smart/model_assembly.py +++ b/smart/model_assembly.py @@ -232,27 +232,33 @@ def print_to_latex( max_col_width=max_col_width, sig_figs=sig_figs, ) + df = df.copy(deep=True) # Change certain df entries to best format for display for name in df.index: if "_" in name: - new_name = name.replace("_", "-") + new_name = name.replace("_", "\_") df = df.rename(index={name: new_name}) + for row in range(df.shape[0]): for col in range(df.shape[1]): if isinstance(df.iat[row, col], str): cur_str = df.iat[row, col] if "_" in cur_str: - df = df.replace(cur_str, cur_str.replace("_", "-")) + df.iloc[row, col] = cur_str.replace("_", "\_") elif isinstance(df.iat[row, col], list): - if len(df.iat[row, col]) > 0: - cur_list = df.iat[row, col] - new_list = cur_list - for i in range(len(cur_list)): - if isinstance(new_list[i], str): - cur_str = df.iat[row, col][0] - new_list[i] = cur_str.replace("_", "-") - df = df.replace(cur_list, new_list) + cur_str = str(df.iat[row, col]) + cur_str = cur_str.replace("_", "\_") + new_list = list(cur_str) + quoteCount = 0 + # switch every other quote to an opening quote ` + for i in range(len(new_list)): + if new_list[i] == "'": + quoteCount += 1 + if np.mod(quoteCount, 2): + new_list[i] = "`" + cur_str = "".join(new_list) + df.iloc[row, col] = cur_str for col in df.columns: # Convert quantity objects to unit if isinstance(df[col].iloc[0], pint.Quantity): @@ -263,7 +269,7 @@ def print_to_latex( df = df.drop("idx", axis=1) if "_" in col: - df = df.rename(columns={col: col.replace("_", "-")}) + df = df.rename(columns={col: col.replace("_", "\_")}) if return_df: return df @@ -966,12 +972,12 @@ def __init__(self): super().__init__(Compartment) self.properties_to_print = [ - "_mesh_id", + # "_mesh_id", "dimensionality", "num_species", "_num_vertices", "_num_dofs", - "_num_dofs_local", + # "_num_dofs_local", "_num_cells", "cell_marker", "_nvolume",