Bug 43089 - Syntax highlighting for Math
Summary: Syntax highlighting for Math
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Formula Editor (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: Other All
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
: 48671 (view as bug list)
Depends on: 160362
Blocks: Formula-Editor
  Show dependency treegraph
 
Reported: 2011-11-19 05:22 UTC by Florian Reisinger
Modified: 2024-03-25 20:16 UTC (History)
10 users (show)

See Also:
Crash report or crash signature:


Attachments
How syntax highlighting should work (86.56 KB, application/vnd.oasis.opendocument.text)
2011-11-19 05:22 UTC, Florian Reisinger
Details
Math Highlighting Comments (56.84 KB, application/vnd.oasis.opendocument.graphics)
2021-01-29 17:47 UTC, Rafael Lima
Details
Math Highlighting Comments (63.21 KB, application/vnd.oasis.opendocument.graphics)
2021-01-29 19:46 UTC, dante19031999
Details
Highlighting Numeric Values (70.32 KB, application/vnd.oasis.opendocument.graphics)
2021-02-01 12:50 UTC, Rafael Lima
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Reisinger 2011-11-19 05:22:32 UTC
Created attachment 53686 [details]
How syntax highlighting should work

Hi there!

It would be great to have syntax highlighting in Math...
Everything from importance is in the .odt file.

Florian
Comment 1 Giuliano 2012-04-14 12:51:14 UTC
Complety right.
Even Gedit use sintax hilight.

It is very hard when you have a lot og {{{((( to understand where you are in the formula and when to close a braket/graph

Could help a lot in formula writing
Comment 2 Florian Reisinger 2012-04-14 13:00:05 UTC
Thank you. BTW; changed version.. and Status to NEW
Comment 3 José Guilherme Vanz 2013-11-02 22:00:25 UTC
I'm taking a look the bugs formula editor, to classify then and after try to solve them. I downloaded the file attachment and there are some germany comments on it. Is something relevant?
Comment 4 José Guilherme Vanz 2013-11-02 22:02:26 UTC
(In reply to comment #3)
> I'm taking a look the bugs formula editor, to classify then and after try to
> solve them. I downloaded the file attachment and there are some germany
> comments on it. Is something relevant?

Well, I used google translate. So, sorry disturb you.
Comment 5 José Guilherme Vanz 2013-11-07 10:38:00 UTC
I'll start to work in this bug. Do you have some code pointers?
I was taking a look on EditEngine and EditView sources. I think we have to implement this on these classes, right?
Comment 6 Florian Reisinger 2013-11-07 12:46:16 UTC
No idea (regarding codepointer) Anyone?
Feel free to ask @ libreoffice-dev IRC channel @ freenode
Comment 7 Norbert X 2017-06-17 19:05:17 UTC Comment hidden (no-value)
Comment 8 Norbert X 2017-09-01 17:01:04 UTC
Bug exists in 

Version: 5.4.1.2
Build ID: 1:5.4.1~rc2-0ubuntu0.16.04.1~lo0
CPU threads: 4; OS: Linux 4.4; UI render: default; VCL: gtk2; 
Locale: en-US (en_US.UTF-8); Calc: group

Ubuntu 16.04 LTS with PPA.
Comment 9 Norbert X 2018-01-02 21:56:42 UTC
On Ubuntu i
Comment 10 Roman Kuznetsov 2018-07-13 19:36:01 UTC
Would be cool to have highlight of operands/functions in Formula editor
Comment 11 Xisco Faulí 2019-11-29 13:28:33 UTC
Changing priority back to 'medium' since the number of duplicates is lower than 5
Comment 12 dante19031999 2020-07-19 11:56:15 UTC
*** Bug 48671 has been marked as a duplicate of this bug. ***
Comment 13 Sergey 2020-12-14 05:30:02 UTC
I have an idea how to solve the problem simply and with much greater effect: allow users to use theys favorite EXTERNAL text editor to edit formula, i.e. parameter "External math text editor path" in settings needed. It it empty - LibreOffice Math runs, else the LibreOffice (or LibreOffice Math without GUI) run this actions:

- create temp file XXXXX.eqn on trying to fornmula edit/create
- run external text editor with this file as parameter
- read file after editor closing and update formula object as it LibreOffice Math does

It's AUTOMATICALY enables features on user side:

- pair brackets highlighting
- functions highlighting
- more simple editing (change variable name with multicaret editing or vim commands, e.t.c.)
- snippets (not only for math constructions, may be used to natural greek symbols writing - [a]+[Tab] -> α instead of %alpha - more simple reading)
- macroses to text editing in some special cases

It seems to be a great effect for easy implementation - don't you think so?
Comment 14 V Stuart Foote 2020-12-14 14:14:59 UTC
(In reply to Sergey from comment #13)
> I have an idea how to solve the problem simply and with much greater effect:
> allow users to use theys favorite EXTERNAL text editor to edit formula, i.e.
> parameter "External math text editor path" in settings needed. It it empty -
> LibreOffice Math runs, else the LibreOffice (or LibreOffice Math without
> GUI) run this actions:
> 
> - create temp file XXXXX.eqn on trying to fornmula edit/create
> - run external text editor with this file as parameter
> - read file after editor closing and update formula object as it LibreOffice
> Math does
> 
> It's AUTOMATICALY enables features on user side:
> 
> - pair brackets highlighting
> - functions highlighting
> - more simple editing (change variable name with multicaret editing or vim
> commands, e.t.c.)
> - snippets (not only for math constructions, may be used to natural greek
> symbols writing - [a]+[Tab] -> α instead of %alpha - more simple reading)
> - macroses to text editing in some special cases
> 
> It seems to be a great effect for easy implementation - don't you think so?

This would require the "external" editor to prepare formula in viable MathML that could be parsed back into ODF.  Sorry, but I don't see how this would provide anything that can't already be accomplished adding logic to node composition in the current sm formula editor module with more direct changes.
Comment 15 Sergey 2020-12-15 16:24:38 UTC
Thanks, V Stuart Foote!

Of cause, I mean only "eqn" text editing by external editor (no MathML and other parts of formula object). For example LO Math may check settings on start and run external editor, than LO Math generates all this MathML as in normal mode - the only difference - it takes text from file, not from textbox.

But! This feature is already particulary realized in iMath plugin. Problem that it's don't open formula objects without "%%ii" text inside.

Also: iMath and CompPad can update formula after text changing. May be they do it with LibreOffice Math. So, may be more simple way exists to edit formula object?
---------------------------------------------------------
Link to iMath:
https://sourceforge.net/projects/ooo-imath/
Discussion:
https://sourceforge.net/p/ooo-imath/feature-requests/75/
To see how it works:
1. Install https://sourceforge.net/projects/ooo-imath/files/Beta%20versions/iMath-2.3.1/iMath-2.3.1~beta2.oxt/download
1. Open Service -> Parameters... -> LibreOffice Writer -> iMath global settings
2. Write path it field "Editing" (if problems - try to use path without spaces, else you may try to write just editor file name and than change %PATH%)
3. Create formula with "Insert" button on panel, write a=10+20 for example
4. Press right mouse button on formula and select Edit iFormula -> External Editor
---------------------------------------------------------
Link to ComPad (not maintainted now)
https://sourceforge.net/projects/comppad/
Comment 16 Rafael Lima 2021-01-29 17:47:41 UTC
Created attachment 169284 [details]
Math Highlighting Comments

Dante, I built your patch and I have a few suggestions to make (see the attached ODG file "Math Highlighting Comments").

1) Keywords could be marked as bold to make it clear for the user that a format command is being used. This is important because sometimes the user thinks the word will be treated as text when it is in fact a command. For a complete list of commands, refer to the Math Guide (https://wiki.documentfoundation.org/images/a/a2/MG70-MathGuide.pdf).

2) The double quotes for strings could be formatted together with the string itself (see the example in the attached file)

The following three comments are not part of this patch, but could be considered in a future enhancement you'll submit.

3) I liked the color combination you chose. However, in the future there could be options for Math under Tools > LibreOffice > Application Colors for the user to change the colors if h/she desires (as currently there is for other LO components).

4) Currently in the Formula Editor, the line breaks at a weird position, near the middle of the editor. It could be better to use all the available screen space.

5) There could be way to increase the size of the font in the Formula Editor (I mean the font used for the markup language). The current size is a bit small. I think the easiest way to implement this is to use the same configuration that's applied for the Basic IDE (which is the font set under Tools > Options > Fonts in the "Font Settings for HTML, Basic and SQL Sources".

I'm available to test/comment future versions of this patch or new patches you submit to the Math component.
Comment 17 dante19031999 2021-01-29 19:46:42 UTC
Created attachment 169287 [details]
Math Highlighting Comments

Answer to Rafael Lima
Comment 18 dante19031999 2021-01-29 20:12:15 UTC
(In reply to Rafael Lima from comment #16)

The answer may disappoint you.

> 1) Keywords could be marked as bold to make it clear for the user that a
> format command is being used. This is important because sometimes the user
> thinks the word will be treated as text when it is in fact a command. For a
> complete list of commands, refer to the Math Guide
> (https://wiki.documentfoundation.org/images/a/a2/MG70-MathGuide.pdf).

This is gonna require a bit more work behind the scenes.
There are some changes that should be done before using more the system to replace.
It is related with matml compatibility and operator priority list.
When ready will implement it.

> 2) The double quotes for strings could be formatted together with the string
> itself (see the example in the attached file)

Done.

> The following three comments are not part of this patch, but could be
> considered in a future enhancement you'll submit.
> 
> 3) I liked the color combination you chose. However, in the future there
> could be options for Math under Tools > LibreOffice > Application Colors for
> the user to change the colors if h/she desires (as currently there is for
> other LO components).

I did make sure the colors where "easy" to switch.
They are declared as a list instead of numerically inserted in the code.
However changing that may require themes and other complicated stuff I don't knwon how to use.

> 4) Currently in the Formula Editor, the line breaks at a weird position,
> near the middle of the editor. It could be better to use all the available
> screen space.

No clue about how to change it.
The number of columns seems fixed whatever you do.
I guess it's related with paper size.
However don't know.
https://opengrok.libreoffice.org/xref/core/include/editeng/editeng.hxx?r=88c0e46e&mo=3646&fi=140#140
https://opengrok.libreoffice.org/xref/core/include/editeng/editview.hxx?r=c83166ce#135

> 5) There could be way to increase the size of the font in the Formula Editor
> (I mean the font used for the markup language). The current size is a bit
> small. I think the easiest way to implement this is to use the same
> configuration that's applied for the Basic IDE (which is the font set under
> Tools > Options > Fonts in the "Font Settings for HTML, Basic and SQL
> Sources".

Already done. Check the attached document.

> I'm available to test/comment future versions of this patch or new patches
> you submit to the Math component.

Patchset 24, available in a couple of hours has the change about the text.
Comment 19 Rafael Lima 2021-02-01 12:50:36 UTC
Created attachment 169343 [details]
Highlighting Numeric Values

Dante! I ran Patchset 27 and all is working. At least from my tests, I couldn't produce any wrong behavior.

There was just one thing that occurred to me (see the new attached file). Maybe you could apply a highlight color to numeric values, as it is currently done in Basic. Also, you could use the same shades of Blue and Green that are used by Basic.

I am not saying that you should use the same color constants as Basic does, but rather innitialy assign the same colors used by Basic to the color constants you created.

However, these are just suggestions. You could try them out and see if it's a good idea.
Comment 20 dante19031999 2021-02-01 18:36:06 UTC
(In reply to Rafael Lima from comment #19)
> Created attachment 169343 [details]
> Highlighting Numeric Values

> There was just one thing that occurred to me (see the new attached file).
> Maybe you could apply a highlight color to numeric values, as it is
> currently done in Basic. Also, you could use the same shades of Blue and
> Green that are used by Basic.

I applied the same color to numbers and hexadecimal values as well (right now command not available, but machinery already implemented, available in 15 days), but not RGB hexadecimal values ( color#RRGGBB (available from 7.1) ) or font sizes or other numeric parameters.
 
> I am not saying that you should use the same color constants as Basic does,
> but rather initially assign the same colors used by Basic to the color
> constants you created.

About basic, I did never used it, but I don't think it uses the same kind of tokens. I looked some screenshots and I'm still not sure about the token types (blue and green). The numbers are in a red variant as in your screenshot in basic, but more pale. I'm using non bright CSS3 colors for it and I don't really believe we need a parallelism with another software or module.

Maybe, I'll be able to add an entry on expert configuration for changing colors.
I'll check it out. But building the UI for normal users is way too complicated.

> However, these are just suggestions. You could try them out and see if it's
> a good idea.

It also hit me to put comments in gray, but I haven't the internal machinery done yet.
Comment 21 Xisco Faulí 2022-05-02 14:46:30 UTC
Dear Dante,
This bug has been in ASSIGNED status for more than 3 months without any
activity. Resetting it to NEW.
Please assign it back to yourself if you're still working on this.