LaTeX forum ⇒ KileSyntax highlighting tweaking for Kile

Information and discussion about Kile, an integrated LaTeX environment for Linux KDE
SmithWillSuffice
Posts: 15
Joined: Fri Feb 23, 2007 9:29 am

Syntax highlighting tweaking for Kile

Postby SmithWillSuffice » Thu Apr 12, 2007 11:23 pm

Due to the use of KParts the Kile syntax highlighting is actually determined by the Kate editor XML file.

It is sometimes useful to know how to tweak the highlighting settings. One situation of annoying editor highlighting that arises is for example when you define a custom verbatim type of environment using say the moreverb, or listings packages. When I did this I found that "$" characters in my code lists (say for bash or Perl script code listings) were seen by Kile as unmatched math delimiters. This does not arise when you use the standard \begin{verbatim}...\end{verbatim} environment because Kate/Kile know about that environment, so they treat unpaired dollar characters as just plain verbatim text.

So to fix my custom environment I had to tweak the syntax highlighting rules for Kate. The place to do this is here:

$HOME/.kde/share/apps/katepart/syntax/latex.xml

This is where your "latex.xml" syntax highlighting rules for Kile are found (at least on my system (Fedora) they were located here in my Kate highlighting rules directory, it might be a little different for other distributions or earlier KDE releases?).


A quick way to incorporate rules for a new verbatim style of environment is to just search this "latex.xml" file for the keyword "verbatim", and wherever it occurs as an argument in a

<RegExpr String="...

string then replace the text "verbatim|" with "verbatim|mylisting|", for example, if your custom code lisiting environment is named "mylisting". Save and reopen Kile and then your editor should have verbatim style highlighting correct for all your

\begin{mylisting}
...
\end{mylisting}

segments, even if you have unpaired "$" characters in it. Of course you won't get any fancy code highlighting this way. It would be nicer to somehow tell Kate/Kile to highlight your \begin{mylisting}...\end{mylisting} segments according to the rules for the code language that the environment contains, e.g., C++ highlighting for lists of C/C++ code, and Perl highlighting for all the Perl code listings and so on. Interestingly this is possible in your output LaTeX dvi with packages like listings, but not so easy for your latex editor.

If anyone knows how to create rules for this for Kate/Kile then I'd like to know! It would probably involve some XML gymnastics because it amounts to having Perl or C or other language syntax highlighting within subregions of a file that is marked for LaTeX native syntax highlighting---not an easy thing to do I'd bet!

Of course i don't really care, it's the final processed LaTeX dvi that I really want to have smart highlighting, my editor can be damned :-)
Support Free Software---It's Made for Everyone

Stefanie
Posts: 25
Joined: Fri Apr 04, 2008 2:39 pm

Postby Stefanie » Wed May 07, 2008 11:02 pm

thanks for the tip!

jphv
Posts: 5
Joined: Wed Aug 12, 2009 8:22 pm

Postby jphv » Thu Aug 13, 2009 1:04 pm

Now I can highlight my own commands in latex :D

Thank you very very much!

soren_dk
Posts: 1
Joined: Wed Jan 13, 2010 1:44 pm

Postby soren_dk » Wed Jan 13, 2010 1:52 pm

Hi SmithWillSuffice,
alas, I know NOTHING about xml coding ...

I was wondering whether it would be possible to add to the latex.xml file in such a way that Kile would hightlight e.g \section{Some heading or other}. By hightlighting (e.g increased size) sections, subsections etc, you could get some of the effect of LyX: no less clutter, but easier to navigate and get an overview of the doc.

Just a thought - I, for one would love it ;)

arwintcher
Posts: 29
Joined: Thu Feb 19, 2009 3:23 pm

Postby arwintcher » Wed Aug 25, 2010 8:21 pm

I was thinking about this today and managed to make a couple of amateur hacks to my latex.xml file which successfully change the highlighting of commands like \citep to be the same as \cite, and also to have the chapter titles etc. in a different color from the other text.

I posted an explanation of what I did on a blog I have been keeping as a sort of notebook, but the gist of it is:

--add commands like citep, citealp, and so on to the line that starts "<RegExpr String="\\(cite|nocite|Cite"
--create a new line under "<itemDatas>" that defines how you want the text to look, and give it a new name
--change the line that starts "<context name="SectioningInside" attribute='Normal Text'" to use whatever name you decided on in the previous step

So, my latex.xml file now has these lines:
<context name="SectioningInside" attribute="Section Highlight" lineEndContext="#stay">

and

<itemData name="Section Highlight" defStyleNum="dsNormal" color="#990099" selColor="#ffcccc" bold="1" italic="1"/>


in the appropriate sections. Not quite making the text bigger, and I haven't tried to make the text appear different in the structure view, but it's a start.


Return to “Kile”

Who is online

Users browsing this forum: No registered users and 1 guest