# Double #s when defining a new command that uses \mint instead of using \mint directly

Why does \dollarcom give a different result than \mint{bash}|$#|? \documentclass{article} \usepackage{minted} \newcommand{\dollarcom}{\mint{bash}/$#/}

\begin{document}

\dollarcom
\mint{bash}|$#| \end{document}  Output: 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. Update: 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> <context name="ToEndOfLine" attribute="Normal Text" lineEndContext="#pop"> </context>  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"/> </context>  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"/> </context>  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. - 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 ## 1 Answer You have to define \dollarcom with a "stringified #": \documentclass{article} \usepackage{minted} \edef\dollarcom{\noexpand\mint{bash}/$\string#/}

\begin{document}

\dollarcom

\mint{bash}|\$#|

\end{document}
`

-