5

In the \verbatim environment, the syntax highlighting is disabled default, e.g. a $ ist not recognized as beginning of the math mode. I add my own environtment (\rawtext) to the kile Verbatim environments (Settings -> Configure Kile -> LaTeX -> General -> Commands -> Environments)

enter image description here

However, it is not working:

enter image description here

What is wrong or what can I do to display my own verbatim environment (kile 2.1.0 under Debian Linux)

5

Kile does not switch its highlighting rule due to the registered environments. The highlighting is governed by the kate highlighting rules.

Locate the highlighting file latex.xml, it should be under PREFIX/share/apps/katepart/syntax/latex.xml, where PREFIX is the root of your KDE installation, like /usr or /opt.

Edit this file as follows. First, we have to find your rawtext environment, just add it where verbatim is detected:

  <!-- filter the environment name and check the type -->
  <context name="Environment" attribute="Environment" lineEndContext="#stay">
    <RegExpr String="(lstlisting|(B|L)?Verbatim)" attribute="Environment" context="VerbatimEnvParam"/>
    <RegExpr String="(verbatim|boxedverbatim|rawtext)" attribute="Environment" context="VerbatimEnv"/>
    <RegExpr String="(equation|displaymath|eqnarray|subeqnarray|math|multline|gather|align|flalign)" attribute="Environment" context="MathEnv"/>
    <RegExpr String="(alignat|xalignat|xxalignat)" attribute="Environment" context="MathEnvParam"/>
    <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
    <RegExpr String="[a-zA-Z]" attribute="Environment" context="LatexEnv"/>
    <RegExpr String="\s+" attribute="Error" context="#pop"/>
    <RegExpr String="[^a-zA-Z\xd7]" attribute="Error" context="#pop"/>
  </context>

Next, the your environment needs to be parsed:

  <!-- parse verbatim text -->
  <context name="Verbatim" attribute="Verbatim" lineEndContext="#stay">
    <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
    <RegExpr String="\\end(?=\s*\{(verbatim|lstlisting|boxedverbatim|rawtext|(B|L)?Verbatim)\*?\})" attribute="Structure"  context="VerbFindEnd"/>
  </context>

Finally, we need to detect the end of that environment:

  <!-- end of verbatim environment -->
  <context name="VerbFindEnd" attribute="Normal Text" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop">
    <RegExpr String="\s*\{" attribute="Normal Text" context="#stay"/>
    <RegExpr String="(verbatim|lstlisting|boxedverbatim|rawtext|(B|L)?Verbatim)\*?" attribute="Environment" context="#stay"/>
    <DetectChar char="}" attribute="Normal Text" context="#pop#pop#pop#pop#pop" endRegion="block"/>
  </context>

In other words, wherever verbatim is handled in the syntax highlighting file, you add rawtext.

snapshot

2
  • this solutions works fine for years, however, now I've updated to Kile 3 beta and it works not anymore. Are there hints to do that?
    – Micha
    Feb 28 '18 at 10:51
  • with KDE5 the file is used from $HOME/.local/share/org.kde.syntax-highlighting/syntax to find a source, go to kate-editor.org/syntax
    – Micha
    Jul 13 '18 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.