Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latex variable name processing #38

Merged
merged 10 commits into from
Nov 21, 2024
Merged

Conversation

JoelLucaAdams
Copy link
Collaborator

Change all long_name attributes to use spaces instead of underscores with Title Case

Add LaTeX detection of variables that contain the following prefixes and suffixes:

prefixes = ["E", "B", "J", "P"]
suffixes = ["x", "y", "z"]

It will convert from Electric Field Ex to Electric Field E$_x$
It will only convert to latex if there are spaces before and after OR if there is a space before. This is to ensure that we don't rename variables that might contain those characters within another word. e.g. Exponential ...

Fixes #36

@JoelLucaAdams JoelLucaAdams added the enhancement New feature or request label Nov 20, 2024
assert df["Current_Jz"].attrs["long_name"] == "Current J$_z$"
assert df["Particles_Px_Electron"].attrs["long_name"] == "Particles P$_x$ Electron"
assert df["Particles_Py_Electron"].attrs["long_name"] == "Particles P$_y$ Electron"
assert df["Particles_Pz_Electron"].attrs["long_name"] == "Particles P$_z$ Electron"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably also wise to have a couple of examples where we don't want this to happen

Copy link
Collaborator Author

@JoelLucaAdams JoelLucaAdams Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added new tests for this in 14a4b65

Comment on lines +137 to +138
assert _process_latex_name("Example") == "Example"
assert _process_latex_name("PxTest") == "PxTest"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to check the long name for one of the variables in df that we've not LaTeXified

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to leave those as there aren't any examples of names like that but also validated against existing variables 9075383

Comment on lines 43 to 45
affix_pattern = rf"(\s+){prefix}{suffix}(\s*|$)"
# Insert LaTeX format while preserving spaces
replacement = rf"\1${prefix}_{suffix}$\2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can just be this?

Suggested change
affix_pattern = rf"(\s+){prefix}{suffix}(\s*|$)"
# Insert LaTeX format while preserving spaces
replacement = rf"\1${prefix}_{suffix}$\2"
affix_pattern = rf"\b{prefix}{suffix}\b"
# Insert LaTeX format while preserving spaces
replacement = rf"${prefix}_{suffix}$"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it can! Ran it locally and checked tests passed

@JoelLucaAdams JoelLucaAdams merged commit 810510d into main Nov 21, 2024
16 checks passed
@JoelLucaAdams JoelLucaAdams deleted the latex-variable-name-processing branch November 21, 2024 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Long names should be in 'sentence case'/'Title Case' instead of snake_case
3 participants