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

Customize Latexified variable names with function keyword argument #1352

Closed
wants to merge 1 commit into from

Conversation

hersle
Copy link
Contributor

@hersle hersle commented Nov 7, 2024

I'm exploring options. Here is an alternative to #1350, using a keyword argument (similar to what @isaacsas suggested). Example usage:

# 1) Default Symbolics-only pure behavior
using Symbolics, Latexify
@variables car₊wheel₊ω
latexify(car₊wheel₊ω) # car.wheel.\omega

# 2) Default in ModelingToolkit?
formatter_mtk(name) = "\\mathtt{$name}"
latexify(car₊wheel₊ω; variable_formatter = formatter_mtk) # \mathtt{car.wheel.\omega}

# 3) Default in another package?
formatter_subsystem(name) = "\\mathrm{$name}"
formatter_variable(name) = length(name) > 1 ? "\\mathrm{$name}" : name
formatter_advanced(name) = (names = split(name, "."); join([formatter_subsystem.(names[begin:end-1]); formatter_variable(names[end])], "."))
latexify(car₊wheel₊ω; variable_formatter = formatter_advanced) # \mathrm{car}.\mathrm{wheel}.\omega

MTK or other packages could dispatch on latexify(sys::SystemType) with an appropriate formatting function.

@hersle
Copy link
Contributor Author

hersle commented Nov 7, 2024

@latexrecipe is a little finicky with keyword arguments, particularly when they are functions or declared as kwargs.... Hence the small hack. See korsbo/Latexify.jl#320.

@codecov-commenter
Copy link

codecov-commenter commented Nov 7, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 0% with 40 lines in your changes missing coverage. Please review.

Project coverage is 6.47%. Comparing base (5af597a) to head (a68360a).
Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
src/latexify_recipes.jl 0.00% 40 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #1352      +/-   ##
=========================================
+ Coverage    3.98%   6.47%   +2.48%     
=========================================
  Files          50      50              
  Lines        4771    4775       +4     
=========================================
+ Hits          190     309     +119     
+ Misses       4581    4466     -115     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hersle hersle marked this pull request as draft November 7, 2024 14:02
@hersle
Copy link
Contributor Author

hersle commented Nov 7, 2024

Forget this, it has the same flaw as #1350.

@hersle hersle closed this Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants