connorferster / handcalcs

Python library for converting Python calculations into rendered latex.
Apache License 2.0
5.69k stars 434 forks source link

Combinations of greek and normal characters in handcalcs #117

Open HVEC-lab opened 2 years ago

HVEC-lab commented 2 years ago

Hi,

I am really impressed by handcalcs and forallpeople and. Currently learning to use it.

In my field it is sometimes customary to write variables as combinations of a greek and normal characters (such as DeltaH). Handcalcs appears not to understand this.

Help is appreciated.

Hessel Voortman

connorferster commented 2 years ago

Thanks for the compliments. You are correct, things like DeltaH are not recognized yet. I have been thinking about how it might be implemented. Currently, individual elements of an equation are broken up as individual strings. Any strings in the equation which match any item in the list of "greeks" are then replaced with the corresponding latex code.

To capture DeltaH, perhaps an obvious step would be to instead check if there is a "greek" within the string. This would have the side effect of extracting and converting eta and nu and psi in words or names like metal, null, and ellipsis.

Do you have any thoughts on what the syntax might be? I am planning on sticking with the underscore == subscript syntax however I have had thoughts about making a double underscore equivalent to an actual space (`) in Latex. However, this would not solve this problem because it would just insert a space, like,Δ H`, which is not quite right.

Am interested to hear your ideas on how this might be done!

HVEC-lab commented 2 years ago

Thanks for the reply. Sadly I have no experience in the programming features required for handcalcs. I am currently developing and publishing packages for hydraulic engineering, which is my field. Handcalcs is great for preparing test cases.

Sorry I am unable to help you here.

BTWS2 commented 2 years ago

I'm in favor of using the double underscore __ for text on the same level. E.g.

connorferster commented 2 years ago

Thanks! I am also thinking of the following:

Thoughts?

On Jun 8, 2022, at 03:11, B. Willems @.***> wrote:

 I'm in favor of using the double underscore __ for text on the same level. E.g.

DeltaH ( \Delta H) $$\Delta H$$ DeltaEcar (\Delta E{car}) $$\Delta E_{car}$$ — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

connorferster commented 2 years ago

I have implemented the global option of being able to toggle on/off whether underscores become subscripts or if they just become spaces/separators between symbols. This is in the global_config branch, which will be released as the new version in the coming week or so.

BTWS2 commented 2 years ago

Thanks! I am also thinking of the following:

  • A global setting to switch single underscore behaviour from subscript to a separator to enable things like DeltaT

Looks good to me for people who don't use underscores often.

  • A global setting to switch double underscore behaviour from a separator to a separator with a space to enable things like “Annual Rate of Return = …” Thoughts?

A double subscript does't exist as far as I know. Only one subscript is used at a time, not two levels at once. Because of that I think the default of __ (two underscores) should be a space.

image

Thank you for your work.

av1dm commented 1 year ago

My workaround is:

from handcalcs import constants

greek = constants.GREEK_LOWER

greek['DeltaSigma'] = '\\Delta\\sigma'
greek['parallel']   = '\\parallel'
greek['normal']     = '\\perp'

For something like this: grafik

connorferster commented 1 year ago

@av1dm That's a brilliant idea!

cream68 commented 1 week ago

@av1dm great idea!