GNOME Bugzilla – Bug 679748
New latex.lang language definition file
Last modified: 2013-12-05 21:11:25 UTC
Created attachment 218539 [details] Proposed LaTeX language definition file (gtksourceview-2.0) (Note: system is gnome 2, file was written for gtksourceview 2.0) While LaTeX has a default language definition (latex.lang), many code structures/formatting remain undefined and can therefore not be highlighted, or can not be distinguished from each other. I would like to contribute a new latex.lang file, which defines more structures, and allows more selective highlighting of different types of functions/macros (e.g. spacing, sections, environments). Although the file achieves at the moment more or less what I intended it to do, the flexibility of LaTeX (and my inexperience?) made many 'workarounds' necessary, and opinions and suggestions would be very welcome. As a summary I would like to see an improvement of the default latex.lang definition and offer this new latex.lang as a suggestion, hoping it is a valuable contribution towards this aim. (the .lang file was also uploaded on the language definitions page https://live.gnome.org/GtkSourceView/LanguageDefinitions) All the Best Tobi
Why not improving the existing latex.lang file and writing patches to improve it?
Yes I agree that all contributions should be made on top of the previous one, maybe this one is on top?
Normally, yes, but just by looking at the code, this new lang file is far superior to the previous one. The common parts are minimum and for a good reason, it detects different modes and different ways of using commands :) I don't know how to proceed here... Tobias, would be possible for you to submit your new lang patches as a set of patches for the old one... so that in the end, we would have yours as a result? Also trying to keep changes short so we can review them easily and faster than trying to review the whole thing at once.
There's another problem with that file that doesn't allow the merge. It's licensed with GPL but gtksourceview is LGPL. Would you be willing to relicense it? I was going to try to perform a merge but stopped after the header when noticed the license.
Created attachment 241485 [details] [review] Latest latex.lang version, LGPL
Dear all, thank you for considering this file. I attached my latest version, and changed it to LGPL (as far as I can tell; I don't know much about licensing, please let me know if I got it wrong). Best Regards Tobi
Please copy/paste the license header from another language spec in gtksourceview, for example c.lang. (this is the _Lesser_ General Public License, not library). I see that the new latex.lang fixes the bug #691749. And if José says that it is far superior to the previous one, the best is probably to replace it directly. I have almost no experience in language specs writing in gtksourceview, so if someone with more experience can review it, it would be really appreciated. Tobias, see also bug #652782 that contain additional rules for languages specs, not yet documented.
Created attachment 256029 [details] [review] Latest latex.lang version Header copied from c.lang, should be LGPL now. As I can tell works well for LaTeX, but some minor issues with TeX code can occur. I am aware that the code is rather complex and likely difficult to review, but to cope with some flexibilities of the language I couldn't come up with easier solutions; any comments from reviewers are very welcome. Tobias
I'm looking more in details the new latex.lang, and compare it with the current latex.lang. Some notes here: - avoid trailing spaces in the file - no need to keep a changelog inside the file, the history is in git - the 'comment' context contains also the verbatim stuff, which are not comments. The current latex.lang contains a list of commands, a better support for lstinline, and probably other features missing in the new latex.lang. It is thus better to take new features and implement them incrementally in the current latex.lang. I've started the wip/latex branch. There is only a small commit for now, but I hope to continue the work in the following days. This is a good exercise for me, to learn how to write syntax files :-)
Review of attachment 256029 [details] [review]: I've made some progress, and here are more comments. The no-spell-check class is not applied. ::: data/language-specs/latex.lang @@ +103,3 @@ + <context id="verbatim-comment" style-ref="comment" style-inside="true"> + <start>(\\begin)\{(comment)\}</start> + <end>(\\end)\{(\%{2@start})\}</end> \%{2@start} is not needed here, just "comment" is better. @@ +116,3 @@ + <start>(\\begin)\{(verbatim\*?|lstlisting|alltt)\}</start> + <end>(\\end)\{(\%{2@start})\}</end> + <include> bad indentation. @@ +172,3 @@ + <!-- [3, -] General command syntax ______________________________________--> + <define-regex id="command" extended="true"> + \\[a-zA-Z@]+\*? why @? Can you give an example of a command with @?
Thanks for your work Sébastien, just regarding the question about the general command syntax. @ is frequently used for internal variables/macros, e.g. in class or style files, it is not used in commands for the direct writing of the document. However, one can change these internal commands within the document by enclosing the relevant part in \makeatletter ... \makeatother for more info: http://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do
Thank you for the info Tobias, I've added the @ to the generic command. I've also improved the math mode, by using some of your work. I don't want a long and complex .lang file. I'm quite happy with the results for now. It is already much better than before. I think we can close this bug. If you want to improve the existing latex.lang, make incremental steps, try to keep things simple* (no hacks), and open another bug report. Anyway, thanks for your work and regexes, it has been useful. * For example it becomes complicated to highlight syntax errors. It's sufficient to highlight correctly correct .tex files.