TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why does \dollarcom give a different result than \mint{bash}|$#|?







enter image description here

Reading from the pdflatex output it seems like $# is taken as an illegal parameter number. In this case, how can I define a command with the same output of \mint{bash}|$#|?

Note: I absolutely do not want to use \mint{bash}|$#| in my text because the non-escaped $ breaks code highlighting in Kile and after that half of my LaTeX source looks green as if in math mode.


I found a hack to make Kile recognize a command as a \verb command. If you want to change the system's syntax highlightining open /usr/share/kde4/apps/katepart/syntax/latex.xml, if you want to add syntax highlighting only for your user open ~/.kde/share/apps/katepart/syntax/latex.xml. If the latter does not exist create the missing directories and copy the system-wide file into it.

Now modify the chosen file. In particular there is a section that looks like this:

  <!-- LaTeX command in text mode -->
  <context name="ContrSeq" attribute="Keyword" lineEndContext="#pop">
    <StringDetect String="verb*" attribute="Keyword" context="Verb"/>
    <RegExpr String="(Verb|verb|lstinline)(?=[^a-zA-Z])" attribute="Keyword" context="Verb"/>
    <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
    <RegExpr String="[a-zA-Z@]+(\+?|\*{0,3})" attribute="Keyword" context="#pop"/>
    <RegExpr String="[^a-zA-Z]" attribute="Keyword" context="#pop" />
  <context name="ToEndOfLine" attribute="Normal Text" lineEndContext="#pop">

Modify the line <RegExpr String="(Verb... to:

<RegExpr String="(Verb|verb|lstinline|mint|mint\{[a-zA-Z0-9=, ]+\})(?=[^a-zA-Z])" attribute="Keyword" context="Verb"/>

This will allow kile to highlight \mint|text| or \mint{some,options}|text| in the correct way.

To make Kile highlight also the minted environments check for the section that looks like:

  <!-- filter the environment name and check the type -->
  <context name="BeginEnvironment" attribute="Environment" lineEndContext="#stay">
    <RegExpr String="(lstlisting|(B|L)?Verbatim)" attribute="Environment" context="VerbatimEnvParam"/>
    <RegExpr String="(verbatim|boxedverbatim)" attribute="Environment" context="VerbatimEnv"/>

And change the last line to:

    <RegExpr String="(verbatim|boxedverbatim|minted)" attribute="Environment" context="VerbatimEnv"/>

Look for the section:

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

And change the RegExpr line with:

    <RegExpr String="\\end(?=\s*\{(verbatim|lstlisting|boxedverbatim|minted|(B|L)?Verbatim)\*?\})" attribute="Structure"  context="VerbFindEnd"/>

Look for the section:

  <!-- 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|(B|L)?Verbatim)\*?" attribute="Environment" context="#stay"/>
    <DetectChar char="}" attribute="Normal Text" context="#pop#pop#pop#pop#pop" endRegion="block"/>

And Change the second RegExpr line to:

    <RegExpr String="(verbatim|lstlisting|boxedverbatim|minted|(B|L)?Verbatim)\*?" attribute="Environment" context="#stay"/>

After that Kile should correctly highlight the minted environments.

I think there should be a way to add at least user-specific syntaxes, if not for each file, but I cannot find any syntax directory in ~/.kde/*.

Unfortunately this does not highlight "shortcuts", so you either have to add all of them manually, or you must use `minted with all the options every time.

share|improve this question
Regarding your syntax problems: Does using \mint{bash}|$#|%$ help? I've seen some syntax highlighting restored by using the complementary symbol in comments. – Werner Nov 20 '12 at 0:28
@Werner No it does not work. Kile ignors the dollar after the %(correctly). – Bakuriu Nov 20 '12 at 6:41
up vote 8 down vote accepted

You have to define \dollarcom with a "stringified #":








enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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