wxMaxima-developers / wxmaxima

A gui for the computer algebra system Maxima built with wxWidgets
https://wxMaxima-developers.github.io/wxmaxima/
Other
471 stars 98 forks source link

Copy as LaTeX #912

Closed astyonax closed 6 years ago

astyonax commented 7 years ago

Hi, I use wxMaxima regularly, but one behavior I really dislike. I think that the latex generated with the "copy as latex" from the contextual menu is hard to read. The biggest issue being the number of braces "{" and "}".

Since also the output of the maxima's tex() function is not much better, some time ago I put together some regular expressions to simplify the tex code I usually get. You can have a a look here https://astyonax.github.io/BetterTex4wxMaxima/, it's my sandbox for this task.

I'm wondering whether it's possible (and there is interest) to reach a consensus on a set of regular expressions that wxmaxima may apply when doing the "copy as latex".

best,

gunterkoenigsmann commented 7 years ago

If you have any idea on regular expressions that help I will be happy to add them. Also each type of cell the worksheet supports has a xxxCell.cpp file containing a ToTeX function. If you have ideas on how to improve them I will be very happy. My last tries to reduce the amount of unneeded {} were only partially successful, though.

gunterkoenigsmann commented 7 years ago

If you tell me the minimal rules from your page don't break anything I will implement them.

gunterkoenigsmann commented 7 years ago

Ok...

  wxRegEx bracesAroundSingleLetter(wxT("[^ ]{([a-zA-Z0-9])}"));
  bracesAroundSingleLetter.Replace(&retval,"\\1");

works fine. But the following RegEx doesn't compile. What did I do wrong?

  wxRegEx bracesAroundSingleCharExponent(wxT("([^}c]){(\\*[^{]*?\^[a-zA-Z0-9])}"));
  bracesAroundSingleCharExponent.Replace(&retval,"\\1");
gunterkoenigsmann commented 7 years ago

Created a branch named BetterTeX for experimenting with the RegExs.

astyonax commented 7 years ago

I started to work on the BetterTeX branch I found that for complex regular expression, the wxRE_ADVANCED flag is needed as in

  wxRegEx bracesAroundStrBeforeExponent("([^}ct]){([a-zA-Z0-9]*?)}\\^",wxRE_ADVANCED);
  bracesAroundStrBeforeExponent.Replace(&retval,"\\1 \\2^");

I'll work on the other regular expressions ASAP.

I can't promise my current set of regular expressions are completely safe, but may be it's possible to make a comprehensive list of tex expressions to use as test?

gunterkoenigsmann commented 7 years ago

In the test folder of wxMaxima there is a .wxmx file containing many constructs wxMaxima can generate. Perhaps we can extend that file...

Do you have a Linux or Mac system and experience with git? If yes feel free to checkout or to fork the BetterTeX branch on github so we can run tests on the real program.

astyonax commented 7 years ago

Thanks for the information! I saw that file indeed. I was wondering if it's possible to call ToTex programatically from within the notebook ?

I'm on Linux (ubuntu), and I've experience with git. wxmaxima compiles fine with cmake, only problem is that it does not find its resource files automatically (bcs I don't want to install over the OS version, which I use for work). So I load wxmathml.lisp by hand. Any idea how to specify a custom prefix with cmake?

Unless you prefer differently, I'll work on a fork (next weekend).

gunterkoenigsmann commented 7 years ago
 cmake -DCMAKE_INSTALL_PREFIX=/usr/local

The idea that with git forks actually do something useful still fascinates me...

There is a way to indirectly call ToTeX: The "copy as LaTeX" right-click menu item. Don't know if that is what you want.

astyonax commented 7 years ago

Ok. Of course I can use the right click. Well ok. I'll let you know asap my progress with this.

astyonax commented 7 years ago

Thus, You can follow the progress in here: https://github.com/astyonax/wxmaxima/tree/BetterTeX I'll make a pull request so that you can review the changes, I didn't finish yet, though.

gunterkoenigsmann commented 6 years ago

Closing this issue as BetterTeX has been merged. But will merge any additional improvements as you find them.