latex syntax coloring

100 views
Skip to first unread message

Josef

unread,
Feb 26, 2019, 10:27:16 AM2/26/19
to leo-editor
latex syntax coloring colors only some common latex commands, for others only the first letter is colorized.
I realize, that coloring all possible latex commands is impossible, since one can define pretty much anything to be a command in latex,
but it would be relatively simple to cover anything starting with a backslash and ending before the first special or whitespace character.
That would cover most user-defined commands also, because it is all one can produce with \newcommand.

- Josef

Rob

unread,
Feb 26, 2019, 11:37:39 AM2/26/19
to leo-e...@googlegroups.com
Josef, wonder why my experience is different. I write LaTeX in Leo almost every day and have no difficulty with syntax coloring. See screenshot:

190226 LaTeX Syntax.PNG


Perhaps post screenshots where the syntax doesn't seem to work to see if I can duplicate in my environment.

Rob...
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Josef

unread,
Feb 27, 2019, 4:13:06 AM2/27/19
to leo-e...@googlegroups.com

I don't seem to be able to respond to your message - all gets deleted when I attach or insert an image.

Leo 5.8.1-b2 devel, build 20190213233241, Wed Feb 13 23:32:41 PST 2019
Git repo info: branch = devel, commit = 95afe636b5e8
Python 3.7.2, PyQt version 5.11.1
linux

Message has been deleted

Josef

unread,
Feb 27, 2019, 4:17:36 AM2/27/19
to leo-e...@googlegroups.com

screenshot.png


ok, finally I managed to upload an image. You can see that some commands are highlighted, others like \cbstart only the first letter and some like \lae not at all.

- Josef

Rob

unread,
Feb 27, 2019, 9:07:04 AM2/27/19
to leo-editor
I sorta duplicated your text and get a very different result.

190227 LaTeX Syntax.PNG

A few thoughts and questions:
  • Wondering if your environment is significantly different from mine (Win10, Python3, PYQT 5.4.1). Don't know why that matter though.
  • The contstructs \lae\, \cbstart and others that don't work for you, color as expected for me.
  • However, words after the closing `\` are improperly colorized.
  • Regarding that, if you use those to create space between the construct and the next word, another way to do that is \lae{}.
  • Also curious about the \EM/\pfn\ fragment; been around LaTeX for awhile and don't know what that does (not relevant to your original question, however).
Rob...

Rob

unread,
Feb 27, 2019, 9:12:27 AM2/27/19
to leo-editor
Duh! Just figured it out. `@language latex` and `@language tex` give different results.

190227 LaTeX Syntax2.PNG

Josef,  In your case, the easy fix is to change your @language to `tex`.

Bigger question to the community; is there any reason why the languages `tex` and `latex` should have different syntax coloring rules?

Rob...

Josef

unread,
Feb 28, 2019, 5:46:55 AM2/28/19
to leo-editor
Hi Rob,

Thanks for figuring this out. I have always @language latex in my files, because that is what gets automatically added by Leo when opening a file with a .tex filename extension.

Since latex and tex have the same syntax, I don't see why there should be two different syntax coloring rules. There are some tex commands which are deemed obsolete in latex, like \em and \bf. It may make sense to color these differently in latex, but I fear it would need a latex expert to identify these and even then it my be a matter of taste.

In my mind, the most sensible solution would be to use always the tex syntax rules and to make @language tex the default when loading .tex (or .latex) files.  I am unsure about .bib files. In case one uses biblatex, they may contain tex commands, but they would really need a bit a different treatment.

- Josef


Josef

unread,
Feb 28, 2019, 5:56:13 AM2/28/19
to leo-editor

  • However, words after the closing `\` are improperly colorized.

This needs fixing, because the "closing" "\ "  designates really macro, which ends with the blank (and expands to a blank), since latex macros gobble up any trailing blank. I have such "\ " (backslash followed by a blank) macros all over the text.

- Josef

Edward K. Ream

unread,
Feb 28, 2019, 6:25:59 AM2/28/19
to leo-editor
On Wed, Feb 27, 2019 at 8:12 AM Rob <lar...@gmail.com> wrote:
Duh! Just figured it out. `@language latex` and `@language tex` give different results.

I have just created #1088 for this.

Edward

Edward K. Ream

unread,
Jun 23, 2019, 3:03:09 PM6/23/19
to leo-editor
On Tuesday, February 26, 2019 at 9:27:16 AM UTC-6, Josef wrote:

latex syntax coloring colors only some common latex commands, for others only the first letter is colorized.

Rev 5e467b6 in devel completes #1088. This was surprisingly easy to do, though some choices are debatable.  The highlights:

- Both `@language tex` and `@language latex` use leo/modes/tex.py. This ignores the many special cases in latex.py. I'll retain leo/modes/latex.py in case this choice becomes controversial.

- Only slight changes were needed to tex.py. Similar changes could be added to latex.py.

Let me know how this works for you.

Edward

Rob

unread,
Jun 23, 2019, 4:02:02 PM6/23/19
to leo-editor
That should work for me as I was using `@language=tex` anyway for all of my LaTeX work.

Rob...

Josef

unread,
Jul 6, 2019, 7:35:52 AM7/6/19
to leo-editor
Thank you for improving this.
I am waiting to test this, but do not want to do a git pull right now, because I see the activepath plugin is currently broken, and I depend on that.
-Josef

Edward K. Ream

unread,
Jul 6, 2019, 9:41:57 AM7/6/19
to leo-editor
On Sat, Jul 6, 2019 at 4:35 AM Josef <joe...@gmx.net> wrote:
Thank you for improving this.
I am waiting to test this, but do not want to do a git pull right now, because I see the activepath plugin is currently broken, and I depend on that.

active_path should work now.

Edward
Reply all
Reply to author
Forward
0 new messages