Skip to content

Commit

Permalink
Fixes to latex table formatting - replace left quotes, escape undersc…
Browse files Browse the repository at this point in the history
…ores
  • Loading branch information
emmetfrancis committed Apr 3, 2024
1 parent d3b4c88 commit d16708e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/example3/example3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
},
Expand Down
32 changes: 19 additions & 13 deletions smart/model_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit d16708e

Please sign in to comment.